<!-- 斥候有线 的新建设备配置 -->
<template>
  <div>
    <!-- 设置树形控件 -->
    <!-- <div v-click-outside="closeMenu"> -->
    <!-- <el-button type="info" plain @click="dialogVisible = true">斥候通道配置</el-button> -->
    <div class="tree_menu" v-show="dialogVisible">
      <el-tree
        :data="trees"
        node-key="id"
        :props="defaultProps"
        default-expand-all
        @node-contextmenu="rightClick"
        @node-click="treeNodeClick"
        ref="tree"
      >
      </el-tree>
      <!-- 树形控件右键组件 -->
      <div v-show="menuShow" class="tree_rightmenu" :style="{ ...rightMenu }">
        <el-menu
          class="el-menu-vertical-demo"
          @select="selectMenuNode"
          default-active="#0078FE"
        >
          <el-menu-item id="menuitem" index="1" style="font-size: 12px">
            <span slot="title">{{$t('addDevice')}}</span>
          </el-menu-item>
          <el-menu-item index="2" style="font-size: 12px">
            <span slot="title">{{$t('cancel')}}</span>
          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <!-- </div> -->
    <div :class="$i18n.locale==='zh'?'zh_params pas_params':'pas_params'">
      <el-dialog
        :title="$t('reconnoitreConfiguration.title')"
        :visible.sync="add_passage"
        width="902px"
        v-loading="loading"
      >
        <el-form
          :model="formData"
          :label-position="labelPosition"
          :rules="rules"
          ref="formData"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item
                :label="$t('reconnoitreConfiguration.name')"
                :label-width="formLabelWidth"
                prop="sbpz_sbmc"
              >
                <el-select
                  v-model="formData.sbpz_sbmc"
                  placeholder=""
                  style="width: 200px; height: 30px"
                >
                  <el-option
                    v-for="item in options1"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('reconnoitreConfiguration.controllerProtocol')"
                :label-width="formLabelWidth"
                prop="sbpz_kzqxy"
              >
                <el-row>
                  <el-col :span="18">
                    <el-input
                      v-model="formData.sbpz_kzqxy"
                      placeholder=""
                      style="width: 200px; height: 30px"
                      disabled
                    ></el-input>
                  </el-col>
                  <el-col :span="6">
                    <el-button
                      style="width: 50px; height: 30px"
                      @click="getDriveName"
                      >...</el-button
                    >
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                  :label="$t('reconnoitreConfiguration.IPAddress')"
                :label-width="formLabelWidth"
                prop="sbpz_ip"
              >
                <el-row>
                  <el-col :span="5">
                    <el-input
                      v-model="sbpz_ip1"
                      style="width: 43px; height: 30px"
                      maxlength="3"
                    ></el-input>
                  </el-col>
                  <el-col :span="1">. </el-col>
                  <el-col :span="5">
                    <el-input
                      v-model="sbpz_ip2"
                      style="width: 43px; height: 30px"
                      maxlength="3"
                    ></el-input>
                  </el-col>
                  <el-col :span="1">.</el-col>
                  <el-col :span="5">
                    <el-input
                      v-model="sbpz_ip3"
                      style="width: 43px; height: 30px"
                      maxlength="3"
                    ></el-input>
                  </el-col>
                  <el-col :span="1">.</el-col>
                  <el-col :span="5">
                    <el-input
                      v-model="sbpz_ip4"
                      style="width: 43px; height: 30px"
                      maxlength="3"
                    ></el-input>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                  :label="$t('reconnoitreConfiguration.portNumber')"
                :label-width="formLabelWidth"
                prop="sbpz_port"
              >
                <el-input
                  v-model="formData.sbpz_port"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row> </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                  :label="$t('reconnoitreConfiguration.slaveAddress')"
                :label-width="formLabelWidth"
                prop="sbpz_czdz"
              >
                <el-input
                  v-model="formData.sbpz_czdz"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                  :label="$t('reconnoitreConfiguration.pollTime')"
                :label-width="formLabelWidth"
                prop="sbpz_lxzq"
              >
                <el-input
                  v-model="formData.sbpz_lxzq"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
                <div class="infos">1-3600</div>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- </el-form> -->
          <div class="super_parmams">
            <h3>{{ $t('reconnoitreConfiguration.params') }}</h3>
            <div>
              <i class="el-icon-caret-bottom" v-if="is_retract"></i>
              <i class="el-icon-caret-top" v-else="is_retract"></i>
              <el-button
                type="text"
                plain
                @click="getRetract"
                style="
                  color: rgba(16, 16, 16, 1);
                  font-size: 14px;
                  text-align: left;
                  border: none;
                "
              >
                {{$t('put')}}</el-button
              >
            </div>
          </div>
          <el-divider></el-divider>
          <div :class="$i18n.locale==='zh'?'zh_con super_con':'super_con'" v-show="is_retract">
            <!-- <el-form :label-position="labelPosition" :rules="rules" ref="ruleForm"> -->
            <el-row>
              <el-col :span="12">
                <el-form-item
                  :label="$t('reconnoitreConfiguration.millisecond')"
                  :label-width="$i18n.locale==='zh'?labelWidth:formLabelWidth"
                  prop="sbpz_qyhmcj"
                >
                  <el-switch v-model="formData.sbpz_qyhmcj"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                    :label="$t('reconnoitreConfiguration.batch')"
                    :label-width="$i18n.locale==='zh'?labelWidth:formLabelWidth"
                  prop="sbpz_qyplcj"
                >
                  <el-switch v-model="formData.sbpz_qyplcj"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                    :label="$t('reconnoitreConfiguration.maxBatch')"
                    :label-width="labelWidth"
                  prop="sbpz_zdplcjs"
                >
                  <el-input
                    v-model="formData.sbpz_zdplcjs"
                    style="width: 200px; height: 30px"
                  ></el-input>
                  <div class="infos">2-125</div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                    :label="$t('reconnoitreConfiguration.overTime')"
                    :label-width="labelWidth"
                  prop="sbpz_cjcgsj"
                >
                  <el-input
                    v-model="formData.sbpz_cjcgsj"
                    style="width: 200px; height: 30px"
                  ></el-input>
                  <div class="infos">2-60000</div>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                    :label="$t('reconnoitreConfiguration.onChangData')"
                  :label-width="$i18n.locale==='zh'?labelWidth:'185px'"
                  prop="sbpz_zqsbonchange"
                >
                  <el-switch v-model="formData.sbpz_zqsbonchange"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                    :label="$t('reconnoitreConfiguration.intervalTime')"
                    :label-width="labelWidth"
                  prop="sbpz_txsjjg"
                >
                  <el-input
                    v-model="formData.sbpz_txsjjg"
                    style="width: 200px; height: 30px"
                  ></el-input>
                  <div class="infos">0-1000</div>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="footer_con">
              <el-row>
                <el-col :span="12">
                  <el-form-item
                      :label="$t('reconnoitreConfiguration.writeFunction1')"
                      :label-width="$i18n.locale==='zh'?'286px':'130px'"
                    style="line-height: 20px"
                    class="cjjcq_code"
                  >
                    <el-select
                      v-model="formData.sbpz_xqjcqxr"
                      placeholder=""
                      style="width: 200px; height: 30px"
                    >
                      <el-option
                        v-for="item in options2"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                      :label="$t('reconnoitreConfiguration.writeFunction2')"
                      :label-width="$i18n.locale==='zh'?'286px':'130px'"
                    class="cjjcq_code"
                  >
                    <el-select
                      v-model="formData.sbpz_bcjcqxr"
                      placeholder=""
                      style="width: 200px; height: 30px"
                    >
                      <el-option
                        v-for="item in options3"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">{{ $t('save') }}</el-button>
          <el-button @click="add_passage = false">{{ $t('cancel') }}</el-button>
        </span>
      </el-dialog>
    </div>
    <div class="drvieName_All" v-show="diag_drive">
      <div class="title">
        <p class="title_l">{{ $t('reconnoitreConfiguration.agreementName') }}</p>
        <i class="el-icon-close title_r" @click="diag_drive = false;"></i>
      </div>
      <el-divider></el-divider>
      <el-tree
        :data="datas2"
        :props="defaultProps"
        @node-click="handleDetailClick"
        default-expand-all
      ></el-tree>
    </div>

    <!-- 网关信息 -->
    <div class="gateway">
      <el-dialog :title="$t('dbcollectiongate.title')" :visible.sync="outerVisible" width="382px">
        <el-form
          :model="formData"
          :rules="rulesGate"
          ref="gateWay"
          :label-width="$i18n.locale === 'zh'?'130px':'85px'"
          class="demo-ruleForm"
        >
          <el-form-item :label="$t('dbcollectiongate.name')" prop="wgpz_wgmc">
            <el-select
              v-model="formData.wgpz_wgmc"
              :placeholder="$t('select')"
              style="width: 200px"
            >
              <el-option
                v-for="item in opts1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('dbcollectiongate.ID')" prop="wgpz_wgid">
            <el-select
              v-model="formData.wgpz_wgid"
              :placeholder="$t('select')"
              style="width: 200px"
            >
              <el-option
                v-for="item in opts2"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer-outer">
          <el-button type="primary" @click="submitGate">{{ $t('save') }}</el-button>
          <el-button @click="outerVisible = false">{{ $t('cancel') }}</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import _ from "lodash";
