<!-- 采集点收集 -->
<template>
  <div>
    <!-- 设置树形控件 -->
    <!-- <el-button type="info" plain @click="dialogVisible = true">斥候采集点设置</el-button> -->
    <div v-show="dialogVisible" class="tree_menu">
      <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('edit') }}</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 class="pas_params" v-show="add_passage" v-loading="loading">
      <div>
        <el-button type="primary" plain @click="handleSelect">{{ $t('save') }}</el-button>
        <!-- <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
          <el-menu-item index="2">保存</el-menu-item>
        </el-menu> -->
      </div>
      <el-table ref="singleTable" :data="tableData" style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column property="cjdpz_tagid" label="TagID">
          <template slot-scope="scope">
            <el-select v-model="scope.row.cjdpz_tagid" placeholder="">
              <el-option v-for="(option, index) in options1" :key="index" :label="option.label"
                :value="option.value"></el-option>
            </el-select>
          </template>
        </el-table-column>
       <el-table-column property="cjdpz_mc" label="名称">
         <template slot-scope="scope">
           <el-select v-model="scope.row.cjdpz_mc" placeholder="">
             <el-option v-for="(option, index) in options2" :key="index" :label="option.label"
               :value="option.value"></el-option>
           </el-select>
         </template>
       </el-table-column>
        <el-table-column property="cjdpz_sjq" :label="$t('dbcollect.dataArea')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.cjdpz_sjq" placeholder="">
              <el-option v-for="(option, index) in options3" :key="index" :label="option.label"
                :value="option.value"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column property="cjdpz_jcqdz" :label="$t('dbcollect.registerAddress')" width="150px">
          <template slot-scope="scope">
            <!-- <el-select v-model="scope.row.cjdpz_jcqdz" placeholder="1">
              <el-option v-for="(option,index) in options4" :key="index" :label="option.label" :value="option.value"></el-option>
            </el-select> -->
            <el-input v-model="scope.row.cjdpz_jcqdz" placeholder="1-9999"></el-input>
          </template>
        </el-table-column>
        <el-table-column property="cjdpz_cjsjlx" :label="$t('dbcollect.type')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.cjdpz_cjsjlx" placeholder="">
              <el-option v-for="(option, index) in options5" :key="index" :label="option.label"
                :value="option.value"></el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column property="cjdpz_dxsx" :label="$t('dbcollect.readWrite')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.cjdpz_dxsx" placeholder="">
              <el-option v-for="(option, index) in options6" :key="index" :label="option.label"
                :value="option.value"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column property="cjdpz_scms" :label="$t('dbcollect.uploadMode')">
          <template slot-scope="scope">
            <el-select v-model="scope.row.cjdpz_scms" placeholder="">
              <el-option v-for="(option, index) in options7" :key="index" :label="option.label"
                :value="option.value"></el-option>
            </el-select>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 网关信息 -->
    <div class="gateway">
      <el-dialog :title="$t('dbcollectiongate.title')" :visible.sync="outerVisible" width="382px">
        <el-form :model="tableData[0]" :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="tableData[0].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="tableData[0].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 class="deviceinfo">
      <!-- <el-tree :data="datas2" :props="defaultProps" @node-click="handleDetailClick" default-expand-all></el-tree> -->
      <el-dialog title="新建设备" :visible.sync="add_device" width="902px" v-loading="loading">
        <el-form :model="tableData[0]" :label-position="labelPosition" :rules="rulesDevice" ref="formData">
          <el-row>
            <el-col :span="12">
              <el-form-item label="设备名称:" :label-width="formLabelWidth" prop="sbpz_sbmc">
                <el-select v-model="tableData[0].sbpz_sbmc" placeholder="" style="width: 200px; height: 30px">
                  <el-option v-for="item in opt1" :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="控制器协议:" :label-width="formLabelWidth" prop="sbpz_kzqxy">
                <el-row>
                  <el-col :span="18">
                    <el-input v-model="tableData[0].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="IP地址:" :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="端口号:" :label-width="formLabelWidth" prop="sbpz_port">
                <el-input v-model="tableData[0].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="从站地址:" :label-width="formLabelWidth" prop="sbpz_czdz">
                <el-input v-model="tableData[0].sbpz_czdz" 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="sbpz_lxzq">
                <el-input v-model="tableData[0].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>高级参数</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;
                  color: rgba(16, 16, 16, 1);
                  font-size: 14px;
                  text-align: left;
                  border: none;
                ">
                收起</el-button>
            </div>
          </div>
          <el-divider></el-divider>
          <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 label="启用毫秒采集:" :label-width="formLabelWidth" prop="sbpz_qyhmcj">
                  <el-switch v-model="tableData[0].sbpz_qyhmcj"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="启用批量采集:" :label-width="formLabelWidth" prop="sbpz_qyplcj">
                  <el-switch v-model="tableData[0].sbpz_qyplcj"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="最大批量采集数:" label-width="126px" prop="sbpz_zdplcjs">
                  <el-input v-model="tableData[0].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="采集超过时间(ms):" label-width="140px" prop="sbpz_cjcgsj">
                  <el-input v-model="tableData[0].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="周期上报OnChange数据:" label-width="186px" prop="sbpz_zqsbonchange">
                  <el-switch v-model="tableData[0].sbpz_zqsbonchange"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="通讯事件间隔(ms):" label-width="140px" prop="sbpz_txsjjg">
                  <el-input v-model="tableData[0].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="线圈寄存器写入功能码:" label-width="120px" style="line-height: 20px" class="cjjcq_code">
                    <el-select v-model="tableData[0].sbpz_xqjcqxr" placeholder="" style="width: 200px; height: 30px">
                      <el-option v-for="item in opt2" :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="线圈寄存器写入功能码:" label-width="120px" class="cjjcq_code">
                    <el-select v-model="tableData[0].sbpz_bcjcqxr" placeholder="" style="width: 200px; height: 30px">
                      <el-option v-for="item in opt3" :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="submitFormDevice">保 存</el-button>
          <el-button @click="add_device = 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>
