<!-- 设备配置----网口设备 -->
<template>
  <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">{{ $t('addDevice') }}</span>
          </el-menu-item>
          <el-menu-item index="2" style="font-size: 12px">
            <span slot="title">{{ $t('del') }}</span>
          </el-menu-item>
          <el-menu-item index="3" style="font-size: 12px">
            <span slot="title">{{ $t('cancel') }}</span>
          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <!-- </div> -->
    <!-- 网口设备 -->
    <div class="pas_params">
      <el-dialog
          :title="$t('configuration.deviceProperties')"
        :visible.sync="add_passage"
        width="382px"
        v-loading="loading"
      >
        <el-form
          :model="formData"
          :label-position="labelPosition"
          :rules="rules"
          ref="formData"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item
                  :label="$t('configuration.deviceID')"
                :label-width="formLabelWidth"
                prop="sbpz_sbid"
              >
                <el-select
                  v-model="formData.sbpz_sbid"
                  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="24">
              <el-form-item
                  :label="$t('configuration.deviceName')"
                :label-width="formLabelWidth"
                prop="sbpz_sbmc"
              >
                <el-select
                  v-model="formData.sbpz_sbmc"
                  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-row>
          <el-row>
            <el-col :span="24">
              <el-form-item
                  :label="$t('configuration.deviceAddress')"
                :label-width="formLabelWidth"
                prop="sbpz_sbdz"
              >
                <el-input
                  v-model="formData.sbpz_sbdz"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item>
                <!-- 需要修改的地方 -->
                <el-checkbox v-model="formData.sbpz_jysb">{{ $t('configuration.disableDevice') }}</el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('configuration.addressSelection')">
                <span :class="">1</span>
                <el-switch v-model="formData.sbpz_jdzxz" disabled></el-switch>
              </el-form-item>
            </el-col>
          </el-row>
        </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="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-item :label="$t('dbcollectiongate.type')" prop="wgpz_wglx">
            <el-select
              v-model="formData.wgpz_wglx"
              :placeholder="$t('select')"
              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">{{ $t('save') }}</el-button>
          <el-button @click="outerVisible = false">{{ $t('cancel') }}</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

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

