<template>
  <div>
    <div>
      <el-dialog
        title="添加策略"
        :visible.sync="dialogVisible1"
        width="82%"
        :center="true"
      >
        <el-form
          :model="ruleForm1"
          :rules="rules1"
          ref="ruleForm1"
          label-width="150px"
          class="demo-ruleForm1"
          :label-position="labelPosition"
        >
          <el-row :justify="center">
            <el-col :span="6">
              <el-form-item label="名称:" prop="clgl_name">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_name"
                    placeholder="选择名称"
                  >
                    <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="源对象:" prop="clgl_ydx" style="color: red">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_ydx"
                    placeholder="选择对象"
                  >
                    <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="入口网关" 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="出口网关" 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="协议:" prop="clgl_xy">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_xy"
                    multiple
                    placeholder="请选择"
                  >
                    <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="源端口:" 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="入口网卡:" prop="clgl_rkwk">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_rkwk"
                    placeholder="选择配置的内网网卡"
                  >
                    <el-option :label="wlgl_nw_name" :value="wlgl_nw_name">
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item label="出口网卡:" prop="clgl_ckwk">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_ckwk"
                    placeholder="选择配置的外网网卡"
                  >
                    <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="工作模式:" prop="clgl_gzms">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_gzms" placeholder="请选择">
                    <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="目的对象:" prop="clgl_mddx">
                <el-col :span="19">
                  <el-select v-model="ruleForm1.clgl_mddx">
                    <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="入口IP" 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="出口IP" 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="未定义命令:" prop="clgl_wdyml">
                <el-col :span="19">
                  <el-select
                    v-model="ruleForm1.clgl_wdyml"
                    placeholder="请选择"
                  >
                    <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="目的端口:" 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">记录日志：</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">
            命令列表
          </h3>
          <el-button @click="flag = true">新增命令</el-button>
        </div>
        <el-divider></el-divider>
        <el-table :data="tableData1" style="width: 100%" border>
          <el-table-column label="序号">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template></el-table-column
          >
          <el-table-column prop="cmdlist_ml" label="命令(功能码)">
          </el-table-column>
          <el-table-column prop="cmdlist_qsdz" label="起始地址">
          </el-table-column>
          <el-table-column prop="cmdlist_dzcd" label="地址长度">
          </el-table-column>
          <el-table-column prop="cmdlist_ms" label="描述"> </el-table-column>
          <el-table-column prop="cmdlist_dz" label="动作"> </el-table-column>
          <el-table-column label="操作">
            <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)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="saveAll">保 存</el-button>
          <el-button @click="dialogVisible1 = false">取 消</el-button>
        </span>
      </el-dialog>
    </div>
    <div>
      <el-dialog title="新增命令" :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="命令:" prop="cmdlist_ml">
            <el-col :span="6">
              <el-select v-model="ruleForm2.cmdlist_ml" style="width: 200px">
                <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="设备ID:" prop="cmdlist_sbid" style="color: red">
            <el-col :span="6">
              <el-select v-model="ruleForm2.cmdlist_sbid" style="width: 200px">
                <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="起始地址:" 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="地址长度:" 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="描述:" 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="动作:" prop="cmdlist_dz">
            <el-col :span="6">
              <el-select v-model="ruleForm2.cmdlist_dz" style="width: 200px">
                <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">保存</el-button>
          <el-button @click="flag = false">取 消</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

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

  data() {
    return {
      switchvalue: false,
      clgl_qidong: true,
      options1: [
        {
          label: "有线区策略",
          value: "有线区策略",
        },
        {
          label: "无线区策略",
          value: "无线区策略",
        },
      ],
      options2: [
        {
          label: "OPC",
          value: "OPC",
        },
        {
          label: "Modbus(TCP)",
          value: "Modbus(TCP)",
        },
        {
          label: "DNP3",
          value: "DNP3",
        },
        {
          label: "S7",
          value: "S7",
        },
        {
          label: "EC104",
          value: "EC104",
        },
      ],
      options3: [
        {
          label: "代理模式",
          value: "代理模式",
        },
        {
          label: "路由模式",
          value: "路由模式",
        },
        {
          label: "透明模式",
          value: "透明模式",
        },
      ],
      options4: [
        {
          label: "有线区交换机",
          value: "有线区交换机",
        },
        {
          label: "无线区路由器",
          value: "无线区路由器",
        },
      ],
      options5: [
        {
          label: "拒绝",
          value: "拒绝",
        },
        {
          label: "允许",
          value: "允许",
        },
      ],
      options6: [
        {
          label: "读线圈状态",
          value: "读线圈状态",
        },
        {
          label: "读输入状态",
          value: "读输入状态",
        },
        {
          label: "读线保持寄存器",
          value: "读线保持寄存器",
        },
        {
          label: "读输入寄存器",
          value: "读输入寄存器",
        },
        {
          label: "强制单个线圈",
          value: "强制单个线圈",
        },
        {
          label: "预置单个寄存器",
          value: "预置单个寄存器",
        },
        {
          label: "强制多个寄存器",
          value: "强制多个寄存器",
        },
      ],
      options7: [
        {
          label: "有线区交换机命令",
          value: "有线区交换机命令",
        },
        {
          label: "无线区路由器命令",
          value: "无线区路由器命令",
        },
      ],
      options8: [
        {
          label: "有线区网闸（内网）",
          value: "有线区网闸（内网）",
        },
        {
          label: "无线区网闸（内网）",
          value: "无线区网闸（内网）",
        },
      ],
      options9: [
        {
          label: "有线区网闸（外网）",
          value: "有线区网闸（外网）",
        },
        {
          label: "无线区网闸（内网）",
          value: "无线区网闸（内网）",
        },
      ],
      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: "拒绝",
        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: "选择一个名称" },
        ],
        clgl_xy: [
          {
            required: true,
            trigger: "change",
            message: "至少选择一个选择协议",
          },
        ],
        clgl_gzms: [
          { required: true, trigger: "change", message: "选择一个工作模式" },
        ],
        clgl_mddk: [
          { required: true, trigger: "blur", message: "目的端口是必填参数" },
        ],
        clgl_rkwk: [
          { required: true, trigger: "change", message: "选择一个入口网卡" },
        ],
        clgl_ckwk: [
          { required: true, trigger: "change", message: "选择一个出口网卡" },
        ],
        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: "选择一个源对象" },
        ],
        clgl_ydk: [
          { required: true, trigger: "blur", message: "源端口不能为空" },
        ],
        clgl_mddx: [
          { required: true, trigger: "blur", message: "源端口不能为空" },
        ],
        clgl_wdyml: [
          { required: true, trigger: "change", message: "选择一个命令" },
        ],
      },
      ruleForm2: {
        cmdlist_ml: "读线圈状态",
        cmdlist_sbid: "",
        cmdlist_qsdz: "",
        cmdlist_dzcd: "",
        cmdlist_ms: "",
        cmdlist_dz: "",
      },
      rules2: {
        cmdlist_ml: [{ required: true, trigger: "change", message: "必填项" }],
        cmdlist_sbid: [
          { required: true, trigger: "change", message: "必填项" },
        ],
        cmdlist_qsdz: [
          { required: true, trigger: "change", message: "必填项" },
        ],
        cmdlist_dzcd: [
          { required: true, trigger: "change", message: "必填项" },
        ],
        cmdlist_dz: [{ required: true, trigger: "change", message: "必填项" }],
      },
      value: "",
      flag: false,
      json: {},
      arr: [],
    };
  },
  mounted() {
    alert(this.$route.query.id, this.$store.state.type);
    console.log(this.user_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("请输入IP地址"));
      } 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("请输入有效的IP地址"));
      } 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("请输入IP地址"));
      } 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("请输入有效的IP地址"));
      } 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.$route.query.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.$route.query.id,
    //     mark: "GYWZ_wx",
    //     user_id: "USER202307301109254198",
    //   });
    //   if (data.data && data.state) {
    //     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);
    //   });
    // },
    //新增命令-保存
    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.$route.query.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.$route.query.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>
