<!-- 网关通道 -->
<template>
  <div>
    <!-- v-click-outside="closeMenu" -->
    <div>
      <div class="tree_menu" v-show="dialogVisible">
        <el-tree
          :data="trees"
          node-key="id"
          :props="defaultProps"
          default-expand-all
          @node-contextmenu="rightClick"
          @node-click="treeNodeClick"
          ref="tree"
        >
        </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('addChannel') }}</span>
            </el-menu-item>
            <el-menu-item index="2" style="font-size: 12px">
              <span slot="title">{{ $t('cancel') }}</span>
            </el-menu-item>
          </el-menu>
        </div>
      </div>
    </div>
    <div :class="$i18n.locale==='zh'?'zh pas_params':'pas_params'">
      <el-dialog
        :title="$t('channelconfig.title')"
        :visible.sync="add_passage"
        width="765px"
        v-loading="loading"
      >
        <el-form
          :model="FormData"
          :label-position="labelPosition"
          :rules="rules"
          ref="FormData"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item
                :label="$t('channelconfig.name')"
                :label-width="formLabelWidth"
                prop="tdpz_tdmc"
              >
                <el-select
                  v-model="FormData.tdpz_tdmc"
                  placeholder=""
                  style="width: 200px; height: 30px"
                >
                  <el-option
                    v-for="(item, index) in options1"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                :label="$t('channelconfig.channel')"
                :label-width="formLabelWidth"
                prop="tdpz_td"
              >
                <el-select
                  v-model="FormData.tdpz_td"
                  placeholder=""
                  style="width: 200px; height: 30px"
                >
                  <el-option
                    v-for="(item, index) in options2"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('channelconfig.driverName')"
                :label-width="formLabelWidth"
                prop="tdpz_qdmc"
              >
                <el-row>
                  <el-col :span="18">
                    <el-input
                      v-model="FormData.tdpz_qdmc"
                      placeholder=""
                      disabled
                      style="width: 200px; height: 30px"
                    ></el-input>
                    <el-button v-if="$i18n.locale==='zh'"
                        style="width: 50px; height: 30px;position: absolute;right:-4px;top:4px"
                        @click="getDriveName"
                    >...</el-button
                    >
                  </el-col>
                  <el-col :span="6">
                    <el-button
                        v-if="$i18n.locale==='en'"
                      style="width: 50px; height: 30px"
                      @click="getDriveName"
                      >...</el-button
                    >
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <div v-if="FormData.tdpz_td == '串口'">
            <el-row>
              <el-col :span="12">
                <el-form-item label="串口号:" :label-width="formLabelWidth">
                  <el-select
                    v-model="formData.tdpz_chuankou"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  >
                    <el-option
                      v-for="item in optts1"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="波特率:" :label-width="formLabelWidth">
                  <el-select
                    v-model="formData.tdpz_btl"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  >
                    <el-option
                      v-for="item in optts2"
                      :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">
                  <el-select
                    v-model="formData.tdpz_sjw"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  >
                    <el-option
                      v-for="item in optts3"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="停止位:" :label-width="formLabelWidth">
                  <el-select
                    v-model="formData.tdpz_tzw"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  >
                    <el-option
                      v-for="item in optts4"
                      :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">
                  <el-select
                    v-model="formData.tdpz_jojy"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  >
                    <el-option
                      v-for="item in optts5"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div v-else>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  :label="$t('channelconfig.IP')"
                  :label-width="formLabelWidth"
                  prop="tdpz_ip"
                >
                  <el-row>
                    <el-col :span="5">
                      <el-input
                        v-model="tdpz_ip1"
                        style="width: 43px; height: 30px"
                      ></el-input>
                    </el-col>
                    <el-col :span="1" style="color: #fff">. </el-col>
                    <el-col :span="5">
                      <el-input
                        v-model="tdpz_ip2"
                        style="width: 43px; height: 30px"
                      ></el-input>
                    </el-col>
                    <el-col :span="1" style="color: #fff">.</el-col>
                    <el-col :span="5">
                      <el-input
                        v-model="tdpz_ip3"
                        style="width: 43px; height: 30px"
                      ></el-input>
                    </el-col>
                    <el-col :span="1" style="color: #fff">.</el-col>
                    <el-col :span="5">
                      <el-input
                        v-model="tdpz_ip4"
                        style="width: 43px; height: 30px"
                      ></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  :label="$t('channelconfig.port')"
                  :label-width="formLabelWidth"
                  prop="tdpz_port"
                >
                  <el-input
                    v-model="FormData.tdpz_port"
                    placeholder=""
                    style="width: 200px; height: 30px"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-row>
            <el-col :span="12">
              <el-form-item
                  :label="$t('channelconfig.overTime')"
                :label-width="formLabelWidth"
                prop="tdpz_cssj"
              >
                <el-input
                  v-model="FormData.tdpz_cssj"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                  :label="$t('channelconfig.intervalTime')"
                :label-width="formLabelWidth"
                prop="tdpz_jgsj"
              >
                <el-input
                  v-model="FormData.tdpz_jgsj"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                  :label="$t('channelconfig.pollTime')"
                :label-width="formLabelWidth"
                prop="tdpz_lxsj"
              >
                <el-input
                  v-model="FormData.tdpz_lxsj"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                  :label="$t('channelconfig.retryCount')"
                :label-width="formLabelWidth"
                prop="tdpz_cfcs"
              >
                <el-input
                  v-model="FormData.tdpz_cfcs"
                  placeholder=""
                  style="width: 200px; height: 30px"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div :class="$i18n.locale==='zh'?'zh super_parmams':'super_parmams'">
          <h3>{{ $t('channelconfig.title1') }}</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="
                border: none;
                color: rgba(16, 16, 16, 1);
                font-size: 14px;
                text-align: left;
              "
            >
              {{ $t('put') }}</el-button
            >
          </div>
        </div>
        <div  :class="$i18n.locale==='zh'?'super super_con':'super_con'" v-show="is_retract">
          <el-form
            :label-position="labelPosition"
            :rules="rules"
            ref="ruleForm"
          >
            <el-row>
              <el-col :span="12">
                <el-form-item>
                  <el-checkbox v-model="FormData.tdpz_watchtime"
                    >watch time(s)</el-checkbox
                  >
                  <el-input
                    v-model="input1"
                    placeholder=""
                    style="width: 200px; height: 30px"
                    :disabled="isdisabled"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item>
                  <el-checkbox v-model="FormData.tdpz_cjsylxdz"
                    >{{ $t('channelconfig.check') }}</el-checkbox
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item :label="$t('channelconfig.reading')" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="10">
                      <el-input
                        v-model="tdpz_dxzkb1"
                        style="width: 91px; height: 30px"
                      ></el-input>
                    </el-col>
                    <el-col :span="4">: </el-col>
                    <el-col :span="10">
                      <el-input
                        v-model="tdpz_dxzkb2"
                        style="width: 91px; height: 30px"
                      ></el-input>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="05/0F:" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_050F" label="auto"
                        >auto</el-radio
                      ></el-col
                    >
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_050F" label="05"
                        >05</el-radio
                      ></el-col
                    >
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_050F" label="0F"
                        >0F</el-radio
                      ></el-col
                    >
                  </el-row>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="06/10:" :label-width="formLabelWidth">
                  <el-row>
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_0610" label="auto"
                        >auto</el-radio
                      ></el-col
                    >
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_0610" label="06"
                        >06</el-radio
                      ></el-col
                    >
                    <el-col :span="8"
                      ><el-radio v-model="FormData.tdpz_0610" label="10"
                        >10</el-radio
                      ></el-col
                    >
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">{{ $t('save') }}</el-button>
          <el-button @click="add_passage = false">{{ $t('cancel') }}</el-button>
        </span>
      </el-dialog>
    </div>
    <div class="drvieName_All" v-show="diag_drive">
      <div class="title">
        <p class="title_l">{{$t('channelconfig.agreementName')}}</p>
        <i class="el-icon-close title_r" @click="diag_drive = false"></i>
      </div>
      <el-divider></el-divider>
      <el-tree
        :data="datas2"
        :props="defaultProps"
        @node-click="handleDetailClick"
        default-expand-all
      ></el-tree>
    </div>
