<template>
  <div>
    <div>
      <el-dialog
        :title="$t('addstrategy.title')"
        :visible.sync="dialogVisible1"
        width="82%"
        :center="true"
      >
        <el-form
          :model="ruleForm1"
          :rules="rules1"
          ref="ruleForm1"
          label-width="100px"
          class="demo-ruleForm1"
          :label-position="labelPosition"
        >
          <el-row :justify="center">
            <el-col :span="6">
              <el-form-item :label="$t('addstrategy.name')" prop="clgl_name">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_name" :placeholder="$t('select')">
                    <el-option
                      v-for="item in options1"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>

              <el-form-item
                :label="$t('addstrategy.sourceObject')"
                prop="clgl_ydx"
                style="color: red"
              >
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_ydx" :placeholder="$t('select')">
                    <el-option
                      v-for="item in arr"
                      :key="item"
                      :label="item"
                      :value="item"
                    >
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-row>
                <el-form-item :label="$t('addstrategy.entranceGateway')" prop="clgl_rkwg">
                  <el-row>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkwg1"></el-input>
                    </el-col>
                    <el-col :span="1">. </el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkwg2"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkwg3"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkwg4"></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item :label="$t('addstrategy.exportGateway')" prop="clgl_ckwg">
                  <el-row>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckwg1"></el-input>
                    </el-col>
                    <el-col :span="1">. </el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckwg2"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckwg3"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckwg4"></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('addstrategy.protocol')" prop="clgl_xy">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_xy"
                    multiple
                    :placeholder="$t('select')"
                  >
                    <el-option
                      v-for="item in options2"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item :label="$t('addstrategy.sourcePort')" prop="clgl_ydk">
                <el-col :span="19">
                  <el-input v-model="ruleForm1.clgl_ydk"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item
                :label="$t('addstrategy.entranceNetworkCard')"
                prop="clgl_rkwk"
              >
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_rkwk" :placeholder="$t('select')">
                    <el-option :label="wlgl_nw_name" :value="wlgl_nw_name"> </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item :label="$t('addstrategy.exportNetworkCard')" prop="clgl_ckwk">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_ckwk" :placeholder="$t('select')">
                    <el-option :label="wlgl_ww_name" :value="wlgl_ww_name"> </el-option>
                  </el-select> </el-col
              ></el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('addstrategy.workingMode')" prop="clgl_gzms">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_gzms" :placeholder="$t('select')">
                    <el-option
                      v-for="item in options3"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item :label="$t('addstrategy.targetObject')" prop="clgl_mddx">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_mddx" :placeholder="$t('select')">
                    <el-option
                      v-for="item in arr"
                      :key="item"
                      :label="item"
                      :value="item"
                    ></el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-row>
                <el-form-item :label="$t('addstrategy.entranceIP')" prop="clgl_rkip">
                  <el-row>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkip1"></el-input>
                    </el-col>
                    <el-col :span="1">. </el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkip2"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkip3"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_rkip4"></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item :label="$t('addstrategy.exportIP')" prop="clgl_ckip">
                  <el-row>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckip1"></el-input>
                    </el-col>
                    <el-col :span="1">. </el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckip2"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckip3"></el-input>
                    </el-col>
                    <el-col :span="1">.</el-col>
                    <el-col :span="5">
                      <el-input v-model="ruleForm1.clgl_ckip4"></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-row>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('addstrategy.undefinedCommand')" prop="clgl_wdyml">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_wdyml" :placeholder="$t('select')">
                    <el-option
                      v-for="item in options5"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item :label="$t('addstrategy.targetPort')" prop="clgl_mddk">
                <el-col :span="19">
                  <el-input v-model="ruleForm1.clgl_mddk"> </el-input>
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span style="color: #fff">{{ $t("addstrategy.recordLogs") }}</span>
        <el-switch style="margin-left: 6%" v-model="switchvalue"> </el-switch>
        <div
          class="title"
          style="display: flex; justify-content: space-between; margin-top: 10px"
        >
          <h3 style="margin-top: 10px; margin-bottom: 3px; color: #fff4">
            {{ $t("addstrategy.commandList") }}
          </h3>
          <el-button @click="flag = true">{{
            $t("addstrategy.createCommand")
          }}</el-button>
        </div>
        <el-divider></el-divider>
        <el-table :data="tableData1" style="width: 100%" border>
          <el-table-column :label="$t('addstrategy.num')">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template></el-table-column
          >
          <el-table-column prop="cmdlist_ml" :label="$t('addstrategy.command')">
          </el-table-column>
          <el-table-column prop="cmdlist_qsdz" :label="$t('addstrategy.startingAddress')">
          </el-table-column>
          <el-table-column prop="cmdlist_dzcd" :label="$t('addstrategy.addressLength')">
          </el-table-column>
          <el-table-column prop="cmdlist_ms" :label="$t('addstrategy.description')">
          </el-table-column>
          <el-table-column prop="cmdlist_dz" :label="$t('addstrategy.action')">
          </el-table-column>
          <el-table-column :label="$t('addstrategy.Operation')">
            <template slot-scope="scope">
              <!-- <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >编辑</el-button
              > -->
              <el-button
                type="text"
                size="small"
                @click="handleDel(scope.$index, scope.row)"
                >{{ $t("del") }}</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="saveAll">{{ $t("save") }}</el-button>
          <el-button @click="dialogVisible1 = false">{{ $t("cancel") }}</el-button>
        </span>
      </el-dialog>
    </div>
    <div>
      <el-dialog
        :title="$t('addstrategy.createCommand') + ':'"
        :visible.sync="flag"
        width="30%"
      >
        <el-form
          center
          :model="ruleForm2"
          :rules="rules2"
          ref="ruleForm2"
          label-width="150px"
          class="demo-ruleForm2"
          :label-position="labelPosition"
        >
          <el-form-item :label="$t('addstrategy.command') + ':'" prop="cmdlist_ml">
            <el-col :span="6">
              <el-select
                v-model="ruleForm2.cmdlist_ml"
                style="width: 200px"
                :placeholder="$t('select')"
              >
                <el-option
                  v-for="item in options6"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-form-item>

          <el-form-item
            :label="$t('addstrategy.deviceID') + ':'"
            prop="cmdlist_sbid"
            style="color: red"
          >
            <el-col :span="6">
              <el-select
                v-model="ruleForm2.cmdlist_sbid"
                style="width: 200px"
                :placeholder="$t('select')"
              >
                <el-option
                  v-for="item in options7"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item
            :label="$t('addstrategy.startingAddress') + ':'"
            prop="cmdlist_qsdz"
          >
            <el-col :span="6">
              <el-input v-model="ruleForm2.cmdlist_qsdz" style="width: 200px"> </el-input>
            </el-col>
          </el-form-item>
          <el-form-item
            :label="$t('addstrategy.addressLength') + ':'"
            prop="cmdlist_dzcd"
          >
            <el-col :span="6">
              <el-input v-model="ruleForm2.cmdlist_dzcd" style="width: 200px"> </el-input>
            </el-col>
          </el-form-item>
          <el-form-item :label="$t('addstrategy.description')" prop="cmdlist_ms">
            <el-col :span="6">
              <el-input v-model="ruleForm2.cmdlist_ms" style="width: 200px"></el-input
            ></el-col>
          </el-form-item>
          <el-form-item :label="$t('addstrategy.action') + ':'" prop="cmdlist_dz">
            <el-col :span="6">
              <el-select
                v-model="ruleForm2.cmdlist_dz"
                style="width: 200px"
                :placeholder="$t('select')"
              >
                <el-option
                  v-for="item in options5"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="saveMl">{{ $t("save") }}</el-button>
          <el-button @click="flag = false">{{ $t("cancel") }}</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { SaveUserAnswer, GetUserAnswer, getQueryAnswer } from "../api/user";