</template>

<script>
import _ from 'lodash'
import {SaveUserAnswer, GetUserAnswer, GetTree, SendTree, getQueryAnswer} from "@/api/user";
export default {
  name: "ChiCollectionwifi",
  data() {
    return {
      user_id: "",
      loading: false,
      flag: false,
      add_device: false,
      diag_drive: false,
      isdisabled: true,
      is_retract: true,
      gateway: "",
      trees: [],
      options1: [
        {
          value: "MachinePamHID909",
          label: "MachinePamHID909",
        },
        {
          value: "MachinePamHID910",
          label: "MachinePamHID910",
        },
        {
          value: "MachinePamHID911",
          label: "MachinePamHID911",
        },
        {
          value: "MachinePamHID912",
          label: "MachinePamHID912",
        },
        {
          value: "MachinePamHID913",
          label: "MachinePamHID913",
        },
        {
          value: "MachinePamHID914",
          label: "MachinePamHID914",
        },
        {
          value: "MachinePamHID915",
          label: "MachinePamHID915",
        },
        {
          value: "MachinePamHID916",
          label: "MachinePamHID916",
        },
        {
          value: "MachinePamHID917",
          label: "MachinePamHID917",
        },
        {
          value: "MachinePamHID918",
          label: "MachinePamHID918",
        },
        {
          value: "MachinePamHID919",
          label: "MachinePamHID919",
        },
        {
          value: "MachinePamHID920",
          label: "MachinePamHID920",
        },
        {
          value: "MachinePamHID921",
          label: "MachinePamHID921",
        },
        {
          value: "MachinePamHID922",
          label: "MachinePamHID922",
        },
        {
          value: "MachinePamHID923",
          label: "MachinePamHID923",
        },
        {
          value: "MachinePamHID924",
          label: "MachinePamHID924",
        },
        {
          value: "MachinePamHID925",
          label: "MachinePamHID925",
        },
        {
          value: "MachinePamHID926",
          label: "MachinePamHID926",
        },
        {
          value: "MachinePamHID927",
          label: "MachinePamHID927",
        },
        {
          value: "MachinePamHID928",
          label: "MachinePamHID928",
        },
        {
          value: "MachinePamHID929",
          label: "MachinePamHID929",
        },
        {
          value: "MachinePamHID930",
          label: "MachinePamHID930",
        },
        {
          value: "MachinePamHID931",
          label: "MachinePamHID931",
        },
        {
          value: "MachinePamHID932",
          label: "MachinePamHID932",
        },
        {
          value: "MachinePamHID933",
          label: "MachinePamHID933",
        },
        {
          value: "MachinePamHID934",
          label: "MachinePamHID934",
        },
        {
          value: "MachinePamHID935",
          label: "MachinePamHID935",
        },
        {
          value: "MachinePamHID936",
          label: "MachinePamHID936",
        },
        {
          value: "MachinePamHID937",
          label: "MachinePamHID937",
        },
        {
          value: "MachinePamHID938",
          label: "MachinePamHID938",
        },
      ],
      options2:this.$t('dbcollect.options2'),
      options3: [
        {
          value: "0X (Coil Status)",
          label: "0X (Coil Status)",
        },
        {
          value: "1X (Input Status)",
          label: "1X (Input Status)",
        },
        {
          value: "3X (Input Registers)",
          label: "3X (Input Registers)",
        },
        {
          value: "4X (Holding Register)",
          label: "4X (Holding Register)",
        },
      ],
      options4: [
        {
          value: "2000H",
          label: "2000H",
        },
        {
          value: "2002H",
          label: "2002H",
        },
        {
          value: "2004H",
          label: "2004H",
        },
        {
          value: "2005H",
          label: "2005H",
        },
        {
          value: "2006H",
          label: "2006H",
        },
        {
          value: "2007H",
          label: "2007H",
        },
        {
          value: "2008H",
          label: "2008H",
        },
        {
          value: "2009H",
          label: "2009H",
        },
        {
          value: "2010H",
          label: "2010H",
        },
        {
          value: "2011H",
          label: "2011H",
        },
        {
          value: "2012H",
          label: "2012H",
        },
        {
          value: "2013H",
          label: "2013H",
        },
        {
          value: "2014H",
          label: "2014H",
        },
        {
          value: "2015H",
          label: "2015H",
        },
        {
          value: "2016H",
          label: "2016H",
        },
        {
          value: "2017H",
          label: "2017H",
        },
        {
          value: "2018H",
          label: "2018H",
        },
        {
          value: "2019H",
          label: "2019H",
        },
        {
          value: "2020H",
          label: "2020H",
        },
        {
          value: "2021H",
          label: "2021H",
        },
        {
          value: "2022H",
          label: "2022H",
        },
        {
          value: "2023H",
          label: "2023H",
        },
        {
          value: "2024H",
          label: "2024H",
        },
        {
          value: "2027H",
          label: "2027H",
        },
        {
          value: "2028H",
          label: "2028H",
        },
        {
          value: "2029H",
          label: "2029H",
        },
        {
          value: "2030H",
          label: "2030H",
        },
        {
          value: "2031H",
          label: "2031H",
        },
      ],
      options5: this.$t('dbcollect.options5'),
      options6: this.$t('dbcollect.options7'),
      options7: [
        {
          value: "Periodic",
          label: "Periodic",
        },
        {
          value: "Onchange",
          label: "Onchange",
        },
        {
          value: "Never",
          label: "Never",
        },
      ],
      activeIndex: "1",
      checked: "",
      labelPosition: "left",
      formLabelWidth: "116px",
      input1: 192,
      add_passage: true,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      datas: [
        {
          label: "Gateway",
          children: [
            {
              label: "数据采集",
              children: [
                {
                  label: "I/O点",
                },
                {
                  label: "用户点",
                },
                {
                  label: "计算点",
                },
                {
                  label: "系统点",
                },
              ],
            },
            {
              label: "上云服务",
              children: [
                {
                  label: "标准 MQTT",
                },
                {
                  label: "AWS loT",
                },
              ],
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      tableData: [
        {
          ippz_ssid: "",
          ippz_rzfs: "",
          ippz_jmfs: "",
          ippz_mm: "",

          wgpz_wgmc: "",
          wgpz_wgid: "",

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

          cjdpz_tagid: "",
          cjdpz_mc: "",
          cjdpz_dz: "",
          cjdpz_jcqdz: "",
          cjdpz_cjsjlx: "",
          cjdpz_dxsx: "",
          cjdpz_scms: "",
          // cjdpz_dw: "",

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

          mqtt_sssjfbzt: "",
          mqtt_qos: "",

          mqtt_cjd_sbmc: "",
          mqtt_cjd_tagid: "",
        },
      ],
      // 网关配置的出现
      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" },
        ],
      },
      opts1: this.$t('dbcollectiongate.options2'),
      opts2: [
        {
          value: "LAN-BOX2",
          label: "LAN-BOX2",
        },
        {
          value: "WLAN-BOX2",
          label: "WLAN-BOX2",
        },
      ],
      // 设备信息
      sbpz_ip1: "",
      sbpz_ip2: "",
      sbpz_ip3: "",
      sbpz_ip4: "",
      opt1: [
        {
          value: "有线区精雕2",
          label: "有线区精雕2",
        },
        {
          value: "无线区精雕2",
          label: "无线区精雕2",
        },
      ],
      opt2: [
        {
          value: "05",
          label: "05",
        },
      ],
      opt3: [
        {
          value: "06",
          label: "06",
        },
      ],
      isdisabled: true,
      radio: "1",
      checked1: false,
      is_retract: true,
      labelPosition: "left",
      formLabelWidth: "116px",
      input1: 192,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      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",
      },
      rulesDevice: {
        sbpz_sbmc: [
          { required: true, message: "请输入通道名称", trigger: "change" },
        ],
        sbpz_kzqxy: [
          { required: true, message: "请输入控制器协议", trigger: "blur" },
        ],
        sbpz_ip: [
          {
            required: true,
            message: "",
            validator: this.validateIp,
            trigger: "blur",
          },
        ],
        sbpz_czdz: [
          { required: true, message: "请输入从站地址", trigger: "blur" },
        ],
        sbpz_port: [
          { required: true, message: "请输入端口号", trigger: "blur" },
        ],
        sbpz_lxzq: [
          { required: true, message: "请输入轮询时间", trigger: "blur" },
        ],
        sbpz_qyhmcj: [
          { required: true, message: "启用毫秒采集", trigger: "change" },
        ],
        sbpz_qyplcj: [
          { required: true, message: "启用批量采集", trigger: "change" },
        ],
        sbpz_zdplcjs: [
          { required: true, message: "请输入最大批量采集数", trigger: "blur" },
        ],
        sbpz_cjcgsj: [
          { required: true, message: "请输入采集超过时间", trigger: "blur" },
        ],
        sbpz_zqsbonchange: [
          {
            required: true,
            message: "周期上报Onchange数据",
            trigger: "change",
          },
        ],
        sbpz_txsjjg: [
          { required: true, message: "请输入通讯时间间隔", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    async rightClick(e, data, node) {
      console.log(node);
      console.log(data);
      if (data.editing) {
        this.outerVisible = true;
        this.getUserAnswer();
      }
      if (node.level == 3 && data.label==this.tableData[0].sbpz_sbmc ) {
        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_device = true;
        this.add_passage = false;
        this.outerVisible = false;
        let { data } = await GetUserAnswer({
          mark: "CHGYWG_wx",
          user_id: this.user_id,
        });
        this.loading = false;
        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];
          }
          if (obj.sbpz_qyhmcj) {
            this.tableData[0].sbpz_zqsbonchange = Boolean(Number(obj.sbpz_zqsbonchange));
            this.tableData[0].sbpz_qyhmcj = Boolean(Number(obj.sbpz_qyhmcj));
            this.tableData[0].sbpz_qyplcj = Boolean(Number(obj.sbpz_qyplcj));
          }
          this.tableData[0].sbpz_sbmc = obj.sbpz_sbmc;
          this.tableData[0].sbpz_kzqxy = obj.sbpz_kzqxy;
          this.tableData[0].sbpz_port = obj.sbpz_port;
          this.tableData[0].sbpz_czdz = obj.sbpz_czdz;
          this.tableData[0].sbpz_lxzq = obj.sbpz_lxzq;
          this.tableData[0].sbpz_zdplcjs = obj.sbpz_zdplcjs;
          this.tableData[0].sbpz_cjcgsj = obj.sbpz_cjcgsj;
          // console.log(this.formData.sbpz_zqsbonchange);
          this.tableData[0].sbpz_txsjjg = obj.sbpz_txsjjg;
          this.tableData[0].sbpz_xqjcqxr = obj.sbpz_xqjcqxr;
          this.tableData[0].sbpz_bcjcqxr = obj.sbpz_bcjcqxr;
          this.tableData[0].wgpz_wgid = obj.wgpz_wgid;
          this.tableData[0].wgpz_wgmc = obj.wgpz_wgmc;

          this.tableData[0].ippz_ssid = obj.ippz_ssid;
          this.tableData[0].ippz_rzfs = obj.ippz_rzfs;
          this.tableData[0].ippz_jmfs = obj.ippz_jmfs;
          this.tableData[0].ippz_mm = obj.ippz_mm;

          this.tableData[0].cjdpz_tagid = obj.cjdpz_tagid;
          this.tableData[0].cjdpz_mc = obj.cjdpz_mc;
          this.tableData[0].cjdpz_sjq = obj.cjdpz_sjq;
          this.tableData[0].cjdpz_jcqdz = obj.cjdpz_jcqdz;
          this.tableData[0].cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
          this.tableData[0].cjdpz_dxsx = obj.cjdpz_dxsx;
          this.tableData[0].cjdpz_scms = obj.cjdpz_scms;

          this.tableData[0].mqtt_ip = obj.mqtt_ip;
          this.tableData[0].mqtt_wgsn = obj.mqtt_wgsn;
          this.tableData[0].mqtt_port = obj.mqtt_port;
          this.tableData[0].mqtt_keepalive = obj.mqtt_keepalive;
          // this.tableData[0].mqtt_tls = obj.mqtt_tls;
          // this.tableData[0].mqtt_clearsession = obj.mqtt_clearsession;
          this.tableData[0].mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
          this.tableData[0].mqtt_qos = obj.mqtt_qos;

          this.tableData[0].mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
          this.tableData[0].mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
        }
      }
      else{
        this.menuShow=false;
      }
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick() {
      this.add_passage = true;
      this.foo();
    },
    getDriveName() {
      this.diag_drive = true;
    },
    // 保存表格
    async handleSelect() {
      // console.log(JSON.parse(datas));
      // let datas = { ...JSON.parse(datas), ...this.tableData[0] };
      let res = await SaveUserAnswer({
        mark: "CHGYWG_wx",
        user_id: this.user_id,
        mark_value: JSON.stringify(this.tableData[0]),
        step: "2",
      });
      // alert(this.tableData[0].cjdpz_sjq);
      // console.log(res, "采集点收集页面表格");
      if (res.data.state) {
        this.$message({
          message: this.$t('success'),
          type: "success",
        });
        console.log(res);
        // sessionStorage.setItem("CHGYWG_wx", JSON.stringify(this.tableData[0]));
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
    },
    async getUserAnswer() {
      this.loading = true;
      let { data } = await GetUserAnswer({
        mark: "CHGYWG_wx",
        user_id: this.user_id,
      });
      this.loading = false;
      console.log(data, "斥候采集器页面");
      if (data.data && data.state) {
        // console.log(JSON.parse(data.data.mark_value));
        let obj = JSON.parse(data.data.mark_value);
        if (obj.cjdpz_tagid) {
          this.tableData[0].cjdpz_tagid = obj.cjdpz_tagid;
          this.tableData[0].cjdpz_mc = obj.cjdpz_mc;
          this.tableData[0].cjdpz_sjq = obj.cjdpz_sjq;
          this.tableData[0].cjdpz_jcqdz = obj.cjdpz_jcqdz;
          this.tableData[0].cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
          this.tableData[0].cjdpz_dxsx = obj.cjdpz_dxsx;
          this.tableData[0].cjdpz_scms = obj.cjdpz_scms;
          // this.tableData[0].cjdpz_dw = obj.cjdpz_dw;
        }
        this.tableData[0].sbpz_sbmc = obj.sbpz_sbmc;
        this.tableData[0].sbpz_kzqxy = obj.sbpz_kzqxy;
        this.tableData[0].sbpz_ip = obj.sbpz_ip;
        this.tableData[0].sbpz_port = obj.sbpz_port;
        this.tableData[0].sbpz_czdz = obj.sbpz_czdz;
        this.tableData[0].sbpz_lxzq = obj.sbpz_lxzq;
        this.tableData[0].sbpz_qyhmcj = obj.sbpz_qyhmcj;
        this.tableData[0].sbpz_qyplcj = obj.sbpz_qyplcj;
        this.tableData[0].sbpz_zdplcjs = obj.sbpz_zdplcjs;
        this.tableData[0].sbpz_cjcgsj = obj.sbpz_cjcgsj;
        this.tableData[0].sbpz_zqsbonchange = obj.sbpz_zqsbonchange;
        this.tableData[0].sbpz_txsjjg = obj.sbpz_txsjjg;
        this.tableData[0].sbpz_xqjcqxr = obj.sbpz_xqjcqxr;
        this.tableData[0].sbpz_bcjcqxr = obj.sbpz_bcjcqxr;

        this.tableData[0].wgpz_wgid = obj.wgpz_wgid;
        this.tableData[0].wgpz_wgmc = obj.wgpz_wgmc;

        this.tableData[0].ippz_ssid = obj.ippz_ssid;
        this.tableData[0].ippz_rzfs = obj.ippz_rzfs;
        this.tableData[0].ippz_jmfs = obj.ippz_jmfs;
        this.tableData[0].ippz_mm = obj.ippz_mm;

        this.tableData[0].mqtt_ip = obj.mqtt_ip;
        this.tableData[0].mqtt_wgsn = obj.mqtt_wgsn;
        this.tableData[0].mqtt_port = obj.mqtt_port;
        this.tableData[0].mqtt_keepalive = obj.mqtt_keepalive;
        this.tableData[0].mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
        this.tableData[0].mqtt_qos = obj.mqtt_qos;
        this.tableData[0].mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
        this.tableData[0].mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
      }else{
        getQueryAnswer({
          mark: "CHGYWG_wx",
          user_id: this.user_id
        }).then(res => {
          let obj = JSON.parse(res.data.data.r3);
          if (obj.cjdpz_tagid) {
            this.tableData[0].cjdpz_tagid = obj.cjdpz_tagid;
            this.tableData[0].cjdpz_mc = obj.cjdpz_mc;
            this.tableData[0].cjdpz_sjq = obj.cjdpz_sjq;
            this.tableData[0].cjdpz_jcqdz = obj.cjdpz_jcqdz;
            this.tableData[0].cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
            this.tableData[0].cjdpz_dxsx = obj.cjdpz_dxsx;
            this.tableData[0].cjdpz_scms = obj.cjdpz_scms;
            // this.tableData[0].cjdpz_dw = obj.cjdpz_dw;
          }
          this.tableData[0].sbpz_sbmc = obj.sbpz_sbmc;
          this.tableData[0].sbpz_kzqxy = obj.sbpz_kzqxy;
          this.tableData[0].sbpz_ip = obj.sbpz_ip;
          this.tableData[0].sbpz_port = obj.sbpz_port;
          this.tableData[0].sbpz_czdz = obj.sbpz_czdz;
          this.tableData[0].sbpz_lxzq = obj.sbpz_lxzq;
          this.tableData[0].sbpz_qyhmcj = obj.sbpz_qyhmcj;
          this.tableData[0].sbpz_qyplcj = obj.sbpz_qyplcj;
          this.tableData[0].sbpz_zdplcjs = obj.sbpz_zdplcjs;
          this.tableData[0].sbpz_cjcgsj = obj.sbpz_cjcgsj;
          this.tableData[0].sbpz_zqsbonchange = obj.sbpz_zqsbonchange;
          this.tableData[0].sbpz_txsjjg = obj.sbpz_txsjjg;
          this.tableData[0].sbpz_xqjcqxr = obj.sbpz_xqjcqxr;
          this.tableData[0].sbpz_bcjcqxr = obj.sbpz_bcjcqxr;

          this.tableData[0].wgpz_wgid = obj.wgpz_wgid;
          this.tableData[0].wgpz_wgmc = obj.wgpz_wgmc;

          this.tableData[0].ippz_ssid = obj.ippz_ssid;
          this.tableData[0].ippz_rzfs = obj.ippz_rzfs;
          this.tableData[0].ippz_jmfs = obj.ippz_jmfs;
          this.tableData[0].ippz_mm = obj.ippz_mm;

          this.tableData[0].mqtt_ip = obj.mqtt_ip;
          this.tableData[0].mqtt_wgsn = obj.mqtt_wgsn;
          this.tableData[0].mqtt_port = obj.mqtt_port;
          this.tableData[0].mqtt_keepalive = obj.mqtt_keepalive;
          this.tableData[0].mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
          this.tableData[0].mqtt_qos = obj.mqtt_qos;
          this.tableData[0].mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
          this.tableData[0].mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
        })
      }
    },
    async sendTree() {
      let result = await SendTree({
        user_id: this.user_id,
        data: JSON.stringify(this.trees),
        type: "4",
      });
      console.log(result);
    },
    //斥候设备的配置信息
    // 收起点击事件的判断
    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.tableData[0].sbpz_kzqxy = data.label;
        this.diag_drive = false;
      }
    },
    // 设备修改的校验信息
    //ip地址验证
    validateIp(rule, value, callback) {
      if (
        this.sbpz_ip1 +
        "." +
        this.sbpz_ip2 +
        "." +
        this.sbpz_ip3 +
        "." +
        this.sbpz_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.sbpz_ip1 +
          "." +
          this.sbpz_ip2 +
          "." +
          this.sbpz_ip3 +
          "." +
          this.sbpz_ip4
        )
      ) {
        callback(new Error("请输入有效的IP地址"));
      } else {
        callback();
      }
    },
    submitFormDevice: _.debounce(function () {
      this.$refs["formData"].validate((valid) => {
        if (valid) {
          this.saveDevice();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }, 1000),
    async saveDevice() {
      var obj = {
        sbpz_sbmc: this.tableData[0].sbpz_sbmc,
        sbpz_kzqxy: this.tableData[0].sbpz_kzqxy,
        sbpz_ip: this.sbpz_ip1 + "." + this.sbpz_ip2 + "." + this.sbpz_ip3 + "." + this.sbpz_ip4,
        sbpz_port: this.tableData[0].sbpz_port,
        sbpz_czdz: this.tableData[0].sbpz_czdz,
        sbpz_lxzq: this.tableData[0].sbpz_lxzq,
        sbpz_qyhmcj: String(Number(this.tableData[0].sbpz_qyhmcj)),
        sbpz_qyplcj: String(Number(this.tableData[0].sbpz_qyplcj)),
        sbpz_zdplcjs: this.tableData[0].sbpz_zdplcjs,
        sbpz_cjcgsj: this.tableData[0].sbpz_cjcgsj,
        sbpz_zqsbonchange: String(Number(this.tableData[0].sbpz_zqsbonchange)),
        sbpz_txsjjg: this.tableData[0].sbpz_txsjjg,
        sbpz_xqjcqxr: this.tableData[0].sbpz_xqjcqxr,
        sbpz_bcjcqxr: this.tableData[0].sbpz_bcjcqxr,
        ippz_ssid: this.tableData[0].ippz_ssid,
        ippz_rzfs: this.tableData[0].ippz_rzfs,
        ippz_jmfs: this.tableData[0].ippz_jmfs,
        ippz_mm: this.tableData[0].ippz_mm,
        wgpz_wgmc: this.tableData[0].wgpz_wgmc,
        wgpz_wgid: this.tableData[0].wgpz_wgid,
        cjdpz_tagid: this.tableData[0].cjdpz_tagid,
        cjdpz_mc: this.tableData[0].cjdpz_mc,
        cjdpz_sjq: this.tableData[0].cjdpz_sjq,
        cjdpz_jcqdz: this.tableData[0].cjdpz_jcqdz,
        cjdpz_cjsjlx: this.tableData[0].cjdpz_cjsjlx,
        cjdpz_dxsx: this.tableData[0].cjdpz_dxsx,
        cjdpz_scms: this.tableData[0].cjdpz_scms,
        mqtt_ip: this.tableData[0].mqtt_ip,
        mqtt_wgsn: this.tableData[0].mqtt_wgsn,
        mqtt_port: this.tableData[0].mqtt_port,
        mqtt_keepalive: this.tableData[0].mqtt_keepalive,
        // mqtt_tls: this.tableData[0].mqtt_tls,
        // mqtt_clearsession: this.tableData[0].mqtt_clearsession,
        mqtt_sssjfbzt: this.tableData[0].mqtt_sssjfbzt,
        mqtt_qos: this.tableData[0].mqtt_qos,

        mqtt_cjd_sbmc: this.tableData[0].mqtt_cjd_sbmc,
        mqtt_cjd_tagid: this.tableData[0].mqtt_cjd_tagid,
      };
      let res = await SaveUserAnswer({
        mark: "CHGYWG_wx",
        user_id: this.user_id,
        mark_value: JSON.stringify(obj),
        step: "2",
      });
      console.log(res);
      if (res.data.state) {
        this.$message({
          message: "更改成功",
          type: "success",
        });
        this.add_device = false;
        // alert(JSON.stringify(res.data.data.mark_value))
        this.updateLabelById(this.nodekey, this.tableData[0].sbpz_sbmc);
        this.sendTree();
      } else {
        this.$message({
          message: `保存失败`,
          type: "error",
        });
      }
    },

    // 修改树形控件的名字
    findNodeById(nodes, targetId) {
      let foundNode = null;
      const findNode = (nodes) => {
        for (const node of nodes) {
          if (node.id === targetId) {
            // 找到节点
            foundNode = node;
            return;
          }
          if (node.children) {
            findNode(node.children);
          }
        }
      };

      findNode(nodes);
      return foundNode;
    },
    updateLabelById(targetId, newLabel) {
      const targetNode = this.findNodeById(this.trees, targetId);
      // console.log(targetId);
      // console.log(targetNode);
      // console.log(newLabel);
      if (targetNode) {
        // 找到节点，更新label值
        // console.log(targetNode);
        // console.log(newLabel);
        this.$set(targetNode, "label", newLabel);
        // 强制更新视图
        this.$forceUpdate();
        // this.getTree();
        // this.getTree();
      }
    },

    //网关配置的信息
    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("CHGYWG_wx");
      // console.log(JSON.parse(datas));
      // datas = { ...JSON.parse(datas), ...this.gateWay };
      // console.log(datas);
      let res = await SaveUserAnswer({
        mark: "CHGYWG_wx",
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        mark_value: JSON.stringify(this.tableData[0]),
        step: "2",
      });
      if (res.data.state) {
        this.$message({
          message: "修改成功",
          type: "success",
        });
        this.trees[0].label = this.tableData[0].wgpz_wgid;
        this.sendTree();
        sessionStorage.setItem("CHGYWG_wx", JSON.stringify(this.tableData[0]));
      } 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: this.user_id,
      type: "4",
    }).then((res) => {
      if(this.$i18n.locale==='zh'){
        this.trees = JSON.parse(res.data.data.r2);
      }else{
        this.trees = JSON.parse(res.data.data.data);
      }
    });
    }
    this.getUserAnswer();
  },
};
</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;
}