<!--    设备配置-->
    <div class="gateway">
      <el-dialog :title="$t('dbcollectiongate.title')" :visible.sync="outerVisible" width="382px">
        <el-form
          :model="FormData"
          :rules="rulesGate"
          ref="gateWay"
          :label-width="$i18n.locale === 'zh'?'130px':'85px'"
          class="demo-ruleForm"
        >
          <el-form-item :label="$t('dbcollectiongate.name')" prop="wgpz_wgmc">
            <el-select
              v-model="FormData.wgpz_wgmc"
              :placeholder="$t('select')"
              style="width: 200px"
            >
              <el-option
                v-for="item in opts1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('dbcollectiongate.ID')" prop="wgpz_wgid">
            <el-select
              v-model="FormData.wgpz_wgid"
              :placeholder="$t('select')"
              style="width: 200px"
            >
              <el-option
                v-for="item in opts2"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-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 _ from 'lodash';
import {SaveUserAnswer, GetUserAnswer, GetTree, SendTree, getQueryAnswer} from "@/api/user";

export default {
  name: "TestTreeView",

  data() {
    return {
      formData: {
        tdpz_chuankou: "",
        tdpz_btl: "",
        tdpz_tzw: "",
        tdpz_sjw: "8",
        tdpz_jojy: "",
      },
      loading: false,
      flag: false,
      isDuan: true,
      user_id: "",
      FormData: {
        ippz_wangkou: "",
        ippz_zwym: "",
        ippz_mrwg: "",
        ippz_dns_sx: "",
        ippz_dns_by: "",
        ippz_ip: "",
        ippz_mac: "",
        wgpz_wgmc: "",
        wgpz_wgid: "",
        wgpz_wglx: "",
        tdpz_tdmc: "",
        tdpz_td: "",
        tdpz_qdmc: "",
        tdpz_port: "",
        tdpz_cssj: "",
        tdpz_jgsj: "",
        tdpz_lxsj: "",
        tdpz_cfcs: "",
        tdpz_watchtime: false,
        tdpz_cjsylxdz: true,
        tdpz_dxzkb: "",
        tdpz_050F: "auto",
        tdpz_0610: "auto",
        sbpz_sbid: "",
        sbpz_sbmc: "",
        sbpz_mac: "",
        sbpz_jysb: "",
        sbpz_jdzxz: "",
        cjdpz_tagid: "",
        cjdpz_mc: "",
        cjdpz_sjq: "",
        cjdpz_jcqdz: "",
        cjdpz_cjsjlx: "",
        cjdpz_zjx: "",
        cjdpz_dxsx: "",
        cjdpz_beilv: "",
        mqtt_qiyong: "",
        mqtt_ip: "",
        mqtt_port: "",
        mqtt_wgsn: "",
        mqtt_sssjfbzt: "",
        mqtt_qos: "",
        mqtt_scms: "",
        mqtt_sczq: "",
        mqtt_sjgl: "",
        mqtt_cjd_sbmc: "",
        mqtt_cjd_tagid: "",
      },
      tdpz_dxzkb1: "1",
      tdpz_dxzkb2: "1",
      tdpz_ip1: "",
      tdpz_ip2: "",
      tdpz_ip3: "",
      tdpz_ip4: "",
      options1:this.$t('channelconfig.options1'),
      options2: this.$t('channelconfig.options'),
      value1: "有线区Channel1",
      value2: "网口",
      diag_drive: false,
      isdisabled: true,
      radio: "1",
      is_retract: true,
      labelPosition: "left",
      formLabelWidth: this.$i18n.locale === 'zh'?"142px":"116px",
      input1: 10,
      add_passage: false,
      rightMenu: "",
      dialogVisible: true,
      menuShow: false,
      trees: [],
      nodekey: "",
      datas2: this.$t('channelconfig.agreement'),
      defaultProps: {
        children: "children",
        label: "label",
      },
      rules: {
        tdpz_tdmc: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_tdmc'), trigger: "change" },
        ],
        tdpz_td: [{ required: true, message: this.$t('channelconfig.rules.tdpz_td'), trigger: "change" }],
        tdpz_qdmc: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_qdmc'), trigger: "change" },
        ],
        tdpz_ip: [
          {
            required: true,
            message: "",
            validator: this.validateIpAddress,
            trigger: "blur",
          },
        ],
        tdpz_port: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_port'), trigger: "blur" },
        ],
        tdpz_cssj: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_cssj'), trigger: "blur" },
        ],
        tdpz_jgsj: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_jgsj'), trigger: "blur" },
        ],
        tdpz_lxsj: [
          { required: true, message: this.$t('channelconfig.rules.tdpz_lxsj'), trigger: "blur" },
        ],
        tdpz_cfcs: [
          { required: true, message:  this.$t('channelconfig.rules.tdpz_cfcs'), trigger: "blur" },
        ],
        tdpz_chuankou: [
          { required: true, message: "请输入串口号", trigger: "blur" },
        ],
        tdpz_btl: [
          { required: true, message: "请输入波特率", trigger: "blur" },
        ],
        tdpz_tzw: [
          { required: true, message: "请输入停止位", trigger: "blur" },
        ],
        tdpz_sjw: [
          { required: true, message: "请输入数据位", trigger: "blur" },
        ],
        tdpz_jojy: [
          { required: true, message: "请输入奇偶校验", trigger: "blur" },
        ],
      },
      // 串口与网口的显隐
      optts1: [
        {
          value: "com1",
          label: "com1",
        },
        {
          value: "com2",
          label: "com2",
        },
        {
          value: "com3",
          label: "com3",
        },
        {
          value: "com4",
          label: "com4",
        },
        {
          value: "com5",
          label: "com5",
        },
        {
          value: "com6",
          label: "com6",
        },
        {
          value: "com7",
          label: "com7",
        },
        {
          value: "com8",
          label: "com8",
        },
        {
          value: "com9",
          label: "com9",
        },
        {
          value: "com10",
          label: "com10",
        },
        {
          value: "com11",
          label: "com11",
        },
        {
          value: "com12",
          label: "com12",
        },
        {
          value: "com13",
          label: "com13",
        },
        {
          value: "com14",
          label: "com14",
        },
        {
          value: "com15",
          label: "com15",
        },
        {
          value: "com16",
          label: "com16",
        },
        {
          value: "com17",
          label: "com17",
        },
        {
          value: "com18",
          label: "com18",
        },
        {
          value: "com19",
          label: "com19",
        },
        {
          value: "com20",
          label: "com20",
        },
        {
          value: "com21",
          label: "com21",
        },
        {
          value: "com22",
          label: "com22",
        },
        {
          value: "com23",
          label: "com23",
        },
        {
          value: "com24",
          label: "com24",
        },
        {
          value: "com25",
          label: "com25",
        },
        {
          value: "com26",
          label: "com26",
        },
        {
          value: "com27",
          label: "com27",
        },
        {
          value: "com28",
          label: "com28",
        },
        {
          value: "com29",
          label: "com29",
        },
        {
          value: "com30",
          label: "com30",
        },
        {
          value: "com31",
          label: "com31",
        },
        {
          value: "com32",
          label: "com32",
        },
        {
          value: "com33",
          label: "com33",
        },
        {
          value: "com34",
          label: "com34",
        },
        {
          value: "com35",
          label: "com35",
        },
        {
          value: "com36",
          label: "com36",
        },
        {
          value: "com37",
          label: "com37",
        },
        {
          value: "com38",
          label: "com38",
        },
        {
          value: "com39",
          label: "com39",
        },
        {
          value: "com40",
          label: "com40",
        },
        {
          value: "com41",
          label: "com41",
        },
        {
          value: "com42",
          label: "com42",
        },
        {
          value: "com43",
          label: "com43",
        },
        {
          value: "com44",
          label: "com44",
        },
        {
          value: "com45",
          label: "com45",
        },
        {
          value: "com46",
          label: "com46",
        },
        {
          value: "com47",
          label: "com47",
        },
        {
          value: "com48",
          label: "com48",
        },
        {
          value: "com49",
          label: "com49",
        },
        {
          value: "com50",
          label: "com50",
        },
      ],
      optts2: [
        {
          value: "1200",
          label: "1200",
        },
        {
          value: "2400",
          label: "2400",
        },
        {
          value: "4800",
          label: "4800",
        },
        {
          value: "9600",
          label: "9600",
        },
        {
          value: "115200",
          label: "115200",
        },
      ],
      optts3: [
        {
          value: "8",
          label: "8",
        },
        {
          value: "7",
          label: "7",
        },
      ],
      optts4: [
        {
          value: "1",
          label: "1",
        },
        {
          value: "2",
          label: "2",
        },
      ],
      optts5: [
        {
          value: "奇校验",
          label: "奇校验",
        },
        {
          value: "偶校验",
          label: "偶校验",
        },
        {
          value: "无校验（none）",
          label: "无校验（none）",
        },
      ],

      // 网关配置的出现
      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: {
    //ip地址验证
    validateIpAddress(rule, value, callback) {
      if (
        this.tdpz_ip1 +
          "." +
          this.tdpz_ip2 +
          "." +
          this.tdpz_ip3 +
          "." +
          this.tdpz_ip4 ===
        "..."
      ) {
        callback(new Error(this.$t('channelconfig.rules.tdpz_ip')));
      } else if (
        !/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
          this.tdpz_ip1 +
            "." +
            this.tdpz_ip2 +
            "." +
            this.tdpz_ip3 +
            "." +
            this.tdpz_ip4
        )
      ) {
        callback(new Error(this.$t('channelconfig.rules.ip2')));
      } else {
        callback();
      }
    },
    // 提交时的校验
    submitForm: _.debounce(function (e) {
      this.$refs["FormData"].validate((valid) => {
        if (valid) {
          this.saveGate();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }, 1000),
    async rightClick(e, data, node) {
      console.log(data);
      // console.log(node);
      if (data.editing) {
        this.outerVisible = true;
        this.add_passage = false;
        this.menuShow = false;
        this.GetUserAnswer();
      }
      if (node.level == 3 && data.label == "I/O点" || node.level == 3 && data.label == "I/O point") {
        this.nodekey = data.id;
        this.menuShow = false;
        this.menuShow = true;
        e.preventDefault(); //关闭浏览器右键默认事件
        this.rightMenu = { top: e.pageY + "px", left: e.pageX + "px" };
        document.addEventListener("click", (ev) => {
          ev.stopImmediatePropagation();
          if (ev.target !== document.querySelector(".el-menu-item.is-active")) {
            this.foo();
          }
        });
      }
    },
    // 点击时候的判断,判断是否为新增网关
    selectMenuNode(index, indexPath) {
      console.log(index);
      if (index == 1) {
        this.add_passage = true;
        this.menuShow = false;
        this.outerVisible = false;
      }
      this.menuShow = false;
    },
    foo() {
      // 取消鼠标监听事件 菜单栏
      this.menuShow = false;
      document.removeEventListener("click", this.foo); // 关掉监听，
    },
    treeNodeClick(key) {
      // console.log
      this.foo();
    },
    // 收起点击事件的判断
    getRetract() {
      if (this.is_retract == true) {
        this.is_retract = false;
      } else {
        this.is_retract = true;
      }
    },
    getDriveName() {
      this.diag_drive = true;
    },
    Merge(value, value1, value2, value3, value4) {
      value = value1 + "." + value2 + "." + value3 + "." + value4;
      return value;
    },
    async saveGate() {
      var obj = {
        tdpz_tdmc: this.FormData.tdpz_tdmc,
        tdpz_td: this.FormData.tdpz_td,
        tdpz_qdmc: this.FormData.tdpz_qdmc,
        tdpz_port: this.FormData.tdpz_port,
        tdpz_cssj: this.FormData.tdpz_cssj,
        tdpz_jgsj: this.FormData.tdpz_jgsj,
        tdpz_ip:
          this.tdpz_ip1 +
          "." +
          this.tdpz_ip2 +
          "." +
          this.tdpz_ip3 +
          "." +
          this.tdpz_ip4,
        tdpz_lxsj: this.FormData.tdpz_lxsj,
        tdpz_cfcs: this.FormData.tdpz_cfcs,
        tdpz_watchtime: String(Number(this.FormData.tdpz_watchtime)),
        tdpz_cjsylxdz: String(Number(this.FormData.tdpz_cjsylxdz)),
        tdpz_dxzkb: this.tdpz_dxzkb1 + ":" + this.tdpz_dxzkb2,
        tdpz_050F: this.FormData.tdpz_050F,
        tdpz_0610: this.FormData.tdpz_0610,
      };
      // let datas = sessionStorage.getItem("DB-IotLite_yx");
      // datas = { ...JSON.parse(datas), ...obj };
      console.log(this.FormData);
      let datas = { ...this.FormData, ...obj };
      console.log(datas,'xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
      let res = await SaveUserAnswer({
        mark: "DB-IotLite_yx",
        // user_id: "USER202307301114011710",
        user_id: this.user_id,
        mark_value: JSON.stringify(datas),
        step: "2",
      });
      console.log(res);
      if (res.data.state) {
        this.$message({
          message: "保存成功",
          type: "success",
        });
        console.log(res.data.data.step);
        // sessionStorage.setItem("DB-IotLite_yx", JSON.stringify(datas));

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

        })
      }
      if (answer.data.data && answer.data.state) {
        let obj = JSON.parse(answer.data.data.mark_value);
        // console.log(obj);
        // this.FormData.
        if (obj.tdpz_dxzkb) {
          this.tdpz_dxzkb1 = obj.tdpz_dxzkb.split(":")[0];
          this.tdpz_dxzkb2 = obj.tdpz_dxzkb.split(":")[1];
          this.FormData.tdpz_dxzkb = obj.tdpz_dxzkb;
        }
        this.FormData.tdpz_watchtime = Boolean(Number(obj.tdpz_watchtime));
        if (obj.tdpz_cjsylxdz) {
          this.FormData.tdpz_cjsylxdz = Boolean(Number(obj.tdpz_cjsylxdz));
        }
        if (obj.tdpz_ip) {
          this.FormData.tdpz_ip = obj.tdpz_ip;
          this.tdpz_ip1 = obj.tdpz_ip.split(".")[0];
          this.tdpz_ip2 = obj.tdpz_ip.split(".")[1];
          this.tdpz_ip3 = obj.tdpz_ip.split(".")[2];
          this.tdpz_ip4 = obj.tdpz_ip.split(".")[3];
        }
        this.FormData.tdpz_tdmc = obj.tdpz_tdmc;
        this.FormData.tdpz_td = obj.tdpz_td;
        this.FormData.tdpz_qdmc = obj.tdpz_qdmc;
        if (obj.tdpz_050F) {
          this.FormData.tdpz_050F = obj.tdpz_050F;
        }
        if (obj.tdpz_0610) {
          this.FormData.tdpz_0610 = obj.tdpz_0610;
        }
        this.FormData.tdpz_port = obj.tdpz_port;
        this.FormData.tdpz_cssj = obj.tdpz_cssj;
        this.FormData.tdpz_jgsj = obj.tdpz_jgsj;
        this.FormData.tdpz_lxsj = obj.tdpz_lxsj;
        this.FormData.tdpz_cfcs = obj.tdpz_cfcs;
        this.FormData.ippz_wangkou = obj.ippz_wangkou;
        this.FormData.ippz_mrwg = obj.ippz_mrwg;
        this.FormData.ippz_ip = obj.ippz_ip;
        this.FormData.ippz_zwym = obj.ippz_zwym;
        this.FormData.ippz_dns_sx = obj.ippz_dns_sx;
        this.FormData.ippz_dns_by = obj.ippz_dns_by;
        this.FormData.wgpz_wgmc = obj.wgpz_wgmc;
        this.FormData.wgpz_wgid = obj.wgpz_wgid;
        this.FormData.wgpz_wglx = obj.wgpz_wglx;
        this.FormData.sbpz_sbid = obj.sbpz_sbid;
        this.FormData.sbpz_sbmc = obj.sbpz_sbmc;
        this.FormData.sbpz_mac = obj.sbpz_mac;
        this.FormData.sbpz_jysb = obj.sbpz_jysb;
        this.FormData.sbpz_jdzxz = obj.sbpz_jdzxz;
        this.FormData.cjdpz_tagid = obj.cjdpz_tagid;
        this.FormData.cjdpz_mc = obj.cjdpz_mc;
        this.FormData.cjdpz_sjq = obj.cjdpz_sjq;
        this.FormData.cjdpz_jcqdz = obj.cjdpz_jcqdz;
        this.FormData.cjdpz_cjsjlx = obj.cjdpz_cjsjlx;
        this.FormData.cjdpz_zjx = obj.cjdpz_zjx;
        this.FormData.cjdpz_dxsx = obj.cjdpz_dxsx;
        this.FormData.cjdpz_beilv = obj.cjdpz_beilv;
        this.FormData.mqtt_qiyong = obj.mqtt_qiyong;
        this.FormData.mqtt_ip = obj.mqtt_ip;
        this.FormData.mqtt_port = obj.mqtt_port;
        this.FormData.mqtt_wgsn = obj.mqtt_wgsn;
        this.FormData.mqtt_sssjfbzt = obj.mqtt_sssjfbzt;
        this.FormData.mqtt_qos = obj.mqtt_qos;
        this.FormData.mqtt_scms = obj.mqtt_scms;
        this.FormData.mqtt_sczq = obj.mqtt_sczq;
        this.FormData.mqtt_sjgl = obj.mqtt_sjgl;
        this.FormData.mqtt_cjd_sbmc = obj.mqtt_cjd_sbmc;
        this.FormData.mqtt_cjd_tagid = obj.mqtt_cjd_tagid;
      }
    },
    async sendTree() {
      let result = await SendTree({
        user_id: this.user_id,
        // user_id: "USER202307301114011710",
        data: JSON.stringify(this.trees),
        type: "1",
      });
      console.log(result);
    },

    //网关配置的信息
    async submitGate() {
      this.$refs["gateWay"].validate((valid) => {
        if (valid) {
          // console.log('submit!');
          this.saveGates();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //

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

        // alert(JSON.stringify(this.trees));
        // console.log(this.$router.query.firstlabel);
        // this.trees[0] = this.$router.query.firstlabel;
      });
    }
    this.loading = true;
    this.GetUserAnswer();
    this.loading = false;
    // let res2 = GetUserAnswer()
  },
  mounted() {
    console.log(this.$route.query.firstlabel);
    // console.log(this.FormData.wgpz_wgid);
    // this.trees[0].label = this.$route.query.firstlabel;
    // this.sendTree();
  },
  watch: {
    "FormData.tdpz_watchtime"(newval) {
      console.log(newval);
      if (newval) {
        this.isdisabled = true;
      } else {
        this.isdisabled = false;
      }
    },
    // "FormData.tdpz_td"(newval) {
    //   console.log(newval);
    //   if (newval =="网口") {
    //     this.isDuan = true;
    //   } else {
    //     this.isDuan = false;
    //   }
    // }
  },
};
</script>

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

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

.tree_rightmenu {
  position: fixed;
  width: 120px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  z-index: 1000;
}
.zh{
  .el-col-12:last-child {
    padding-right: 25px !important;
  }

  .el-col-12:first-child {
    padding-right: 20px !important;
  }
}
.super_parmams {
  display: flex;
  color: #fff !important;
  justify-content: space-between;
  align-items: center;
  width: 668px;

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

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

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

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

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

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

    .el-col-6 {
      height: 40px;
      top: 4px;
      left: 78px;
      position: relative;
      width: 50px;
    }
  }
}
//英文版css
.super {
  .el-col-12:last-child {
    padding-right: 28px !important;
  }

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

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

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

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

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

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

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

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

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

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

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

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

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