export default {
  name: "InternetCompetitionAddPolicy",

  data() {
    return {
      switchvalue: false,
      clgl_qidong: true,
      options1: this.$t("addstrategy.options1"),
      options2: [
        {
          label: "OPC",
          value: "OPC",
        },
        {
          label: "Modbus(TCP)",
          value: "Modbus(TCP)",
        },
        {
          label: "DNP3",
          value: "DNP3",
        },
        {
          label: "S7",
          value: "S7",
        },
        {
          label: "EC104",
          value: "EC104",
        },
      ],
      options3: this.$t("addstrategy.options3"),
      options4: this.$t("addstrategy.options4"),
      options5: this.$t("addstrategy.options5"),
      options6: this.$t("addstrategy.options6"),
      options7: this.$t("addstrategy.options7"),
      options8: this.$t("addstrategy.options8"),
      options9: this.$t("addstrategy.options9"),
      dialogVisible1: true,
      labelPosition: "left",
      tableData: [
        {
          clgl_name: "数来服务器",
          cmdlist_qsdz: "192.168.89.21",
          clgl_xy: "Modbus(TCP)",
          clgl_gzms: "透明模式",
          clgl_ydx: "有线区交换机",
          clgl_ydk: "5200",
          clgl_rkwk: "有线区网闸（内网）",
          clgl_rkip: "",
          clgl_rkwg: "",
          clgl_ckwk: "有线区网闸（外网）",
          clgl_ckip: "",
          clgl_ckwg: "",
          clgl_mddx: "无限区路由器",
          clgl_mddk: "",
          clgl_rkip1: "",
          clgl_rkip2: "",
          clgl_rkip3: "",
          clgl_rkip4: "",
        },
      ],
      tableData1: [
        // {
        //   cmdlist_ml: "",
        //   // cmdlist_sbid: "有线区交换机命令",
        //   cmdlist_qsdz: "",
        //   cmdlist_dzcd: "",
        //   cmdlist_ms: "",
        //   cmdlist_dz: "",
        // },
      ],
      clgl_name: "数来服务器",
      cmdlist_qsdz: "192.168.89.21",
      clgl_xy: "Modbus(TCP)",
      clgl_gzms: "透明模式",
      clgl_ydx: "有线区交换机",
      clgl_ydk: "5200",
      clgl_rkwk: "有线区网闸（内网）",
      clgl_rkip: "",
      clgl_rkwg: "",
      clgl_ckwk: "有线区网闸（外网）",
      clgl_ckip: "",
      clgl_ckwg: "",
      clgl_mddx: "无限区路由器",
      clgl_mddk: "",
      wlgl_nw_name: "",
      wlgl_nw_ip: "",
      wlgl_nw_zwym: "",
      wlgl_ww_name: "",
      wlgl_ww_ip: "",
      wlgl_ww_zwym: "",
      dxgl: [],
      cmdlist_ml: "",
      cmdlist_sbid: "",
      cmdlist_qsdz: "",
      cmdlist_dzcd: "",
      cmdlist_ms: "",
      cmdlist_dz: "",
      ruleForm1: {
        wlgl_nw_name: "",
        clgl_name: "",
        clgl_xy: [],
        clgl_gzms: "",
        clgl_ydx: "",
        clgl_ydk: "",
        clgl_mddx: "",
        clgl_mddk: "",
        clgl_rkwg: "",
        clgl_rkwk: "",
        clgl_rkip: "",
        clgl_ckwg: "",
        clgl_ckwk: "",
        clgl_ckip: "",
        clgl_wdyml: this.$t("addstrategy.clgl_wdyml"),
        clgl_rkip1: "",
        clgl_rkip2: "",
        clgl_rkip3: "",
        clgl_rkip4: "",
        clgl_ckip1: "",
        clgl_ckip2: "",
        clgl_ckip3: "",
        clgl_ckip4: "",
        clgl_rkwg1: "",
        clgl_rkwg2: "",
        clgl_rkwg3: "",
        clgl_rkwg4: "",
        clgl_ckwg1: "",
        clgl_ckwg2: "",
        clgl_ckwg3: "",
        clgl_ckwg4: "",
      },
      rules1: {
        clgl_name: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_name"),
          },
        ],
        clgl_xy: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_xy"),
          },
        ],
        clgl_gzms: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_gzms"),
          },
        ],
        clgl_mddk: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("addstrategy.rules1.clgl_mddk"),
          },
        ],
        clgl_rkwk: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_rkwk"),
          },
        ],
        clgl_ckwk: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_ckwk"),
          },
        ],
        clgl_rkip: [
          {
            required: true,
            validator: this.validateIpAddress,
            trigger: "blur",
            message: "",
          },
        ],

        clgl_ckip: [
          {
            required: true,
            validator: this.validateIpAddress1,
            trigger: "blur",
            message: "",
          },
        ],
        clgl_rkwg: [],
        clgl_ckwg: [],

        clgl_ydx: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_ydx"),
          },
        ],
        clgl_ydk: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("addstrategy.rules1.clgl_ydk"),
          },
        ],
        clgl_mddx: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("addstrategy.rules1.clgl_mddx"),
          },
        ],
        clgl_wdyml: [
          {
            required: true,
            trigger: "change",
            message: this.$t("addstrategy.rules1.clgl_wdyml"),
          },
        ],
      },
      ruleForm2: this.$t("addstrategy.ruleForm2"),
      rules2: {
        cmdlist_ml: [
          { required: true, trigger: "change", message: this.$t("addstrategy.rules2") },
        ],
        cmdlist_sbid: [
          { required: true, trigger: "change", message: this.$t("addstrategy.rules2") },
        ],
        cmdlist_qsdz: [
          { required: true, trigger: "change", message: this.$t("addstrategy.rules2") },
        ],
        cmdlist_dzcd: [
          { required: true, trigger: "change", message: this.$t("addstrategy.rules2") },
        ],
        cmdlist_dz: [
          { required: true, trigger: "change", message: this.$t("addstrategy.rules2") },
        ],
      },
      value: "",
      flag: false,
      json: {},
      arr: [],
      user_id: "",
    };
  },
  mounted() {
    let str = window.location.href.split("?")[1];
    this.user_id = decodeURIComponent(str).split("|")[0];
    let type = decodeURIComponent(str).split("|")[1];
    if (type == 1) {
      this.$store.commit("setType", "GYWZ_yx");
    } else {
      this.$store.commit("setType", "GYWZ_wx");
    }
    // alert(this.$route.query.id, this.$store.state.type);

    this.GetUserAnswer();
  },

  methods: {
    //ip地址验证
    validateIpAddress(rule, value, callback) {
      if (
        this.ruleForm1.clgl_rkip1 +
          "." +
          this.ruleForm1.clgl_rkip2 +
          "." +
          this.ruleForm1.clgl_rkip3 +
          "." +
          this.ruleForm1.clgl_rkip4 ===
        ""
      ) {
        callback(new Error(this.$t("addstrategy.rules1.nullIp")));
      } else if (
        !/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
          this.ruleForm1.clgl_rkip1 +
            "." +
            this.ruleForm1.clgl_rkip2 +
            "." +
            this.ruleForm1.clgl_rkip3 +
            "." +
            this.ruleForm1.clgl_rkip4
        )
      ) {
        callback(new Error(this.$t("addstrategy.rules1.valid")));
      } else {
        callback();
      }
    },
    validateIpAddress1(rule, value, callback) {
      if (
        this.ruleForm1.clgl_ckip1 +
          "." +
          this.ruleForm1.clgl_ckip2 +
          "." +
          this.ruleForm1.clgl_ckip3 +
          "." +
          this.ruleForm1.clgl_ckip4 ===
        ""
      ) {
        callback(new Error(this.$t("addstrategy.rules1.nullIp")));
      } else if (
        !/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
          this.ruleForm1.clgl_ckip1 +
            "." +
            this.ruleForm1.clgl_ckip2 +
            "." +
            this.ruleForm1.clgl_ckip3 +
            "." +
            this.ruleForm1.clgl_ckip4
        )
      ) {
        callback(new Error(this.$t("addstrategy.rules1.valid")));
      } else {
        callback();
      }
    },
    //保存
    async saveAll() {
      this.$refs["ruleForm1"].validate((valid) => {
        if (valid) {
          this.SaveUserAnswer();
        } else {
          return false;
        }
      });
    },
    //保存上传服务器方法---新增策略
    async SaveUserAnswer() {
      console.log(this.ruleForm1);
      var obj = {
        clgl_name: this.ruleForm1.clgl_name,
        clgl_xy: this.ruleForm1.clgl_xy,
        clgl_gzms: this.ruleForm1.clgl_gzms,
        clgl_ydx: this.ruleForm1.clgl_ydx,
        clgl_ydk: this.ruleForm1.clgl_ydk,
        clgl_rkwk: this.ruleForm1.clgl_rkwk,
        clgl_rkip:
          this.ruleForm1.clgl_rkip1 +
          "." +
          this.ruleForm1.clgl_rkip2 +
          "." +
          this.ruleForm1.clgl_rkip3 +
          "." +
          this.ruleForm1.clgl_rkip4,
        clgl_rkwg:
          this.ruleForm1.clgl_rkwg1 +
          "." +
          this.ruleForm1.clgl_rkwg2 +
          "." +
          this.ruleForm1.clgl_rkwg3 +
          "." +
          this.ruleForm1.clgl_rkwg4,
        clgl_ckwk: this.ruleForm1.clgl_ckwk,
        clgl_ckip:
          this.ruleForm1.clgl_ckip1 +
          "." +
          this.ruleForm1.clgl_ckip2 +
          "." +
          this.ruleForm1.clgl_ckip3 +
          "." +
          this.ruleForm1.clgl_ckip4,
        clgl_ckwg:
          this.ruleForm1.clgl_ckwg1 +
          "." +
          this.ruleForm1.clgl_ckwg2 +
          "." +
          this.ruleForm1.clgl_ckwg3 +
          "." +
          this.ruleForm1.clgl_ckwg4,
        clgl_mddx: this.ruleForm1.clgl_mddx,
        clgl_mddk: this.ruleForm1.clgl_mddk,
        clgl_wdyml: this.ruleForm1.clgl_wdyml,
        wlgl_nw_name: this.wlgl_nw_name,
        wlgl_nw_ip: this.wlgl_nw_ip,
        wlgl_nw_zwym: this.wlgl_nw_zwym,
        wlgl_ww_name: this.wlgl_ww_name,
        wlgl_ww_ip: this.wlgl_ww_ip,
        wlgl_ww_zwym: this.wlgl_ww_zwym,
        dxgl: this.dxgl,
        cmdlist_ml: this.ruleForm2.cmdlist_ml,
        cmdlist_sbid: this.ruleForm2.cmdlist_sbid,
        cmdlist_qsdz: this.ruleForm2.cmdlist_qsdz,
        cmdlist_dzcd: this.ruleForm2.cmdlist_dzcd,
        cmdlist_ms: this.ruleForm2.cmdlist_ms,
        cmdlist_dz: this.ruleForm2.cmdlist_dz,
      };
      console.log(obj);
      let { data } = await SaveUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
        mark_value: JSON.stringify(obj),
      });
      if (data.state) {
        this.$message({
          message: "缓存成功",
          type: "success",
        });
        // this.dialogVisible1 = false;
        this.$router.back();
      } else {
        this.$message.error("操作失败");
      }
    },
    //获取缓存数据
    async GetUserAnswer() {
      let { data } = await GetUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
      });
      if (!data.state) {
        getQueryAnswer({
          mark: this.$store.state.type,
          user_id: this.user_id,
        }).then((res1) => {
          console.log(JSON.parse(res1.data.data.r3), "xxxxxxxxxxx");
          let res = null;

          if (this.$i18n.locale === "zh") {
            res = JSON.parse(res1.data.data.r3_en_default);
          } else {
            res = JSON.parse(res1.data.data.r3);
          }
          if (res1.data.data) {
            this.clgl_name = res.clgl_name;
            this.clgl_xy = res.clgl_xy;
            this.clgl_gzms = res.clgl_gzms;
            this.clgl_mddk = res.clgl_mddk;
            this.clgl_ydx = res.clgl_ydx;
            this.clgl_ydk = res.clgl_ydk;
            this.clgl_mddk = res.clgl_mddk;
            this.clgl_rkwk = res.clgl_rkwk;
            this.clgl_wdyml = res.clgl_wdyml;
            this.clgl_ckwk = res.clgl_ckwk;
            this.wlgl_nw_name = res.wlgl_nw_name;
            this.wlgl_nw_ip = res.wlgl_nw_ip;
            this.wlgl_nw_zwym = res.wlgl_nw_zwym;
            this.wlgl_ww_name = res.wlgl_ww_name;
            this.wlgl_ww_ip = res.wlgl_ww_ip;
            this.wlgl_ww_zwym = res.wlgl_ww_zwym;
            this.dxgl = [].concat(res.dxgl);
            this.cmdlist_ml = res.cmdlist_ml;
            this.cmdlist_sbid = res.cmdlist_sbid;
            this.cmdlist_qsdz = res.cmdlist_qsdz;
            this.cmdlist_dzcd = res.cmdlist_dzcd;
            this.cmdlist_ms = res.cmdlist_ms;
            this.cmdlist_dz = res.cmdlist_dz;
          }
        });
      }
      if (data.data && data.state) {
        console.log(JSON.parse(data.data.mark_value), "xxxxxxxxxxx");
        let res = JSON.parse(data.data.mark_value);
        console.log(res);
        this.clgl_name = res.clgl_name;
        this.clgl_xy = res.clgl_xy;
        this.clgl_gzms = res.clgl_gzms;
        this.clgl_mddk = res.clgl_mddk;
        this.clgl_ydx = res.clgl_ydx;
        this.clgl_ydk = res.clgl_ydk;
        this.clgl_mddk = res.clgl_mddk;
        this.clgl_rkwk = res.clgl_rkwk;
        this.clgl_wdyml = res.clgl_wdyml;
        this.clgl_ckwk = res.clgl_ckwk;
        this.wlgl_nw_name = res.wlgl_nw_name;
        this.wlgl_nw_ip = res.wlgl_nw_ip;
        this.wlgl_nw_zwym = res.wlgl_nw_zwym;
        this.wlgl_ww_name = res.wlgl_ww_name;
        this.wlgl_ww_ip = res.wlgl_ww_ip;
        this.wlgl_ww_zwym = res.wlgl_ww_zwym;
        this.dxgl = [].concat(res.dxgl);
        this.cmdlist_ml = res.cmdlist_ml;
        this.cmdlist_sbid = res.cmdlist_sbid;
        this.cmdlist_qsdz = res.cmdlist_qsdz;
        this.cmdlist_dzcd = res.cmdlist_dzcd;
        this.cmdlist_ms = res.cmdlist_ms;
        this.cmdlist_dz = res.cmdlist_dz;
      }
      // console.log(this.dxgl);
      this.dxgl.forEach((item) => {
        this.arr.push(item.dx_name);
      });
      console.log(this.dxgl);
    },
    //新增命令-保存
    saveMl() {
      this.$refs["ruleForm2"].validate((valid) => {
        if (valid) {
          this.saveMlAnswer();
        } else {
          return false;
        }
      });
    },
    //新增命令方法
    async saveMlAnswer() {
      var obj = {
        cmdlist_ml: this.ruleForm2.cmdlist_ml,
        cmdlist_sbid: this.ruleForm2.cmdlist_sbid,
        cmdlist_qsdz: this.ruleForm2.cmdlist_qsdz,
        cmdlist_dzcd: this.ruleForm2.cmdlist_dzcd,
        cmdlist_ms: this.ruleForm2.cmdlist_ms,
        cmdlist_dz: this.ruleForm2.cmdlist_dz,
        clgl_name: this.ruleForm1.clgl_name,
        clgl_xy: this.ruleForm1.clgl_xy,
        clgl_gzms: this.ruleForm1.clgl_gzms,
        clgl_ydx: this.ruleForm1.clgl_ydx,
        clgl_ydk: this.ruleForm1.clgl_ydk,
        clgl_mddx: this.ruleForm1.clgl_mddx,
        clgl_mddk: this.ruleForm1.clgl_mddk,
        clgl_rkwg: this.ruleForm1.clgl_rkwg,
        clgl_rkwk: this.ruleForm1.clgl_rkwk,
        clgl_rkip: this.ruleForm1.clgl_rkip,
        clgl_ckwg: this.ruleForm1.clgl_ckwg,
        clgl_ckwk: this.ruleForm1.clgl_ckwk,
        clgl_ckip: this.ruleForm1.clgl_ckip,
        clgl_wdyml: this.ruleForm1.clgl_wdyml,
        wlgl_nw_name: this.wlgl_nw_name,
        wlgl_nw_ip: this.wlgl_nw_ip,
        wlgl_nw_zwym: this.wlgl_nw_zwym,
        wlgl_ww_name: this.wlgl_ww_name,
        wlgl_ww_ip: this.wlgl_ww_ip,
        wlgl_ww_zwym: this.wlgl_ww_zwym,
        dxgl: this.dxgl,
      };
      console.log(obj);
      let { data } = await SaveUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
        mark_value: JSON.stringify(obj),
      });
      if (data.state) {
        this.tableData1 = [
          {
            cmdlist_ml: this.ruleForm2.cmdlist_ml,
            cmdlist_sbid: this.ruleForm2.cmdlist_sbid,
            cmdlist_qsdz: this.ruleForm2.cmdlist_qsdz,
            cmdlist_dzcd: this.ruleForm2.cmdlist_dzcd,
            cmdlist_ms: this.ruleForm2.cmdlist_ms,
            cmdlist_dz: this.ruleForm2.cmdlist_dz,
          },
        ];
        this.flag = false;
        this.$message({
          message: "新增成功",
          type: "success",
        });
      } else {
        this.$message.error(data.message);
      }
    },
    //删除命令
    async handleDel(index, row) {
      this.tableData1 = [];
      var obj = {
        cmdlist_ml: "",
        cmdlist_sbid: "",
        cmdlist_qsdz: "",
        cmdlist_dzcd: "",
        cmdlist_ms: "",
        cmdlist_dz: "",
        clgl_name: this.ruleForm1.clgl_name,
        clgl_xy: this.ruleForm1.clgl_xy,
        clgl_gzms: this.ruleForm1.clgl_gzms,
        clgl_ydx: this.ruleForm1.clgl_ydx,
        clgl_ydk: this.ruleForm1.clgl_ydk,
        clgl_mddx: this.ruleForm1.clgl_mddx,
        clgl_mddk: this.ruleForm1.clgl_mddk,
        clgl_rkwg: this.ruleForm1.clgl_rkwg,
        clgl_rkwk: this.ruleForm1.clgl_rkwk,
        clgl_rkip: this.ruleForm1.clgl_rkip,
        clgl_ckwg: this.ruleForm1.clgl_ckwg,
        clgl_ckwk: this.ruleForm1.clgl_ckwk,
        clgl_ckip: this.ruleForm1.clgl_ckip,
        clgl_wdyml: this.ruleForm1.clgl_wdyml,
        wlgl_nw_name: this.wlgl_nw_name,
        wlgl_nw_ip: this.wlgl_nw_ip,
        wlgl_nw_zwym: this.wlgl_nw_zwym,
        wlgl_ww_name: this.wlgl_ww_name,
        wlgl_ww_ip: this.wlgl_ww_ip,
        wlgl_ww_zwym: this.wlgl_ww_zwym,
        dxgl: this.dxgl,
      };
      let { data } = await SaveUserAnswer({
        mark: this.$store.state.type,
        user_id: this.user_id,
        // mark: "GYWZ_wx",
        // user_id: "USER202307301109254198",
        mark_value: JSON.stringify(obj),
      });
      if (data.state) {
        this.$message({
          message: "删除成功",
          type: "success",
        });
      } else {
        this.$message.error(data.message);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.el-col-1 {
  padding: 0px 4px;
  line-height: 62px;
  height: 20px;
  text-align: center;
}

/deep/.el-col-5 {
  width: 43px;
  height: 30px;
  .el-input__inner {
    padding: 0;
    padding-left: 3px;
    box-sizing: border-box;
  }
}

/deep/.el-dialog__header {
  text-align: left;
  /* 标题左对齐 */
}

/deep/ .demo-ruleForm1 {
  .el-col-1 {
    padding: 0px 4px;
    line-height: 62px;
    height: 20px;
    text-align: center;
    color: transparent;
  }

  .el-col-5 {
    width: 43px;
    height: 30px;
  }
}
</style>
