<!-- 设备配置----网口设备 -->
<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.MACAddress')"
                :label-width="formLabelWidth"
                prop="sbpz_mac"
              >
                <el-input
                  v-model="formdata.sbpz_mac"
                  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">
              <span class="one">1</span>
              <el-form-item :label="$t('configuration.addressSelection')">
                <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('Please')"
              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('Please')"
              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('Please')"
              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 _ from "lodash";
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_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_ip: "",
        tdpz_port: "",
        tdpz_cssj: "",
        tdpz_jgsj: "",
        tdpz_lxsj: "",
        tdpz_cfcs: "",
        tdpz_watchtime: "",
        tdpz_cjsylxdz: "",
        tdpz_dxzkb: "",
        tdpz_050F: "",
        tdpz_0610: "",
        sbpz_sbid: "",
        sbpz_sbmc: "",
        sbpz_mac: "3C:2D:50:20:30:3D",
        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: "",
      },
      labelPosition: "left",
      formLabelWidth: "116px",
      input1: 192,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      options1: this.$t('configuration.options1'),
      options2: this.$t('configuration.options2'),
      datas: [
        {
          label: "Gateway",
          children: [
            {
              label: "数据采集",
              children: [
                {
                  label: "I/O点",
                },
                {
                  label: "用户点",
                },
                {
                  label: "计算点",
                },
                {
                  label: "系统点",
                },
              ],
            },
            {
              label: "用户点",
            },
            {
              label: "计算点",
            },
            {
              label: "系统点",
            },
          ],
        },
        {
          label: "数据服务",
          children: [
            {
              label: "Modbus",
            },
          ],
        },
        {
          label: "IOT",
          children: [
            {
              label: "Mqtt Client",
            },
            {
              label: "Alink",
            },
            {
              label: "Tlink",
            },
            {
              label: "loTDDC",
            },
            {
              label: "Ulink",
            },
          ],
        },
      ],
      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_mac: [
          { required: true, message: this.$t('configuration.rules.sbpz_mac'), 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" },
        ],
        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) {
      console.log(node);
      if (data.editing) {
        this.outerVisible = true;
        this.add_passage = false;
        this.menuShow = false;
        this.GetUserAnswer();
        // this.trees[0].label = this.formdata.wgpz_wgid;
      }
      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();
          }
        });
      }
    },
    // 点击时候的判断,判断是否为新增设备
    async selectMenuNode(index, indexPath) {
      console.log(index);
      if (index == 1) {
        this.add_passage = true;
        this.menuShow = false;
        this.outerVisible = false;
      }
      if (index == 2) {
        console.log("123");
        this.$refs["tree"].remove(this.nodekey);
        this.sendTree();
        this.$message({
          message: "删除成功",
          type: "success",
        });
        var obj = {
          sbpz_sbid: "",
          sbpz_jdzxz: "",
          sbpz_jysb: "",
          sbpz_sbmc: "",
          sbpz_mac: "",
          cjdpz_tagid: "",
          cjdpz_mc: "",
          cjdpz_sjq: "",
          cjdpz_jcqdz: "",
          cjdpz_cjsjlx: "",
          cjdpz_zjx: "",
          cjdpz_dxsx: "",
          cjdpz_beilv: "",
          ippz_wangkou: this.formdata.ippz_wangkou,
          ippz_zwym: this.formdata.ippz_zwym,
          ippz_mrwg: this.formdata.ippz_mrwg,
          ippz_dns_sx: this.formdata.ippz_dns_sx,
          ippz_dns_by: this.formdata.ippz_dns_by,
          ippz_ip: this.formdata.ippz_ip,
          ippz_mac: this.formdata.ippz_mac,
          wgpz_wgmc: this.formdata.wgpz_wgmc,
          wgpz_wgid: this.formdata.wgpz_wgid,
          wgpz_wglx: this.formdata.wgpz_wglx,
          tdpz_tdmc: "",
          tdpz_td: "",
          tdpz_qdmc: "",
          tdpz_ip: "",
          tdpz_port: "",
          tdpz_cssj: "",
          tdpz_jgsj: "",
          tdpz_lxsj: "",
          tdpz_cfcs: "",
          tdpz_watchtime: "",
          tdpz_cjsylxdz: "",
          tdpz_dxzkb: "",
          tdpz_050F: "",
          tdpz_0610: "",
          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_yx",
          user_id: this.user_id,
          // user_id: "USER202307301114011710",
          mark_value: JSON.stringify(obj),
          step: "1",
        });
        // alert("12342");
        this.$router.push(`/channelconfig?user_id=${this.user_id}`);
        // this.$router.back();
      }
      this.menuShow = false;
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick() {
      this.foo();
    },
    getDriveName() {
      this.diag_drive = true;
    },
    closeMenu(ev) {
      console.log({ ev });
      this.dialogVisible = false;
    },
    async saveDevice() {
      // let datas = sessionStorage.getItem("DB-IotLite_yx");
      // 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)),
      };
      let datas = { ...this.formdata, ...obj };
      this.add_passage = false;
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_yx",
        user_id: this.user_id,
        // user_id:'USER202307301114011710',
        mark_value: JSON.stringify(datas),
        step: "3",
      });
      console.log(res);
      sessionStorage.setItem(
        "answer",
        JSON.stringify(res.data.data.mark_value)
      );
      if (res.data.state) {
        this.$message({
          message: this.$t('success'),
          type: "success",
        });
        sessionStorage.setItem("DB-IotLite_yx", 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(`/dbcollect?user_id=${this.user_id}`);
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
    },
    async GetUserAnswer() {
      let answer = await GetUserAnswer({
        mark: "DB-IotLite_yx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
      });
      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_mac = obj.sbpz_mac;
          }
          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.tdpz_tdmc = obj.tdpz_tdmc;
          this.formdata.tdpz_td = obj.tdpz_td;
          this.formdata.tdpz_qdmc = obj.tdpz_qdmc;
          this.formdata.tdpz_ip = obj.tdpz_ip;
          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.tdpz_watchtime = obj.tdpz_watchtime;
          this.formdata.tdpz_cjsylxdz = obj.tdpz_cjsylxdz;
          this.formdata.tdpz_dxzkb = obj.tdpz_dxzkb;
          this.formdata.tdpz_050F = obj.tdpz_050F;
          this.formdata.tdpz_0610 = obj.tdpz_0610;
          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) {
        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_mac = obj.sbpz_mac;
        }
        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.tdpz_tdmc = obj.tdpz_tdmc;
        this.formdata.tdpz_td = obj.tdpz_td;
        this.formdata.tdpz_qdmc = obj.tdpz_qdmc;
        this.formdata.tdpz_ip = obj.tdpz_ip;
        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.tdpz_watchtime = obj.tdpz_watchtime;
        this.formdata.tdpz_cjsylxdz = obj.tdpz_cjsylxdz;
        this.formdata.tdpz_dxzkb = obj.tdpz_dxzkb;
        this.formdata.tdpz_050F = obj.tdpz_050F;
        this.formdata.tdpz_0610 = obj.tdpz_0610;
        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: "2",
      });
      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;
    if (this.user_id != "undefined") {
      GetTree({
        user_id: this.user_id,
        type: "1",
      }).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;
  },
};
</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: 12px;
}
</style>