/deep/ .pas_params {
  position: absolute;
  left: 362px;
  top: 95px;
  width: 1066px;
  height: 752px;
  line-height: 20px;
  border-radius: 3px;
  color: white;
  background-image: url(../assets/image/bg.png);
  background-size: 100% 100%;
  // text-align: center;
  border: 1px solid rgba(220, 220, 220, 1);

  .el-button {
    width: 80px;
    height: 30px;
    line-height: 0.5;
  }

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

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

  .el-row {
    height: 40px;
    display: flex;
    align-items: flex-start;

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

    .el-col-9 {
      padding-left: 30px;
    }
  }

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

  .content {
    position: absolute;
    left: 377px;
    top: 69px;
    width: 1220px;
    height: 836px;
    line-height: 20px;
    padding-left: 36px;
    background-color: rgba(255, 255, 255, 1);
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
    border: 1px solid rgba(187, 187, 187, 1);
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;

    .el-form-item {
      margin-bottom: 0px;
    }

    /deep/ .con_left {
      .el-con-5 {
        width: 43px;
      }
    }

    .con_left {
      width: 709px;
      position: relative;

      .con_left_footer {
        position: absolute;
        left: 499px;
        top: 777px;
      }
    }

    .con_right {
      width: 480px;

      .dialog-footer {
        .el-button {
          width: 80px;
          height: 30px;
          line-height: 0.5;
        }
      }
    }
  }
}

/deep/ .deviceinfo {
  .el-form-item {
    margin-bottom: 20px !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>
