<!-- 网关通道 -->
<template>
  <div>
    <!-- v-click-outside="closeMenu" -->
    <div>
      <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">
          <!-- <span class="custom-tree-node" slot-scope="{ node, data }">
            <template v-if="data.editing == 1 && flag">
              <el-input style="width: 260px;" v-model="gateway" @change="changeInput"></el-input>
            </template>
            <template v-else>{{ data.label }}</template>
          </span> -->
        </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">新建通道</span>
            </el-menu-item>
            <el-menu-item index="2" style="font-size: 12px">
              <span slot="title">取 消</span>
            </el-menu-item>
          </el-menu>
        </div>
      </div>
    </div>
    <div class="pas_params">
      <el-dialog title="通道参数设置" :visible.sync="add_passage" width="765px" v-loading="loading">
        <el-form :model="FormData" :label-position="labelPosition" :rules="rules" ref="FormData">
          <el-row>
            <el-col :span="12">
              <el-form-item label="通道名称:" :label-width="formLabelWidth" prop="tdpz_tdmc">
                <el-select v-model="FormData.tdpz_tdmc" placeholder="" style="width: 200px; height: 30px">
                  <el-option v-for="(item, index) in options1" :key="index" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="通道:" :label-width="formLabelWidth" prop="tdpz_td">
                <el-select v-model="FormData.tdpz_td" placeholder="" style="width: 200px; height: 30px">
                  <el-option v-for="(item, index) in options2" :key="index" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="驱动名称:" :label-width="formLabelWidth" prop="tdpz_qdmc">
                <el-row>
                  <el-col :span="18">
                    <el-input v-model="FormData.tdpz_qdmc" placeholder="" style="width: 200px; height: 30px"></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="IP地址:" :label-width="formLabelWidth" prop="tdpz_ip">
                <el-row>
                  <el-col :span="5">
                    <el-input v-model="tdpz_ip1" style="width: 43px; height: 30px"></el-input>
                  </el-col>
                  <el-col :span="1" style="color: #fff">. </el-col>
                  <el-col :span="5">
                    <el-input v-model="tdpz_ip2" style="width: 43px; height: 30px"></el-input>
                  </el-col>
                  <el-col :span="1" style="color: #fff">.</el-col>
                  <el-col :span="5">
                    <el-input v-model="tdpz_ip3" style="width: 43px; height: 30px"></el-input>
                  </el-col>
                  <el-col :span="1" style="color: #fff">.</el-col>
                  <el-col :span="5">
                    <el-input v-model="tdpz_ip4" style="width: 43px; height: 30px"></el-input>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="端口号:" :label-width="formLabelWidth" prop="tdpz_port">
                <el-input v-model="FormData.tdpz_port" placeholder="" style="width: 200px; height: 30px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="超过时间(ms):" :label-width="formLabelWidth" prop="tdpz_cssj">
                <el-input v-model="FormData.tdpz_cssj" placeholder="" style="width: 200px; height: 30px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="间隔时间(ms):" :label-width="formLabelWidth" prop="tdpz_jgsj">
                <el-input v-model="FormData.tdpz_jgsj" placeholder="" style="width: 200px; height: 30px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="轮询时间(ms):" :label-width="formLabelWidth" prop="tdpz_lxsj">
                <el-input v-model="FormData.tdpz_lxsj" placeholder="" style="width: 200px; height: 30px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="重复次数:" :label-width="formLabelWidth" prop="tdpz_cfcs">
                <el-input v-model="FormData.tdpz_cfcs" placeholder="" style="width: 200px; height: 30px"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div class="super_parmams">
          <h3>高级参数</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="
                width: 28px;
                border: none;
                color: rgba(16, 16, 16, 1);
                font-size: 14px;
                text-align: left;
              ">
              收起</el-button>
          </div>
        </div>
        <div class="super_con" v-show="is_retract">
          <el-form :label-position="labelPosition" :rules="rules" ref="ruleForm">
            <el-row>
              <el-col :span="12">
                <el-form-item>
                  <el-checkbox v-model="FormData.tdpz_watchtime">watch time(s)</el-checkbox>
                  <el-input v-model="input1" placeholder="" style="width: 200px; height: 30px"
                    :disabled="isdisabled"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item>
                  <el-checkbox v-model="FormData.tdpz_cjsylxdz">采集使用连续地址</el-checkbox>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="读写占空比:" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="10">
                      <el-input v-model="tdpz_dxzkb1" style="width: 91px; height: 30px"></el-input>
                    </el-col>
                    <el-col :span="4">: </el-col>
                    <el-col :span="10">
                      <el-input v-model="tdpz_dxzkb2" style="width: 91px; height: 30px"></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="05/0F:" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_050F" label="auto">auto</el-radio></el-col>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_050F" label="05">05</el-radio></el-col>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_050F" label="0F">0F</el-radio></el-col>
                  </el-row>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="06/10:" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_0610" label="auto">auto</el-radio></el-col>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_0610" label="06">06</el-radio></el-col>
                    <el-col :span="8"><el-radio v-model="FormData.tdpz_0610" label="10">10</el-radio></el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">保 存</el-button>
          <el-button @click="add_passage = false">取 消</el-button>
        </span>
      </el-dialog>
    </div>
    <div class="drvieName_All" v-show="diag_drive">
      <div class="title">
        <p class="title_l">协议选择</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="新建网关" :visible.sync="outerVisible" width="382px">
        <el-form :model="FormData" :rules="rulesGate" ref="gateWay" label-width="85px" class="demo-ruleForm">
          <el-form-item label="网关名称:" prop="wgpz_wgmc">
            <el-select v-model="FormData.wgpz_wgmc" placeholder="请选择" 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="网关ID:" prop="wgpz_wgid">
            <el-select v-model="FormData.wgpz_wgid" placeholder="请选择" 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-item label="网关类型:" prop="wgpz_wglx">
            <el-select v-model="FormData.wgpz_wglx" placeholder="请选择" style="width: 200px">
              <el-option v-for="item in opts3" :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">保存</el-button>
          <el-button @click="outerVisible = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { SaveUserAnswer, GetUserAnswer, GetTree, SendTree } from "@/api/user";