export default {
  name: "DeviceView",

  data() {
    return {
      loading: false,
      flag: false,
      gateway: "",
      user_id: "",
      trees: [],
      formData: {
        ippz_lwfs: "",
        ippz_wangkou: "",
        ippz_zwym: "",
        ippz_mrwg: "",
        ippz_dns_sx: "",
        ippz_dns_by: "",
        ippz_ip: "",
        ippz_mac: "",
        ippz_wifi_ssid: "",
        ippz_wifi_mm: "",
        wgpz_wgmc: "",
        wgpz_wgid: "",
        wgpz_wglx: "",
        tdpz_tdmc: "",
        tdpz_td: "",
        tdpz_qdmc: "",
        tdpz_chuankou: "",
        tdpz_btl: "",
        tdpz_sjw: "",
        tdpz_tzw: "",
        tdpz_jojy: "",
        tdpz_cgsj: "",
        tdpz_jgsj: "",
        tdpz_lxsj: "",
        tdpz_cfcs: "",
        tdpz_watchtime: "",
        tdpz_cjsylxdz: "",
        tdpz_dxzkb: "",
        tdpz_050F: "",
        tdpz_0610: "",
        sbpz_sbid: "",
        sbpz_sbmc: "",
        sbpz_sbdz: "",
        sbpz_jysb: false,
        sbpz_jdzxz: true,
        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: "",
        // mqtt_retained: "",
      },
      labelPosition: "left",
      formLabelWidth: "116px",
      input1: 192,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      options1: this.$t('configuration.options1'),
      options2: this.$t('configuration.options2'),
      defaultProps: {
        children: "children",
        label: "label",
      },
      nodekey: "",
      rules: {
        sbpz_sbid: [
          { required: true, message: this.$t('configuration.rules.sbpz_sbid'), trigger: "blur" },
        ],
        sbpz_sbmc: [
          { required: true, message: this.$t('configuration.rules.sbpz_sbmc'), trigger: "blur" },
        ],
        sbpz_sbdz: [
          { required: true, message: this.$t('configuration.rules.sbpz_sbdz'), trigger: "blur" },
        ],
      },
      // 网关配置的出现
      outerVisible: false,
      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" },
        ],
        wgpz_wglx: [
          { required: true, message: this.$t('dbcollectiongate.rules.wgpz_wglx'), trigger: "blur" },
        ],
      },
      opts1: this.$t('dbcollectiongate.options1'),
      opts2: [
        {
          value: "LAN-BOX1",
          label: "LAN-BOX1",
        },
        {
          value: "WLAN-BOX1",
          label: "WLAN-BOX1",
        },
      ],
      opts3: this.$t('dbcollectiongate.options3'),
    };
  },
  methods: {
    // 提交时进行校验
    submitForm: _.debounce(function (e) {
      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;
        this.GetUserAnswer();
        // let res2 = await GetUserAnswer({
        //   mark: "DB-IotLite_wx",
        //   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;
        // }
      }
      if (node.level == 4) {
        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();
          }
        });
      }
    },
    getDriveName() {
      this.diag_drive = true;
    },
    closeMenu(ev) {
      console.log({ ev });
      this.dialogVisible = false;
    },
    async selectMenuNode(index, indexPath) {
      console.log(index);
      if (index == 1) {
        this.add_passage = true;
      } else if (index == 2) {
        this.$refs["tree"].remove(this.nodekey);
        this.sendTree();
        this.$message({
          message: "删除成功",
          type: "success",
        });
        var obj = {
          sbpz_sbid: "",
          sbpz_jdzxz: "",
          sbpz_jysb: "",
          sbpz_sbmc: "",
          sbpz_sbdzc: "",
          cjdpz_tagid: "",
          cjdpz_mc: "",
          cjdpz_sjq: "",
          cjdpz_jcqdz: "",
          cjdpz_cjsjlx: "",
          cjdpz_zjx: "",
          cjdpz_dxsx: "",
          cjdpz_beilv: "",
          ippz_lwfs: this.formData.ippz_lwfs,
          ippz_wangkou: this.formData.ippz_wangkou,
          ippz_zwym: this.formData.ippz_zwym,
          ippz_ip: this.formData.ippz_ip,
          ippz_mrwg: this.formData.ippz_mrwg,
          ippz_dns_sx: this.formData.ippz_dns_sx,
          ippz_dns_by: this.formData.ippz_dns_by,
          ippz_mac: this.formData.ippz_mac,
          ippz_wifi_ssid: this.formData.ippz_wifi_ssid,
          ippz_wifi_mm: this.formData.ippz_wifi_mm,
          wgpz_wgmc: this.formData.wgpz_wgmc,
          wgpz_wgid: this.formData.wgpz_wgid,
          wgpz_wglx: this.formData.wgpz_wglx,
          tdpz_watchtime: "",
          tdpz_cjsylxdz: "",
          tdpz_tdmc: "",
          tdpz_td: "",
          tdpz_qdmc: "",
          tdpz_chuankou: "",
          tdpz_btl: "",
          tdpz_sjw: "",
          tdpz_tzw: "",
          tdpz_jojy: "",
          tdpz_port: "",
          tdpz_cgsj: "",
          tdpz_jgsj: "",
          tdpz_lxsj: "",
          tdpz_cfcs: "",
          tdpz_050F: "",
          tdpz_0610: "",
          tdpz_dxzkb: "",
          mqtt_qiyong: this.formData.mqtt_qiyong,
          mqtt_ip: this.formData.mqtt_ip,
          mqtt_port: this.formData.mqtt_port,
          mqtt_wgsn: this.formData.mqtt_wgsn,
          mqtt_sssjfbzt: this.formData.mqtt_sssjfbzt,
          mqtt_qos: this.formData.mqtt_qos,
          mqtt_scms: this.formData.mqtt_scms,
          mqtt_sczq: this.formData.mqtt_sczq,
          mqtt_sjgl: this.formData.mqtt_sjgl,
          mqtt_cjd_sbmc: this.formData.mqtt_cjd_sbmc,
          mqtt_cjd_tagid: this.formData.mqtt_cjd_tagid,
        };
        let res = await SaveUserAnswer({
          mark: "DB-IotLite_wx",
          user_id: this.user_id,
          mark_value: JSON.stringify(obj),
          step: "1",
        });
        this.$router.push(`/dbcollectserial?user_id=${this.user_id}`);
        // this.$router.back();
      }
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick() {
      this.foo();
    },
    async saveDevice() {
      // console.log(datas);
      var obj = {
        sbpz_sbid: this.formData.sbpz_sbid,
        sbpz_sbmc: this.formData.sbpz_sbmc,
        sbpz_sbmc: this.formData.sbpz_sbmc,
        sbpz_jysb: String(Number(this.formData.sbpz_jysb)),
        sbpz_jdzxz: String(Number(this.formData.sbpz_jdzxz)),
      };
      let datas = { ...this.formData, ...obj };
      this.add_passage = false;
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_wx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        mark_value: JSON.stringify(datas),
        step: "3",
      });
      // console.log(res.data);
      if (res.data.state) {
        this.$message({
          message: this.$t('success'),
          type: "success",
        });
        sessionStorage.setItem("DB-IotLite_wx", JSON.stringify(datas));
        // console.log(res);
        // console.log(JSON.parse(res.data.data.mark_value));
        this.$refs["tree"].append(
          {
            id: this.nodekey + 10000,
            label: this.formData.sbpz_sbmc,
          },
          this.nodekey
        );
        // console.log(this.trees);
        this.sendTree();
        this.$router.push(`/dbwificollect?user_id=${this.user_id}`);
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
    },
    async GetUserAnswer() {
      let answer = await GetUserAnswer({
        mark: "DB-IotLite_wx",
        // user_id: "USER202307301114011710",
        user_id: this.user_id,
      });
      if(!answer.data.state){
        getQueryAnswer({
          mark: "DB-IotLite_wx",
          user_id: this.user_id
        }).then(res => {
          let obj = JSON.parse(res.data.data.r3);
          // console.log(obj);
          if (obj.sbpz_sbid) {
            this.formData.sbpz_sbid = obj.sbpz_sbid;
            this.formData.sbpz_jdzxz = Boolean(Number(obj.sbpz_jdzxz));
            this.formData.sbpz_jysb = Boolean(Number(obj.sbpz_jysb));
            this.formData.sbpz_sbmc = obj.sbpz_sbmc;
            this.formData.sbpz_sbdz = obj.sbpz_sbdz;
          }
          this.formData.wgpz_wgid = obj.wgpz_wgid;
          // console.log(this.formData.wgpz_wgid);
          this.formData.wgpz_wgmc = obj.wgpz_wgmc;
          this.formData.wgpz_wglx = obj.wgpz_wglx;
          this.formData.ippz_lwfs = obj.ippz_lwfs;
          this.formData.ippz_wangkou = obj.ippz_wangkou;
          this.formData.ippz_zwym = obj.ippz_zwym;
          this.formData.ippz_mrwg = obj.ippz_mrwg;
          this.formData.ippz_ip = obj.ippz_ip;
          this.formData.tdpz_watchtime = obj.tdpz_watchtime;
          this.formData.tdpz_cjsylxdz = obj.tdpz_cjsylxdz;
          this.formData.ippz_dns_sx = obj.ippz_dns_sx;
          this.formData.ippz_dns_by = obj.ippz_dns_by;
          this.formData.ippz_mac = obj.ippz_mac;
          this.formData.ippz_wifi_ssid = obj.ippz_wifi_ssid;
          this.formData.ippz_wifi_mm = obj.ippz_wifi_mm;
          this.formData.tdpz_tdmc = obj.tdpz_tdmc;
          this.formData.tdpz_td = obj.tdpz_td;
          this.formData.tdpz_qdmc = obj.tdpz_qdmc;
          this.formData.tdpz_chuankou = obj.tdpz_chuankou;
          this.formData.tdpz_btl = obj.tdpz_btl;
          this.formData.tdpz_sjw = obj.tdpz_sjw;
          this.formData.tdpz_tzw = obj.tdpz_tzw;
          this.formData.tdpz_jojy = obj.tdpz_jojy;
          this.formData.tdpz_port = obj.tdpz_port;
          this.formData.tdpz_cgsj = obj.tdpz_cgsj;
          this.formData.tdpz_jgsj = obj.tdpz_jgsj;
          this.formData.tdpz_lxsj = obj.tdpz_lxsj;
          this.formData.tdpz_cfcs = obj.tdpz_cfcs;
          this.formData.tdpz_050F = obj.tdpz_050F;
          this.formData.tdpz_0610 = obj.tdpz_0610;
          this.formData.tdpz_dxzkb = obj.tdpz_dxzkb;
          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;
        })
      }
      if (answer.data.data && answer.data.state) {
        // console.log(answer);
        let obj = JSON.parse(answer.data.data.mark_value);
        // console.log(obj);
        if (obj.sbpz_sbid) {
          this.formData.sbpz_sbid = obj.sbpz_sbid;
          this.formData.sbpz_jdzxz = Boolean(Number(obj.sbpz_jdzxz));
          this.formData.sbpz_jysb = Boolean(Number(obj.sbpz_jysb));
          this.formData.sbpz_sbmc = obj.sbpz_sbmc;
          this.formData.sbpz_sbdz = obj.sbpz_sbdz;
        }
        this.formData.wgpz_wgid = obj.wgpz_wgid;
        // console.log(this.formData.wgpz_wgid);
        this.formData.wgpz_wgmc = obj.wgpz_wgmc;
        this.formData.wgpz_wglx = obj.wgpz_wglx;
        this.formData.ippz_lwfs = obj.ippz_lwfs;
        this.formData.ippz_wangkou = obj.ippz_wangkou;
        this.formData.ippz_zwym = obj.ippz_zwym;
        this.formData.ippz_mrwg = obj.ippz_mrwg;
        this.formData.ippz_ip = obj.ippz_ip;
        this.formData.tdpz_watchtime = obj.tdpz_watchtime;
        this.formData.tdpz_cjsylxdz = obj.tdpz_cjsylxdz;
        this.formData.ippz_dns_sx = obj.ippz_dns_sx;
        this.formData.ippz_dns_by = obj.ippz_dns_by;
        this.formData.ippz_mac = obj.ippz_mac;
        this.formData.ippz_wifi_ssid = obj.ippz_wifi_ssid;
        this.formData.ippz_wifi_mm = obj.ippz_wifi_mm;
        this.formData.tdpz_tdmc = obj.tdpz_tdmc;
        this.formData.tdpz_td = obj.tdpz_td;
        this.formData.tdpz_qdmc = obj.tdpz_qdmc;
        this.formData.tdpz_chuankou = obj.tdpz_chuankou;
        this.formData.tdpz_btl = obj.tdpz_btl;
        this.formData.tdpz_sjw = obj.tdpz_sjw;
        this.formData.tdpz_tzw = obj.tdpz_tzw;
        this.formData.tdpz_jojy = obj.tdpz_jojy;
        this.formData.tdpz_port = obj.tdpz_port;
        this.formData.tdpz_cgsj = obj.tdpz_cgsj;
        this.formData.tdpz_jgsj = obj.tdpz_jgsj;
        this.formData.tdpz_lxsj = obj.tdpz_lxsj;
        this.formData.tdpz_cfcs = obj.tdpz_cfcs;
        this.formData.tdpz_050F = obj.tdpz_050F;
        this.formData.tdpz_0610 = obj.tdpz_0610;
        this.formData.tdpz_dxzkb = obj.tdpz_dxzkb;
        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;
        // this.formData.mqtt_retained = obj.mqtt_retained;
      }
    },
    async sendTree() {
      let result = await SendTree({
        // user_id: "USER202307301114011710",
        user_id: this.user_id,
        data: JSON.stringify(this.trees),
        type: "2",
      });
      // 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_wx");
      // console.log(JSON.parse(datas));

      //  datas = { ...JSON.parse(datas), ...this.gateWay };
      // console.log(datas);
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_wx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        mark_value: JSON.stringify(this.formData),
        step: "2",
      });
      if (res.data.state) {
        this.$message({
          message: "修改成功",
          type: "success",
        });
        this.trees[0].label = this.formData.wgpz_wgid;
        this.sendTree();
        // sessionStorage.setItem("DB-IotLite_wx", JSON.stringify(this.formData));
      } else {
        this.$message({
          message: `保存失败,原因是${res.data.message}`,
          type: "error",
        });
      }
      console.log(res);
    },
  },
  created() {
    this.user_id = this.$route.query.user_id;
    if (this.user_id != "undefined") {
      GetTree({
        // user_id: "USER202307301114011710",
        user_id: this.user_id,
        type: "2",
      }).then((res) => {
        // console.log(res);
        // console.log(JSON.parse(res.data.data.data));
        if(this.$i18n.locale==='zh'){
          this.trees = JSON.parse(res.data.data.r2);

        }else{
          this.trees = JSON.parse(res.data.data.data);
        }

      });
    }
    this.loading = true;
    this.GetUserAnswer();
    this.loading = false;
  },
};
// 点击时候的判断,判断是否为新增设备
//     async saveDevice() {
//   let datas = sessionStorage.getItem("DB-IotLite_wx");
//   console.log(datas);
//   var obj = {
//     sbpz_sbid: this.formData.sbpz_sbid,
//     sbpz_sbmc: this.formData.sbpz_sbmc,
//     sbpz_mac: this.formData.sbpz_mac,
//     sbpz_jysb: String(Number(this.formData.sbpz_jysb)),
//     sbpz_jdzxz: String(Number(this.formData.sbpz_jdzxz)),
//   };
//   datas = { ...JSON.parse(datas), ...obj };
//   this.add_passage = false;
//   let res = await SaveUserAnswer({
//     mark: "DB-IotLite_wx",
//     user_id: this.user_id,
//     mark_value: JSON.stringify(datas),
//   });
//   if (res.status == 200) {
//     this.$message({
//       message: this.$t('success'),
//       type: "success",
//     });
//   }
//   sessionStorage.setItem("DB-IotLite_wx", JSON.stringify(datas));
//   // console.log(res);
//   // console.log(JSON.parse(res.data.data.mark_value));
//   this.$refs["tree"].append(
//     {
//       id: this.nodekey + 10000,
//       label: this.formData.sbpz_sbmc,
//     },
//     this.nodekey
//   );
//   // console.log(this.trees);
//   this.sendTree();
//   this.$router.push(`/dbwificollect?user_id=${this.user_id}`);
// },
//     async GetUserAnswer() {
//   let answer = await GetUserAnswer({
//     mark: "DB-IotLite_wx",
//     user_id: this.user_id,
//   });
//   // console.log(answer);
//   // console.log(obj);
//   if (obj.sbpz_sbid) {
//     let obj = JSON.parse(answer.data.data.mark_value);

//     this.formData.sbpz_sbid = obj.sbpz_sbid;
//     this.formData.sbpz_jdzxz = Boolean(Number(obj.sbpz_jdzxz));
//     this.formData.sbpz_jysb = Boolean(Number(obj.sbpz_jysb));
//     this.formData.sbpz_sbmc = obj.sbpz_sbmc;
//     this.formData.sbpz_mac = obj.sbpz_mac;
//   }
// },
//     async sendTree() {
//   let result = await SendTree({
//     user_id: this.user_id,
//     data: JSON.stringify(this.trees),
//     type: "2",
//   });
//   console.log(result);
// },
//   },
</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;
  }
}

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

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

  .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: 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 {
    display: flex;
    align-items: flex-end;

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

.one {
  z-index: 10000;
  position: absolute;
  left: 95px;
  top: 0px;
}
</style>