import {SaveUserAnswer, GetUserAnswer, GetTree, SendTree, getQueryAnswer} from "@/api/user";
export default {
  name: "ChiDevice",
  data() {
    return {
      labelWidth:this.$i18n.locale==='zh'?'280px':'156px',
      user_id: "",
      loading: false,
      flag: false,
      nodekey: "",
      gateway: "",
      trees: [],
      formData: {
        ippz_wllx: "",
        ippz_ip: "",
        ippz_zwym: "",
        ippz_wg: "",
        ippz_dns: "",
        ippz_dns_by: "",

        wgpz_wgmc: "",
        wgpz_wgid: "",

        sbpz_sbmc: "",
        sbpz_kzqxy: "",
        sbpz_ip: "",
        sbpz_port: "",
        sbpz_czdz: "",
        sbpz_lxzq: "",
        sbpz_qyhmcj: false,
        sbpz_qyplcj: true,
        sbpz_zdplcjs: "",
        sbpz_cjcgsj: "",
        sbpz_zqsbonchange: false,
        sbpz_txsjjg: "",
        sbpz_xqjcqxr: "05",
        sbpz_bcjcqxr: "06",

        cjdpz_tagid: "",
        cjdpz_mc: "",
        cjdpz_sjq: "",
        cjdpz_jcqdz: "",
        cjdpz_cjsjlx: "",
        cjdpz_dxsx: "",
        cjdpz_scms: "",

        mqtt_ip: "",
        mqtt_wgsn: "",
        mqtt_port: "",
        mqtt_keepalive: "",

        mqtt_sssjfbzt: "",
        mqtt_qos: "",

        mqtt_cjd_sbmc: "",
        mqtt_cjd_tagid: "",
      },
      diag_drive: false,
      sbpz_ip1: "",
      sbpz_ip2: "",
      sbpz_ip3: "",
      sbpz_ip4: "",
      firstlabel: "",
      options1: this.$t('reconnoitreConfiguration.options1'),
      options3: [
        {
          value: "06",
          label: "06",
        },
      ],
      isdisabled: true,
      radio: "1",
      checked1: false,
      is_retract: true,
      labelPosition: "left",
      formLabelWidth: this.$i18n.locale==='zh'?'155px':"116px",
      input1: 192,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      datas: [
        {
          label: "Gateway",
          children: [
            {
              label: "数据采集",
              children: [
                {
                  label: "I/O点",
                },
                {
                  label: "用户点",
                },
                {
                  label: "计算点",
                },
                {
                  label: "系统点",
                },
              ],
            },
            {
              label: "上云服务",
              children: [
                {
                  label: "标准 MQTT",
                },
                {
                  label: "AWS loT",
                },
              ],
            },
          ],
        },
      ],
      datas2: [
        {
          label: "Allen-Bradley",
          children: [
            {
              label: "EtherNet/IP(ControlLogix)",
            },
            {
              label: "EtherNet/IP(MicroLogix)",
            },
          ],
        },
        {
          label: "Modbus",
          children: [
            {
              label: "Modbus TCP",
            },
            {
              label: "Modbus RTU",
            },
            {
              label: "Modbus ASCII",
            },
            {
              label: "Modbus RTU Over TCP",
            },
          ],
        },
        {
          label: "MITSUBISHI",
          children: [
            {
              label: "Mitsubishi CPU Port(Serial)",
            },
            {
              label: "Mitsubishi MC 3C",
            },
            {
              label: "Mitsubishi MC 1E",
            },
            {
              label: "Mitsubishi MC 3E",
            },
            {
              label: "Mitsubishi MC 3C Over TCP",
            },
          ],
        },
        {
          label: "OMRON",
          children: [
            {
              label: "FINS TCP",
            },
            {
              label: "FINS UDP",
            },
            {
              label: "HostLink",
            },
          ],
        },
        {
          label: "SIEMENS",
          children: [
            {
              label: "ISO-on-TCP",
            },
            {
              label: "PPI",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      rules: {
        sbpz_sbmc: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_sbmc'), trigger: "change" },
        ],
        sbpz_kzqxy: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_kzqxy'), trigger: "blur" },
        ],
        sbpz_ip: [
          {
            required: true,
            message: "",
            validator: this.validateIp,
            trigger: "blur",
          },
        ],
        sbpz_czdz: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_czdz'), trigger: "blur" },
        ],
        sbpz_port: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_port'), trigger: "blur" },
        ],
        sbpz_lxzq: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_lxzq'), trigger: "blur" },
        ],
        sbpz_qyhmcj: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_qyhmcj'), trigger: "change" },
        ],
        sbpz_qyplcj: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_qyplcj'), trigger: "change" },
        ],
        sbpz_zdplcjs: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_zdplcjs'), trigger: "blur" },
        ],
        sbpz_cjcgsj: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_cjcgsj'), trigger: "blur" },
        ],
        sbpz_zqsbonchange: [
          {
            required: true,
            message: "周期上报Onchange数据",
            trigger: "change",
          },
        ],
        sbpz_txsjjg: [
          { required: true, message: this.$t('reconnoitreConfiguration.rules.sbpz_txsjjg'), trigger: "blur" },
        ],
      },

      // 网关配置的出现
      outerVisible: false,
      gateWay: {
        wgpz_wgmc: "",
        wgpz_wgid: "",
        wgpz_wglx: "",
      },
      rulesGate: {
        wgpz_wgmc: [
          { required: true, message: this.$t('dbcollectiongate.rules.wgpz_wgmc'), trigger: "blur" },
        ],
        wgpz_wgid: [
          { required: true, message: this.$t('dbcollectiongate.rules.wgpz_wgid'), trigger: "blur" },
        ],
      },
      opts1:this.$t('dbcollectiongate.options2'),
      opts2: [
        {
          value: "LAN-BOX2",
          label: "LAN-BOX2",
        },
        {
          value: "WLAN-BOX2",
          label: "WLAN-BOX2",
        },
      ],
    };
  },

  methods: {
    //ip地址验证
    validateIp(rule, value, callback) {
      if (
        this.sbpz_ip1 +
          "." +
          this.sbpz_ip2 +
          "." +
          this.sbpz_ip3 +
          "." +
          this.sbpz_ip4 ===
        "..."
      ) {
        callback(new Error(this.$t('reconnoitreConfiguration.rules.sbpz_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.sbpz_ip1 +
            "." +
            this.sbpz_ip2 +
            "." +
            this.sbpz_ip3 +
            "." +
            this.sbpz_ip4
        )
      ) {
        callback(new Error(this.$t('reconnoitreConfiguration.rules.sbpz_ip1')));
      } else {
        callback();
      }
    },
    // 提交时的校验
    submitForm: _.debounce(function () {
      this.$refs["formData"].validate((valid) => {
        if (valid) {
          this.saveDevice();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }, 1000),
    async rightClick(e, data, node) {
      if (data.editing) {
        this.outerVisible = true;
        // let res2 = await GetUserAnswer({
        //   mark: "CHGYWG_yx",
        //   user_id: this.user_id,
        //   // user_id: "USER202307301114011710",
        // });
        // if (res2.data.data && res2.data.state) {
        //   console.log(res2.data.data.mark_value);
        //   let res3 = JSON.parse(res2.data.data.mark_value);
        //   this.gateWay.wgpz_wgid = res3.wgpz_wgid;
        //   // console.log(this.formData.wgpz_wgid);
        //   this.gateWay.wgpz_wgmc = res3.wgpz_wgmc;
        // }
        this.GetUserAnswer();
      }
      if (node.level == 2) {
        this.menuShow = false;
        this.menuShow = true;
        this.nodekey = data.id;
        e.preventDefault(); //关闭浏览器右键默认事件
        this.rightMenu = { top: e.pageY + "px", left: e.pageX + "px" };
        document.addEventListener("click", (ev) => {
          ev.stopImmediatePropagation();
          if (ev.target !== document.querySelector(".el-menu-item.is-active")) {
            this.foo();
          }
        });
      }
    },
    // 点击时候的判断,判断是否为新增网关
    selectMenuNode(index, indexPath) {
      console.log(index);
      if (index == 1) {
        this.add_passage = true;
      }
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick() {
      this.foo();
    },
    // 收起点击事件的判断
    getRetract() {
      if (this.is_retract == true) {
        this.is_retract = false;
      } else {
        this.is_retract = true;
      }
    },
    getDriveName() {
      this.diag_drive = true;
    },
    closeMenu(ev) {
      console.log({ ev });
      this.dialogVisible = false;
    },
    handleDetailClick(data, node, value) {
      console.log(data.label);
      if (node.childNodes.length == 0) {
        this.formData.sbpz_kzqxy = data.label;
        this.diag_drive = false;
      }
    },
    async saveDevice() {
      var obj = {
        sbpz_sbmc: this.formData.sbpz_sbmc,
        sbpz_kzqxy: this.formData.sbpz_kzqxy,
        sbpz_ip:
          this.sbpz_ip1 +
          "." +
          this.sbpz_ip2 +
          "." +
          this.sbpz_ip3 +
          "." +
          this.sbpz_ip4,
        sbpz_port: this.formData.sbpz_port,
        sbpz_czdz: this.formData.sbpz_czdz,
        sbpz_lxzq: this.formData.sbpz_lxzq,
        sbpz_qyhmcj: String(Number(this.formData.sbpz_qyhmcj)),
        sbpz_qyplcj: String(Number(this.formData.sbpz_qyplcj)),
        sbpz_zdplcjs: this.formData.sbpz_zdplcjs,
        sbpz_cjcgsj: this.formData.sbpz_cjcgsj,
        sbpz_zqsbonchange: String(Number(this.formData.sbpz_zqsbonchange)),
        sbpz_txsjjg: this.formData.sbpz_txsjjg,
        sbpz_xqjcqxr: this.formData.sbpz_xqjcqxr,
        sbpz_bcjcqxr: this.formData.sbpz_bcjcqxr,
      };
      console.log(obj, "111111111");
      let datas = { ...this.formData, ...obj };
      console.log(datas, "3333333");
      let res = await SaveUserAnswer({
        mark: "CHGYWG_yx",
        user_id: this.user_id,
        mark_value: JSON.stringify(datas),
        step: "2",
      });
      console.log(res);
      if (res.data.state) {
        this.$message({
          message: "保存成功",
          type: "success",
        });
        this.$refs["tree"].append(
          {
            id: this.nodekey + 1000,
            label: this.formData.sbpz_sbmc,
          },
          this.nodekey
        );
        this.sendTree();
        this.$router.push(`/collectionpoint?user_id=${this.user_id}`);
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
      // console.log(res);
    },
    async GetUserAnswer() {
      this.loading = true;
      let { data } = await GetUserAnswer({
        mark: "CHGYWG_yx",
        user_id: this.user_id,
      });
      this.loading = false;
      console.log(data, "斥候有网关设置页面");
      if(!data.state){
        getQueryAnswer({
          mark: "CHGYWG_yx",
          user_id: this.user_id
        }).then(res => {
          let obj = JSON.parse(res.data.data.r3);
          if (obj.sbpz_ip) {
            this.sbpz_ip1 = obj.sbpz_ip.split(".")[0];
            this.sbpz_ip2 = obj.sbpz_ip.split(".")[1];
            this.sbpz_ip3 = obj.sbpz_ip.split(".")[2];
            this.sbpz_ip4 = obj.sbpz_ip.split(".")[3];
            this.formData.sbpz_zqsbonchange = Boolean(
                Number(obj.sbpz_zqsbonchange)
            );
            this.formData.sbpz_qyhmcj = Boolean(Number(obj.sbpz_qyhmcj));
            this.formData.sbpz_qyplcj = Boolean(Number(obj.sbpz_qyplcj));
          }
          this.formData.sbpz_sbmc = obj.sbpz_sbmc;
          this.formData.sbpz_kzqxy = obj.sbpz_kzqxy;
          this.formData.sbpz_port = obj.sbpz_port;
          this.formData.sbpz_czdz = obj.sbpz_czdz;
          this.formData.sbpz_lxzq = obj.sbpz_lxzq;
          this.formData.sbpz_zdplcjs = obj.sbpz_zdplcjs;
          this.formData.sbpz_cjcgsj = obj.sbpz_cjcgsj;
          // console.log(this.formData.sbpz_zqsbonchange);
          this.formData.sbpz_txsjjg = obj.sbpz_txsjjg;
          this.formData.sbpz_xqjcqxr = obj.sbpz_xqjcqxr;
          this.formData.sbpz_bcjcqxr = obj.sbpz_bcjcqxr;
          this.formData.wgpz_wgid = obj.wgpz_wgid;
          this.formData.wgpz_wgmc = obj.wgpz_wgmc;

          this.formData.ippz_wllx = obj.ippz_wllx;
          this.formData.ippz_ip = obj.ippz_ip;
          this.formData.ippz_zwym = obj.ippz_zwym;
          this.formData.ippz_wg = obj.ippz_wg;
          this.formData.ippz_dns = obj.ippz_dns;
          this.formData.ippz_dns_by = obj.ippz_dns_by;

          this.formData.cjdpz_tagid = obj.mqtt_cjd_tagid;
          this.formData.cjdpz_mc = obj.cjdpz_mc;
          this.formData.cjdpz_sjq = obj.cjdpz_sjq;
          this.formData.cjdpz_jcqdz = obj.cjdpz_cjsjlx;
          this.formData.cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
          this.formData.cjdpz_dxsx = obj.cjdpz_dxsx;
          this.formData.cjdpz_scms = obj.cjdpz_scms;

          this.formData.mqtt_ip = obj.mqtt_ip;
          this.formData.mqtt_wgsn = obj.mqtt_wgsn;
          this.formData.mqtt_port = obj.mqtt_port;
          this.formData.mqtt_keepalive = obj.mqtt_keepalive;
          // this.formData.mqtt_tls = obj.mqtt_tls;
          // this.formData.mqtt_clearsession = obj.mqtt_clearsession;
          this.formData.mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
          this.formData.mqtt_qos = obj.mqtt_qos;

          this.formData.mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
          this.formData.mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
        })
      }
      // console.log(data, "22222222");
      // console.log(JSON.parse(data.data.mark_value));
      if (data.data && data.state) {
        let obj = JSON.parse(data.data.mark_value);
        if (obj.sbpz_ip) {
          this.sbpz_ip1 = obj.sbpz_ip.split(".")[0];
          this.sbpz_ip2 = obj.sbpz_ip.split(".")[1];
          this.sbpz_ip3 = obj.sbpz_ip.split(".")[2];
          this.sbpz_ip4 = obj.sbpz_ip.split(".")[3];
          this.formData.sbpz_zqsbonchange = Boolean(
            Number(obj.sbpz_zqsbonchange)
          );
          this.formData.sbpz_qyhmcj = Boolean(Number(obj.sbpz_qyhmcj));
          this.formData.sbpz_qyplcj = Boolean(Number(obj.sbpz_qyplcj));
        }
        this.formData.sbpz_sbmc = obj.sbpz_sbmc;
        this.formData.sbpz_kzqxy = obj.sbpz_kzqxy;
        this.formData.sbpz_port = obj.sbpz_port;
        this.formData.sbpz_czdz = obj.sbpz_czdz;
        this.formData.sbpz_lxzq = obj.sbpz_lxzq;
        this.formData.sbpz_zdplcjs = obj.sbpz_zdplcjs;
        this.formData.sbpz_cjcgsj = obj.sbpz_cjcgsj;
        // console.log(this.formData.sbpz_zqsbonchange);
        this.formData.sbpz_txsjjg = obj.sbpz_txsjjg;
        this.formData.sbpz_xqjcqxr = obj.sbpz_xqjcqxr;
        this.formData.sbpz_bcjcqxr = obj.sbpz_bcjcqxr;
        this.formData.wgpz_wgid = obj.wgpz_wgid;
        this.formData.wgpz_wgmc = obj.wgpz_wgmc;

        this.formData.ippz_wllx = obj.ippz_wllx;
        this.formData.ippz_ip = obj.ippz_ip;
        this.formData.ippz_zwym = obj.ippz_zwym;
        this.formData.ippz_wg = obj.ippz_wg;
        this.formData.ippz_dns = obj.ippz_dns;
        this.formData.ippz_dns_by = obj.ippz_dns_by;

        this.formData.cjdpz_tagid = obj.mqtt_cjd_tagid;
        this.formData.cjdpz_mc = obj.cjdpz_mc;
        this.formData.cjdpz_sjq = obj.cjdpz_sjq;
        this.formData.cjdpz_jcqdz = obj.cjdpz_cjsjlx;
        this.formData.cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
        this.formData.cjdpz_dxsx = obj.cjdpz_dxsx;
        this.formData.cjdpz_scms = obj.cjdpz_scms;

        this.formData.mqtt_ip = obj.mqtt_ip;
        this.formData.mqtt_wgsn = obj.mqtt_wgsn;
        this.formData.mqtt_port = obj.mqtt_port;
        this.formData.mqtt_keepalive = obj.mqtt_keepalive;
        // this.formData.mqtt_tls = obj.mqtt_tls;
        // this.formData.mqtt_clearsession = obj.mqtt_clearsession;
        this.formData.mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
        this.formData.mqtt_qos = obj.mqtt_qos;

        this.formData.mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
        this.formData.mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
      }
      console.log(this.formData, "8888888");
    },
    async sendTree() {
      let result = await SendTree({
        user_id: this.user_id,
        data: JSON.stringify(this.trees),
        type: "3",
      });
      console.log(result);
    },
    async getTree() {
      let res = await GetTree({
        user_id: this.user_id,
        type: "3",
      });
      if(this.$i18n.locale==='zh'){
        this.trees = JSON.parse(res.data.data.r2);
      }else{
        this.trees = JSON.parse(res.data.data.data);
      }
    },
    //网关配置的信息
    async submitGate() {
      this.$refs["gateWay"].validate((valid) => {
        if (valid) {
          // console.log('submit!');
          this.saveGates();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //
    async saveGates() {
      this.outerVisible = false;

      let res = await SaveUserAnswer({
        mark: "CHGYWG_yx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        mark_value: JSON.stringify(this.formData),
      });
      if (res.data.state) {
        this.$message({
          message: "修改成功",
          type: "success",
        });
        this.trees[0].label = this.formData.wgpz_wgid;
        this.sendTree();
      } else {
        this.$message({
          message: `保存失败,原因是${res.data.message}`,
          type: "error",
        });
      }
      console.log(res);
    },
  },
  mounted() {
    this.user_id = this.$route.query.user_id;
    console.log(this.user_id);
    this.formData.sbpz_xqjcqxr = "05";
    this.formData.sbpz_bcjcqxr = "06";
    // console.log(this.$route.query.firstlabel);
    if (this.user_id != "undefined") {
      this.getTree();
    }
    // this.trees[0].label = this.$route.query.firstlabel;
    this.GetUserAnswer();
  },
  watch: {
    checked1: {
      handler(old) {
        if (old) {
          this.isdisabled = false;
        } else {
          this.isdisabled = true;
        }
      },
    },
  },
  directives: {
    "click-outside": {
      bind: function (el, binding, vnode) {
        console.log("el", el);
        console.log("binding", binding);
        el.event = function (event) {
          // 检查点击是否发生在节点之内（包括子节点）
          if (!(el == event.target || el.contains(event.target))) {
            // 如果没有，则触发调用
            // 若绑定值为函数，则执行
            // 这里我们可以通过钩子函数中的 vnode.context，来获取当前组件的作用域
            if (typeof vnode.context[binding.expression] == "function") {
              vnode.context[binding.expression](event);
            }
          }
        };
        // 绑定事件
        // 设置为true，代表在DOM树中，注册了该listener的元素，会先于它下方的任何事件目标，接收到该事件。
        document.body.addEventListener("click", el.event, true);
      },
      unbind: function (el) {
        // 解绑事件
        document.body.removeEventListener("click", el.event, true);
      },
    },
  },
};
</script>

<style lang="less" scoped>
.tree_menu {
  position: absolute;
  width: 286px;
  height: 753px;
  left: 64px;
  top: 104px;
  width: 286px;
  height: 753px;
  line-height: 20px;
  border-radius: 3px;
  background-color: rgba(255, 255, 255, 1);
  text-align: center;
  border: 1px solid rgba(220, 220, 220, 1);
}

.tree_rightmenu {
  position: fixed;
  width: 120px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  z-index: 1000;
}

.super_parmams {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 668px;

  i {
    width: 24px;
    height: 24px;
    display: inline-block;
  }
}
.zh_con{
  .el-col-12{
    width: 100% !important;
  }
  .el-row{
    display:block !important;
  }
}
 .zh_params{

    .el-col-12:last-child {
      padding-right: 100px !important;
    }

    .el-col-12:first-child {
      padding-right: 66px !important;
    }
}
/deep/ .pas_params {
  .el-form-item {
    margin-bottom: 25px !important;
  }

  .el-col-12:last-child {
    padding-right: 150px;
  }

  .el-col-12:first-child {
    padding-right: 102px;
  }

  .el-divider--horizontal {
    margin: 8px 0px;
  }

  .el-input__inner {
    height: 30px;
    text-align: left;
    padding: 0px 8px;
  }

  .el-row {
    display: flex;
    align-items: flex-end;

    .el-col-1 {
      text-align: center;
      line-height: 20px;
      height: 20px;
    }

    .el-col-6 {
      height: 40px;
      top: 5px;
      left: 25px;
      position: relative;
      width: 50px;
    }
  }
}

/deep/ .super_con {
  .el-form-item {
    margin-bottom: 7px;
  }

  .el-row {
    display: flex;
    align-items: flex-end;
  }

  .coil {
    display: inline-block;
    width: 98px;
    height: 25px;
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
    text-align: left;
  }
}

.infos {
  width: 60px;
  position: absolute;
  left: 208px;
  top: 0;
}

/deep/ .footer_con {
  .cjjcq_code {
    // margin-left: 140px !important;
    .el-form-item__content {
      margin-left: 140px !important;
    }
  }

  .el-form-item__label {
    line-height: 20px;
  }
}

/deep/ .drvieName_All {
  position: absolute;
  left: 1478px;
  top: 140px;
  width: 435px;
  max-height: 720px;
  z-index: 10000;
  border: 1px solid #f5f5f5;

  .title {
    background-color: #fff;
    padding: 5px 6px 5px 25px;
    display: flex;
    justify-content: space-between;

    .title_l {
      width: 103px;
      height: 26px;
      color: rgba(16, 16, 16, 1);
      font-size: 18px;
      text-align: left;
    }

    .title_r {
      width: 24px;
      height: 24px;
      line-height: 24px;
      cursor: pointer;
      color: rgba(111, 103, 103, 1);
    }
  }

  .el-divider--horizontal {
    margin: 0px;
  }
}
</style>