export default {
  name: "TestTreeView",

  data() {
    return {
      loading: false,
      flag: false,
      gateway: "",
      user_id: "",
      FormData: {
        ippz_wangkou: "",
        ippz_zwym: "",
        ippz_mrwg: "",
        ippz_dns_sx: "",
        ippz_dns_by: "",
        ippz_ip: "",
        ippz_mac: "",
        wgpz_wgmc: "",
        wgpz_wgid: "",
        wgpz_wglx: "",
        tdpz_tdmc: "",
        tdpz_td: "",
        tdpz_qdmc: "",
        tdpz_port: "",
        tdpz_cssj: "",
        tdpz_jgsj: "",
        tdpz_lxsj: "",
        tdpz_cfcs: "",
        tdpz_watchtime: false,
        tdpz_cjsylxdz: true,
        tdpz_dxzkb: "",
        tdpz_050F: "auto",
        tdpz_0610: "auto",
        sbpz_sbid: "",
        sbpz_sbmc: "",
        sbpz_mac: "",
        sbpz_jysb: "",
        sbpz_jdzxz: "",
        cjdpz_tagid: "",
        cjdpz_mc: "",
        cjdpz_sjq: "",
        cjdpz_jcqdz: "",
        cjdpz_cjsjlx: "",
        cjdpz_zjx: "",
        cjdpz_dxsx: "",
        cjdpz_beilv: "",
        mqtt_qiyong: "",
        mqtt_ip: "",
        mqtt_port: "",
        mqtt_wgsn: "",
        mqtt_sssjfbzt: "",
        mqtt_qos: "",
        mqtt_scms: "",
        mqtt_sczq: "",
        mqtt_sjgl: "",
        mqtt_cjd_sbmc: "",
        mqtt_cjd_tagid: "",
      },
      tdpz_dxzkb1: "1",
      tdpz_dxzkb2: "1",
      tdpz_ip1: "",
      tdpz_ip2: "",
      tdpz_ip3: "",
      tdpz_ip4: "",
      options1: [
        {
          value: "有线区Channel1",
          label: "有线区Channel1",
        },
        {
          value: "无线区Channel1",
          label: "无线区Channel1",
        },
      ],
      options2: [
        {
          value: "网口",
          label: "网口",
        },
        {
          value: "串口",
          label: "串口",
        },
      ],
      value1: "有线区Channel1",
      value2: "网口",
      diag_drive: false,
      isdisabled: true,
      radio: "1",
      is_retract: true,
      labelPosition: "left",
      formLabelWidth: "116px",
      input1: 10,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      trees: [],
      nodekey: "",
      datas2: [
        {
          label: "通用标准",
          children: [
            {
              label: "ModbusTCPClient",
            },
            {
              label: "ModbusRTU_over_TCP",
            },
            {
              label: "OPCUAClient",
            },
            {
              label: "OPCDAClient",
            },
            {
              label: "MQTTClient",
            },
            {
              label: "OPCXMLDAClient",
            },
            {
              label: "环保212协议网口监听",
            },
          ],
        },
        {
          label: "PLC",
          children: [
            {
              label: "Slemens S7-200 Network",
            },
            {
              label: "Slemens S7-300 Network",
            },
            {
              label: "Slemens S7-400 Network",
            },
            {
              label: "Slemens S7-1200 Network",
            },
            {
              label: "Slemens S7-1500 Network",
            },
            {
              label: "EtherNet/IP CIP协议(AB OMR ON)",
            },
            {
              label: "MC_Qna-3E(三菱 基恩士 松下)",
            },
            {
              label: "MC_A-1E_Binary",
            },
            {
              label: "OMRON-FINS",
            },
            {
              label: "横河PLC",
            },
            {
              label: "西门子FetchWirte",
            },
            {
              label: "富机 FUJI_SPH_NET",
            },
            {
              label: "基恩士上位链路通讯",
            },
          ],
        },
        {
          label: "智能建筑",
          children: [],
        },
        {
          label: "厂家定制",
          children: [],
        },
        {
          label: "电力行业标准",
          children: [
            {
              label: "IEC104",
            },
            {
              label: "DLT645_over_TCP",
            },
          ],
        },
        {
          label: "CNC数控",
          children: [],
        },
        {
          label: "私有协议",
          children: [],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      rules: {
        tdpz_tdmc: [
          { required: true, message: "请输入通道名称", trigger: "change" },
        ],
        tdpz_td: [{ required: true, message: "请输入通道", trigger: "change" }],
        tdpz_qdmc: [
          { required: true, message: "请输入驱动名称", trigger: "change" },
        ],
        tdpz_ip: [
          {
            required: true,
            message: "",
            validator: this.validateIpAddress,
            trigger: "blur",
          },
        ],
        tdpz_port: [
          { required: true, message: "请输入端口号", trigger: "blur" },
        ],
        tdpz_cssj: [
          { required: true, message: "请输入超出时间", trigger: "blur" },
        ],
        tdpz_jgsj: [
          { required: true, message: "请输入间隔时间", trigger: "blur" },
        ],
        tdpz_lxsj: [
          { required: true, message: "请输入轮询时间", trigger: "blur" },
        ],
        tdpz_cfcs: [
          { required: true, message: "请输入重复次数", trigger: "blur" },
        ],
      },
      // 网关配置的出现
      outerVisible: false,
      gateWay: {
        wgpz_wgmc: "",
        wgpz_wgid: "",
        wgpz_wglx: "",
      },
      rulesGate: {
        wgpz_wgmc: [
          { required: true, message: "请选择网关名称", trigger: "blur" },
        ],
        wgpz_wgid: [
          { required: true, message: "请选择网关id", trigger: "blur" },
        ],
        wgpz_wglx: [
          { required: true, message: "请选择网关类型", trigger: "blur" },
        ],
      },
      opts1: [
        {
          value: "有线区网关1",
          label: "有线区网关1",
        },
        {
          value: "无线区网关1",
          label: "无线区网关1",
        },
      ],
      opts2: [
        {
          value: "LAN-BOX1",
          label: "LAN-BOX1",
        },
        {
          value: "WLAN-BOX1",
          label: "WLAN-BOX1",
        },
      ],
      opts3: [
        {
          value: "loT Lite网关",
          label: "loT Lite网关",
        },
        {
          value: "MODBUS网关",
          label: "MODBUS网关",
        },
        {
          value: "BACNET网关",
          label: "BACNET网关",
        },
        {
          value: "OPC UA网关",
          label: "OPC UA网关",
        },
        {
          value: "OPC DA网关",
          label: "OPC DA网关",
        },
        {
          value: "loT网关",
          label: "loT网关",
        },
      ],
    };
  },

  methods: {
    //ip地址验证
    validateIpAddress(rule, value, callback) {
      if (
        this.tdpz_ip1 +
        "." +
        this.tdpz_ip2 +
        "." +
        this.tdpz_ip3 +
        "." +
        this.tdpz_ip4 ===
        "..."
      ) {
        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.tdpz_ip1 +
          "." +
          this.tdpz_ip2 +
          "." +
          this.tdpz_ip3 +
          "." +
          this.tdpz_ip4
        )
      ) {
        callback(new Error("请输入有效的IP地址"));
      } else {
        callback();
      }
    },
    // 提交时的校验
    submitForm() {
      this.$refs["FormData"].validate((valid) => {
        if (valid) {
          this.saveGate();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // changeInput() {
    //   this.flag = false;
    //   this.trees[0].label = this.gateway;
    //   this.sendTree();
    // },
    async rightClick(e, data, node) {
      console.log(data);
      // console.log(node);
      if (data.editing) {
        this.outerVisible = true;
        // let res2 = await GetUserAnswer({
        //   mark: "DB-IotLite_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.gateWay.wgpz_wglx = res3.wgpz_wglx;
        // }
        this.GetUserAnswer();
      }
      if (node.level == 3) {
        this.nodekey = data.id;
        // if (data.id == 111 || data.label == "I/O点") {
        this.menuShow = false;
        this.menuShow = true;
        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;
      }
      this.menuShow = false;
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick(key) {
      // console.log
      this.foo();
    },
    // 收起点击事件的判断
    getRetract() {
      if (this.is_retract == true) {
        this.is_retract = false;
      } else {
        this.is_retract = true;
      }
    },
    getDriveName() {
      this.diag_drive = true;
    },
    Merge(value, value1, value2, value3, value4) {
      value = value1 + "." + value2 + "." + value3 + "." + value4;
      return value;
    },
    async saveGate() {
      var obj = {
        tdpz_tdmc: this.FormData.tdpz_tdmc,
        tdpz_td: this.FormData.tdpz_td,
        tdpz_qdmc: this.FormData.tdpz_qdmc,
        tdpz_port: this.FormData.tdpz_port,
        tdpz_cssj: this.FormData.tdpz_cssj,
        tdpz_jgsj: this.FormData.tdpz_jgsj,
        tdpz_ip:
          this.tdpz_ip1 +
          "." +
          this.tdpz_ip2 +
          "." +
          this.tdpz_ip3 +
          "." +
          this.tdpz_ip4,
        tdpz_lxsj: this.FormData.tdpz_lxsj,
        tdpz_cfcs: this.FormData.tdpz_cfcs,
        tdpz_watchtime: String(Number(this.FormData.tdpz_watchtime)),
        tdpz_cjsylxdz: String(Number(this.FormData.tdpz_cjsylxdz)),
        tdpz_dxzkb: this.tdpz_dxzkb1 + ":" + this.tdpz_dxzkb2,
        tdpz_050F: this.FormData.tdpz_050F,
        tdpz_0610: this.FormData.tdpz_0610,
      };
      // let datas = sessionStorage.getItem("DB-IotLite_yx");
      // datas = { ...JSON.parse(datas), ...obj };
      console.log(this.FormData);
      let datas = { ...this.FormData, ...obj };
      console.log(datas);
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_yx",
        // user_id: "USER202307301114011710",
        user_id: this.user_id,
        mark_value: JSON.stringify(datas),
        step: "2",
      });
      console.log(res);
      if (res.data.state) {
        this.$message({
          message: "保存成功",
          type: "success",
        });
        console.log(res.data.data.step);
        // sessionStorage.setItem("DB-IotLite_yx", JSON.stringify(datas));

        this.add_passage = false;
        // console.log(res.data.data.mark_value);
        // this.$nextTick(() => {
        this.$refs["tree"].append(
          {
            id: this.nodekey + 1000,
            label: this.FormData.tdpz_tdmc,
          },
          this.nodekey
        );
        // console.log(this.trees);
        this.sendTree();
        this.$router.push(`/dbcollectdevice?user_id=${this.user_id}`);
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
    },
    handleDetailClick(data, node, value) {
      console.log(data.label);
      console.log(data);
      if (node.level == 2) {
        this.FormData.tdpz_qdmc = data.label;
        this.diag_drive = false;
        console.log(result);
      }
    },
    async GetUserAnswer() {
      let answer = await GetUserAnswer({
        mark: "DB-IotLite_yx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
      });
      console.log(answer);
      if (answer.data.data && answer.data.state) {
        let obj = JSON.parse(answer.data.data.mark_value);
        console.log(obj);
        // this.FormData.
        if (obj.tdpz_dxzkb) {
          this.tdpz_dxzkb1 = obj.tdpz_dxzkb.split(":")[0];
          this.tdpz_dxzkb2 = obj.tdpz_dxzkb.split(":")[1];
          this.FormData.tdpz_dxzkb = obj.tdpz_dxzkb;
        }
        this.FormData.tdpz_watchtime = Boolean(Number(obj.tdpz_watchtime));
        if (obj.tdpz_cjsylxdz) {
          this.FormData.tdpz_cjsylxdz = Boolean(Number(obj.tdpz_cjsylxdz));
        }
        if (obj.tdpz_ip) {
          this.FormData.tdpz_ip = obj.tdpz_ip;
          this.tdpz_ip1 = obj.tdpz_ip.split(".")[0];
          this.tdpz_ip2 = obj.tdpz_ip.split(".")[1];
          this.tdpz_ip3 = obj.tdpz_ip.split(".")[2];
          this.tdpz_ip4 = obj.tdpz_ip.split(".")[3];
        }
        this.FormData.tdpz_tdmc = obj.tdpz_tdmc;
        this.FormData.tdpz_td = obj.tdpz_td;
        this.FormData.tdpz_qdmc = obj.tdpz_qdmc;
        if (obj.tdpz_050F) {
          this.FormData.tdpz_050F = obj.tdpz_050F;
        }
        if (obj.tdpz_0610) {
          this.FormData.tdpz_0610 = obj.tdpz_0610;
        }
        this.FormData.tdpz_port = obj.tdpz_port;
        this.FormData.tdpz_cssj = obj.tdpz_cssj;
        this.FormData.tdpz_jgsj = obj.tdpz_jgsj;
        this.FormData.tdpz_lxsj = obj.tdpz_lxsj;
        this.FormData.tdpz_cfcs = obj.tdpz_cfcs;
        this.FormData.ippz_wangkou = obj.ippz_wangkou;
        this.FormData.ippz_mrwg = obj.ippz_mrwg;
        this.FormData.ippz_ip = obj.ippz_ip;
        this.FormData.ippz_zwym = obj.ippz_zwym;
        this.FormData.ippz_dns_sx = obj.ippz_dns_sx;
        this.FormData.ippz_dns_by = obj.ippz_dns_by;
        this.FormData.wgpz_wgmc = obj.wgpz_wgmc;
        this.FormData.wgpz_wgid = obj.wgpz_wgid;
        this.FormData.wgpz_wglx = obj.wgpz_wglx;
        this.FormData.sbpz_sbid = obj.sbpz_sbid;
        this.FormData.sbpz_sbmc = obj.sbpz_sbmc;
        this.FormData.sbpz_mac = obj.sbpz_mac;
        this.FormData.sbpz_jysb = obj.sbpz_jysb;
        this.FormData.sbpz_jdzxz = obj.sbpz_jdzxz;
        this.FormData.cjdpz_tagid = obj.cjdpz_tagid;
        this.FormData.cjdpz_mc = obj.cjdpz_mc;
        this.FormData.cjdpz_sjq = obj.cjdpz_sjq;
        this.FormData.cjdpz_jcqdz = obj.cjdpz_jcqdz;
        this.FormData.cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
        this.FormData.cjdpz_zjx = obj.cjdpz_zjx;
        this.FormData.cjdpz_dxsx = obj.cjdpz_dxsx;
        this.FormData.cjdpz_beilv = obj.cjdpz_beilv;
        this.FormData.mqtt_qiyong = obj.mqtt_qiyong;
        this.FormData.mqtt_ip = obj.mqtt_ip;
        this.FormData.mqtt_port = obj.mqtt_port;
        this.FormData.mqtt_wgsn = obj.mqtt_wgsn;
        this.FormData.mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
        this.FormData.mqtt_qos = obj.mqtt_qos;
        this.FormData.mqtt_scms = obj.mqtt_scms;
        this.FormData.mqtt_sczq = obj.mqtt_sczq;
        this.FormData.mqtt_sjgl = obj.mqtt_sjgl;
        this.FormData.mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
        this.FormData.mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
      }
    },
    async sendTree() {
      let result = await SendTree({
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        data: JSON.stringify(this.trees),
        type: "1",
      });
      console.log(result);
    },

    //网关配置的信息
    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;
      // this.innerVisible = false;
      // let datas = sessionStorage.getItem("DB-IotLite_yx");
      // console.log(JSON.parse(datas));
      // datas = { ...JSON.parse(datas), ...this.gateWay };
      // console.log(datas);
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_yx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        mark_value: JSON.stringify(this.FormData),
        // step: "1",
      });
      if (res.data.state) {
        this.$message({
          message: "修改成功",
          type: "success",
        });
        this.trees[0].label = this.FormData.wgpz_wgid;
        this.sendTree();
        // sessionStorage.setItem("DB-IotLite_yx", JSON.stringify(this.gateWay));
      } else {
        this.$message({
          message: `修改失败,原因是${res.data.message}`,
          type: "error",
        });
      }
      console.log(res);
    },
  },
  created() {
    console.log(this.$route.query.user_id);
    this.user_id = this.$route.query.user_id;
    GetTree({
      user_id: this.user_id,
      // user_id: "USER202307301114011710",
      type: "1",
    }).then((res) => {
      console.log(res);
      console.log(JSON.parse(res.data.data.data));
      this.trees = JSON.parse(res.data.data.data);
      // console.log(this.$router.query.firstlabel);
      // this.trees[0] = this.$router.query.firstlabel;
      this.sendTree();
    });
    this.loading = true;
    this.GetUserAnswer();
    this.loading = false;
    // let res2 = GetUserAnswer()
  },

  watch: {
    "FormData.tdpz_watchtime"(newval) {
      console.log(newval);
      if (newval) {
        this.isdisabled = true;
      } else {
        this.isdisabled = false;
      }
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .tree_menu {
  position: absolute;
  width: 286px;
  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);

  .el-input__inner {
    height: 30px !important;
  }
}

.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;
  color: #fff !important;
  justify-content: space-between;
  align-items: center;
  width: 668px;

  i {
    width: 24px;
    height: 24px;
    display: inline-block;
  }
}

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

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

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

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

    .el-col-1 {
      color: #fff !important;
      text-align: center;
      line-height: 20px;
      height: 20px;
    }

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

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

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

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

  .el-row {
    color: #fff !important;
    display: flex;
    align-items: flex-end;

    .el-col-4 {
      padding-left: 5px;
      width: 14px;
      text-align: center;
      line-height: 4px;
      height: 20px;
    }
  }
}

.el-dialog__footer {
  padding: 18px 1.25rem 50px;
}

.dialog-footer {
  position: absolute;
  left: 50%;
  bottom: 45px;
  transform: translateX(-50%);
}

/deep/ .drvieName_All {
  position: absolute;
  left: 1408px;
  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);
    }
  }

  // h3 {
  //   padding-bottom: 10px;
  //   background-color: #fff;
  // }

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