<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div id="tunnelinfo">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><h3><i class="el-icon-tickets"/>&nbsp;综合通道信息
          <el-button size="mini" type="primary" round @click="check" style="width: 150px;margin-left: 100px" :loading="btnLonding">查看网卡信息</el-button>
          <el-button size="mini" type="primary" round @click="check1" style="width: 150px;margin-left: 100px" :loading="btnLonding">查看通道对端ip状态</el-button>
          <el-button size="mini" type="primary" round @click="check2" style="width: 150px;margin-left: 100px" :loading="btnLonding">查看通道本机端口状态</el-button>
        </h3>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-card class="box-carde">
      <el-tabs v-model="activeName1">
        <el-tab-pane label="数据交互通道" name="first1" :disabled="btnLonding">
          <!--表格-->
          <vxe-table
            ref="xTable"
            border
            stripe
            row-id="id"
            height="250px"
            align="center"
            :cell-style="cellStyle"
            :expand-config="{expandRowKeys: ['1']}"
            :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
          >
            <vxe-table-column type="seq" width="60"/>
            <vxe-table-column type="expand" width="60">
              <template v-slot:content="{ row, rowIndex }">
                <vxe-form v-if="row.tunnelType==='FILEPARSE'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='IEC104TCPMASTER'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="公共地址位:" label-width="125px">
                        <span>{{ row.publicAddress }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="远端ip:" label-width="125px">
                        <span>{{ row.remoteIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="远端端口:" label-width="125px">
                        <span>{{ row.remotePort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端ip:" label-width="125px">
                        <span>{{ row.remoteSpareIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端端口:" label-width="125px">
                        <span>{{ row.remoteSparePort }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='IEC104TCPSLAVE'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="公共地址位:" label-width="125px">
                        <span>{{ row.publicAddress }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="12">
                      <vxe-form-item title="对端ip:" label-width="125px">
                        <span>{{ row.remotePort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='MODBUSTCPMASTER'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="公共地址位:" label-width="125px">
                        <span>{{ row.publicAddress }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="远端ip:" label-width="125px">
                        <span>{{ row.remoteIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="远端端口:" label-width="125px">
                        <span>{{ row.remotePort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端ip:" label-width="125px">
                        <span>{{ row.remoteSpareIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端端口:" label-width="125px">
                        <span>{{ row.remoteSparePort }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="功能码:" label-width="125px">
                        <span>{{ row.functionCode }}</span>
                      </vxe-form-item>
                    </el-col>
                    <!--<el-col :span="6">
                      <vxe-form-item title="数据类型:" label-width="125px">
                        <span>{{ row.protocolDataType }}</span>
                      </vxe-form-item>
                    </el-col>-->
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='MODBUSTCPSLAVE'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="公共地址位:" label-width="125px">
                        <span>{{ row.publicAddress }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="设备地址:" label-width="125px">
                        <span>{{ row.slaveId }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="功能码:" label-width="125px">
                        <span>{{ row.functionCode }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="12">
                      <vxe-form-item title="对端ip:" label-width="125px">
                        <span>{{ row.remotePort }}</span>
                      </vxe-form-item>
                    </el-col>
                    <!--<el-col :span="6">
                      <vxe-form-item title="数据类型:" label-width="125px">
                        <span>{{ row.protocolDataType }}</span>
                      </vxe-form-item>
                    </el-col>-->
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='MODBUSRTUMASTER' || row.tunnelType==='MODBUSRTUSLAVE'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="串口名称:" label-width="125px">
                        <span>{{ row.serialName }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="波特率:" label-width="125px">
                        <span>{{ row.baudRate }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="功能码:" label-width="125px">
                        <span>{{ row.functionCode }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="设备地址:" label-width="125px">
                        <span>{{ row.slaveId }}</span>
                      </vxe-form-item>
                    </el-col>
                    <!--<el-col :span="6">
                      <vxe-form-item title="数据类型:" label-width="125px">
                        <span>{{ row.protocolDataType }}</span>
                      </vxe-form-item>
                    </el-col>-->
                    <el-col :span="6">
                      <vxe-form-item title="奇偶校验:" label-width="125px">
                        <span>{{ row.parity }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='CDTRTUMASTER' || row.tunnelType==='CDTRTUSLAVE'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="串口名称:" label-width="125px">
                        <span>{{ row.serialName }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="波特率:" label-width="125px">
                        <span>{{ row.baudRate }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="同步字1:" label-width="125px">
                        <span>{{ row.synchronousWord1 }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="同步字2:" label-width="125px">
                        <span>{{ row.synchronousWord2 }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="奇偶校验:" label-width="125px">
                        <span>{{ row.parity }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='TCPSERVERASMODBUSMASTER'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="远端ip:" label-width="125px">
                        <span>{{ row.remoteIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="4">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="功能码:" label-width="125px">
                        <span>{{ row.functionCode }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="设备地址:" label-width="125px">
                        <span>{{ row.slaveId }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
                <vxe-form v-if="row.tunnelType==='TCPCLIENTASMODBUSMASTER'">
                  <el-row>
                    <el-col :span="12">
                      <vxe-form-item title="通道id:" label-width="300px">
                        <span>{{ row.id }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="远端ip:" label-width="125px">
                        <span>{{ row.remoteIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="远端端口:" label-width="125px">
                        <span>{{ row.remotePort }} </span>
                      </vxe-form-item>
                    </el-col>

                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端ip:" label-width="125px">
                        <span>{{ row.remoteSpareIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="备用远端端口:" label-width="125px">
                        <span>{{ row.remoteSparePort }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身ip:" label-width="125px">
                        <span>{{ row.selfIp }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="自身端口:" label-width="125px">
                        <span>{{ row.selfPort }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <vxe-form-item title="功能码:" label-width="125px">
                        <span>{{ row.functionCode }}</span>
                      </vxe-form-item>
                    </el-col>
                    <el-col :span="6">
                      <vxe-form-item title="设备地址:" label-width="125px">
                        <span>{{ row.slaveId }}</span>
                      </vxe-form-item>
                    </el-col>
                  </el-row>
                </vxe-form>
              </template>
            </vxe-table-column>
            <!--   <vxe-table-column field="id" title="通道"></vxe-table-column>-->
            <vxe-table-column field="tunnelName" title="通道名称"/>
            <vxe-table-column field="tunnelType" title="通道类型" :filters="proTypeList" :formatter="formateProType"/>
            <vxe-table-column field="refreshInterval" title="时间间隔(s)"/>
            <vxe-table-column
              field="isEnable"
              title="是否启用通道"
              :filters="options"
              :edit-render="{name: '$select', options: options}"
            />
            <vxe-table-column>
              <template v-slot="{ row }">
                <el-button
                  style="padding: 3px 4px 3px 4px;margin: 2px"
                  size="mini"
                  v-show="row.remoteIp!=null"
                  @click="ping(row.remoteIp)">ping
                </el-button>
                <el-button
                  style="padding: 3px 4px 3px 4px;margin: 2px"
                  size="mini"
                  v-show="row.selfPort!=null"
                  @click="lsof(row.selfPort)">lsof
                </el-button>
              </template>
            </vxe-table-column>
          </vxe-table>
          <vxe-pager
            perfect
            :current-page.sync="currentPage"
            :page-size.sync="pageSize"
            :total="totalResult"
            :layouts="['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
          />
        </el-tab-pane>
      </el-tabs>
    </el-card>


    <el-card class="box-carde">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="上报对象" name="first" :disabled="btnLonding">
          <vxe-table
            align="center"
            :loading="loading"
            ref="xTable"
            auto-resize
            border
            resizable
            highlight-current-row
            show-overflow
            :data="tableData1"
            v-show="showTable"
            :expand-config="{labelField: 'channelNo', expandAll: false}"
          >
            <vxe-table-column field="uploadObjectName" title="上报对象名称"></vxe-table-column>
            <vxe-table-column field="objectNo" title="上报对象编号"></vxe-table-column>
            <vxe-table-column field="uploadFileType" title="上报文件类型"></vxe-table-column>
            <vxe-table-column field="uploadFileCharSetEnum" title="上报文件字符集"></vxe-table-column>
            <vxe-table-column field="uploadProtocolEnum" title="上报协议"></vxe-table-column>
            <vxe-table-column field="uploadD5000" title="上报嘉越D5000"
                              :formatter="formateuploadD5000"></vxe-table-column>
            <vxe-table-column field="uploadObjectRemarks" title="上报对象备注"></vxe-table-column>
          </vxe-table>
        </el-tab-pane>
        <el-tab-pane label="通道配置" name="secend" :disabled="btnLonding">
          <vxe-table
            align="center"
            :loading="loading"
            ref="sTable"
            auto-resize
            border
            resizable
            highlight-current-row
            show-overflow
            :data="channelData"
            v-show="showTable"
          >
            <vxe-table-column type="expand" title="查看更多" width="8%">
              <template v-slot:content="{ row, rowIndex }">
                <table style="width: 100%;text-align: left"
                       v-show="row.uploadObjectId.uploadProtocolEnum == '102服务端' || row.uploadObjectId.uploadProtocolEnum == '102山东客户端' || row.uploadObjectId.uploadProtocolEnum == '102山东服务端'||row.uploadObjectId.uploadProtocolEnum == '102浙江客户端'">
                  <tr>
                    <td>本地IP：{{ row.localIp }}</td>
                    <td>本地端口：{{ row.localPort }}</td>
                    <td>名称长度：{{ row.uploadFileNameLengthEnum }}</td>
                  </tr>
                  <tr>
                    <td>远端IP：{{ row.remoteIp }}</td>
                    <td>远端端口：{{ row.remotePort }}</td>
                    <td>单次传输字节：{{ row.uploadFileSingleByteEnum }}</td>
                  </tr>
                </table>
                <table style="width: 100%;text-align: left;" v-show="row.uploadObjectId.uploadProtocolEnum=='ftp'">
                  <tr>
                    <td>远端IP：{{ row.remoteIp }}</td>
                    <td>远端端口：{{ row.remotePort }}</td>
                    <td v-if="row.backupC!=1">服务端路径：{{ row.pathService }}</td>
                  </tr>
                  <tr>
                    <td>用户名：{{ row.uploadUserName }}</td>
                    <td>密码：{{ row.uploadPassword }}</td>
                    <td>FTP模式：{{ row.ftpPassiveModeEnum }}</td>
                  </tr>

                  <tr v-if="row.backupC==1" v-for="item in row.backupA">
                    <td>{{ item.label }}：{{ item.url }}</td>
                  </tr>

                </table>
                <table style="width: 100%;text-align: left" v-show="row.uploadObjectId.uploadProtocolEnum=='sftp'">
                  <tr>
                    <td>远端IP：{{ row.remoteIp }}</td>
                    <td>远端端口：{{ row.remotePort }}</td>
                    <td>用户名：{{ row.uploadUserName }}</td>
                    <!--<td>FTP模式：{{row.ftpPassiveModeEnum}}</td>-->
                  </tr>
                  <tr>
                    <td>sftp上报方式：{{ row.sftpConnectModeEnum == 'E1' ? "密码连接" : "密钥连接" }}</td>
                    <td v-if="row.backupC!=1">服务端路径：{{ row.pathService }}</td>
                    <!--<td>FTP/SFTP密码：{{row.uploadPassword}}</td>-->
                  </tr>
                  <tr v-if="row.backupC==1" v-for="item in row.backupA">
                    <td>{{ item.label }}：{{ item.url }}</td>
                  </tr>
                  <tr>
                    <td v-show="row.sftpConnectModeEnum == 'E1'">密码：{{ row.uploadPassword }}</td>
                    <td v-show="row.sftpConnectModeEnum == 'E2'">SFTP秘钥路径：{{ row.keyFilePath }}</td>
                    <td v-show="row.sftpConnectModeEnum == 'E2'">SFPT秘钥密码：{{ row.passPhrase }}</td>
                  </tr>
                </table>
              </template>
            </vxe-table-column>
            <vxe-table-column field="uploadObjectId.uploadObjectName" title="上报对象"></vxe-table-column>
            <vxe-table-column field="channelName" title="通道名称"></vxe-table-column>
            <vxe-table-column field="channelStatusEnum" title="通道状态" :formatter="formatechannelStatusEnum"
                              width="200px"></vxe-table-column>
            <vxe-table-column field="channelRemarks" title="通道备注"></vxe-table-column>
            <vxe-table-column>
              <template v-slot="{ row }">
                <el-button
                  style="padding: 3px 4px 3px 4px;margin: 2px"
                  size="mini"
                  v-show="row.remoteIp!=null"
                  @click="ping(row.remoteIp)">ping
                </el-button>
                <el-button
                  style="padding: 3px 4px 3px 4px;margin: 2px"
                  size="mini"
                  v-show="row.localPort!=null"
                  @click="lsof(row.localPort)">lsof
                </el-button>
              </template>
            </vxe-table-column>
          </vxe-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <div>
      <el-dialog :visible.sync="visible" :close-on-click-modal='false' :before-close="closeDialog" width="70%">
        <fieldset>
          <legend>自检信息报告</legend>
          <div v-for="item in ipData">
            {{item}}
          </div>
        </fieldset>
      </el-dialog>

      <el-dialog :visible.sync="visible1" :close-on-click-modal='false' :before-close="closeDialog1" width="70%">
        <fieldset>
          <legend>自检信息报告</legend>
          <div v-for="item in pingData">
            {{item}}
          </div>
        </fieldset>
      </el-dialog>

      <el-dialog :visible.sync="visible2" :close-on-click-modal='false' :before-close="closeDialog2" width="70%">
        <fieldset>
          <legend>自检信息报告</legend>
          <div v-for="item in lsofData">
            {{item}}
          </div>
        </fieldset>
      </el-dialog>
    </div>
  </div>




</template>

<script>
import enumerations from '../enumeration'

export default {
  data() {
    return {
      activeName1: 'first1',
      disabled: false,
      tableLoading: false,
      typeTableData1a: [],
      tunnelType: '',
      proType: '',
      // 后台传入场站数据
      elTableData: [],
      StartEndTime: [],
      typeTable: [],
      checkFlag: 0,
      // 防止重复提交
      isDisabled: false,
      // 后台传入数据
      tableData: [],
      keywords: '',
      protocol: [],
      linuxDev: [],
      errorstr: '',
      filetype: '',
      currentid: 1,
      // 分页
      currentPage: 1,
      pageSize: 10,
      totalResult: 0,
      modiId: '',
      visible: false,
      visible1: false,
      visible2: false,
      // 数据下标
      idx: -1,
      proIndex: '',
      // 下拉框数据
      enums: enumerations,
      options: [
        {value: false, label: '停用中'},
        {value: true, label: '使用中'}
      ],
      tunnelTypeList: [{value: 'Master', label: '数据接入'}, {value: 'Slave', label: '数据上送'}],
      proTypeOptions: [],
      proBaudrateOptions: [
        {value: 300, label: 'B300'},
        {value: 600, label: 'B600'},
        {value: 1200, label: 'B1200'},
        {value: 1800, label: 'B1800'},
        {value: 2400, label: 'B2400'},
        {value: 4800, label: 'B4800'},
        {value: 9600, label: 'B9600'},
        {value: 19200, label: 'B19200'},
        {value: 38400, label: 'B38400'},
        {value: 57600, label: 'B57600'},
        {value: 115200, label: 'B115200'}
      ],
      proTypeList: [
        {value: 'IEC104TCPMASTER', label: '采集104tcp'},
        {value: 'IEC104TCPSLAVE', label: '转发104tcp'},
        {value: 'MODBUSTCPMASTER', label: '采集modbustcp'},
        {value: 'MODBUSTCPSLAVE', label: '转发modbustcp'},
        {value: 'MODBUSRTUMASTER', label: '采集modbusRtu'},
        {value: 'MODBUSRTUSLAVE', label: '转发modbusRtu'},
        {value: 'CDTRTUMASTER', label: '采集cdtRtu'},
        {value: 'CDTRTUSLAVE', label: '转发cdtRtu'},
        { value: 'TCPSERVERASMODBUSMASTER', label: 'TCPServerAsModBus' },
        { value: 'TCPCLIENTASMODBUSMASTER', label: 'TCPClientAsModBus' },
        {value: 'FILEPARSE', label: '隔离文件解析'}
      ],
      parityOptions: [
        {value: 0, label: '无校验'},
        {value: 1, label: '奇校验'},
        {value: 2, label: '偶校验'},
        {value: 3, label: '0校验'},
        {value: 4, label: '1校验'}],
      functionCodeOptions: [
        {value: 1, label: '1'},
        {value: 2, label: '2'},
        {value: 3, label: '3'},
        {value: 4, label: '4'}],
      proProgramOptions: [],
      serialPortsList: [],
      proProgramList: [],


      disabledBtn: false,
      activeName: 'first',
      type: '',
      objectId: '',
      loading: false,
      channelId: '',
      channelData: [],
      add: true,
      showTable: true,
      btnLonding: false,
      tableData1: [],
      form: {},
      uploadFileTypeList: [],
      channelFileRuleEnumList: [],
      channelStatusEnumList: [],
      uploadProtocolEnumList: [],
      uploadFileCharSetEnumList: [],
      uploadFileNameLengthEnumList: [],
      uploadFileSingleByteEnumList: [],
      ftpPassiveModeEnumList: [],
      sftpsaveForm: [],
      ftpsaveForm: [],
      sftpConnectModeEnum: [{value: 'E1', label: '密码连接'}, {value: 'E2', label: '密钥连接'}],
      uploadD5000List: [{value: '0', label: '否'}, {value: '1', label: '是'}],
      isMoreURL: [{value: null, label: '否'}, {value: '1', label: '是'}],
      fileTypeListForUrl: [],

      ipData:[],
      lsofData:[],
      pingData:[],
      i:0
    }
  },
  mounted() {
    this.getData()
    this.getEl()
    this.getSerialPorts()
    this.get()
  },
  methods: {
    getData() {
      this.$axios.get('/TunnelInfo/getAllTunnel').then(res => {
        this.tableData = res.data
        this.totalResult = this.tableData.length
        this.currentPage = 1
      })
    },
    getSerialPorts() {
      this.$axios.get('/TunnelInfo/getServerSerialPorts/').then(res => {
        if (res.code === 0) {
          this.serialPortsList = res.data
          for (var i = 0; i < this.serialPortsList.length; i++) {
            if (this.serialPortsList[i].substring(0, 3) === 'tty') {
              this.serialPortsList[i] = '/dev/' + this.serialPortsList[i]
            }
          }
        }
      })
    },
    getEl() {
      this.$axios.get('/electricField/').then(res => {
        this.elTableData.push(res.data)
        this.form.efiId = this.elTableData[0].stationCode
        this.ef = this.elTableData[0].stationCode
      })
    },
    handleDialogClose() {
      if (this.addVisible === true) {
        this.cancelForm('form')
      }
      this.addVisible = false
      this.getData()
    },
    cellStyle({row, column}) {
      if (column.property === 'isEnable') {
        if (row.isEnable) {
          return {
            color: '#168822'
          }
        } else {
          return {
            color: '#881513'
          }
        }
      }
    },
    // 设备id转名称
    formateProType({cellValue}) {
      const item = this.proTypeList.find(item => item.value === cellValue)
      return item ? item.label : ''
    },
    /**
     * 关闭对话框的回调
     **/
    cancelForm(formName) {
      this.resetForm(formName)
      this.addVisible = false
      this.getData()
      this.getEl()
    },


    get() {
      Promise.all([this.getChannelStatusEnum(), this.getUploadProtocolEnum(), this.getUploadFileCharSetEnum(), this.getUploadFileNameLengthEnum(), this.getUploadFileSingleByteEnum(), this.getFtpPassiveModeEnum(), this.getChannelFileRuleEnum(), this.getFileType()]).then((results) => {
        this.disabledBtn = false
        this.loading = true
        this.channelStatusEnumList = results[0]
        // this.form.channelStatusEnum = this.channelStatusEnumList[0].value
        this.uploadProtocolEnumList = results[1]
        this.uploadFileCharSetEnumList = results[2]
        this.uploadFileNameLengthEnumList = results[3]
        this.uploadFileSingleByteEnumList = results[4]
        this.ftpPassiveModeEnumList = results[5]
        this.channelFileRuleEnumList = results[6]
        this.uploadFileTypeList = results[7]
        this.getAll()
      })
    },
    handleClick(tab, event) {
      // console.log(tab.name);
      if (tab.name === 'secend') {
        this.getAllChannel()
      } else {
        this.getAll()
      }
    },
    getAllChannel() {
      this.$axios.get("/uploadFileChannel/").then(res => {
        this.channelData = res.data
        for (let i = 0; i < this.channelData.length; i++) {

          /*for (let j = 0; j < this.channelStatusEnumList.length; j++) {
            if (this.channelData[i].channelStatusEnum == this.channelStatusEnumList[j]["value"]) {
              this.channelData[i].channelStatusEnum = this.channelStatusEnumList[j]["label"]
            }
          }*/
          for (let j = 0; j < this.uploadFileNameLengthEnumList.length; j++) {
            if (this.channelData[i].uploadFileNameLengthEnum == this.uploadFileNameLengthEnumList[j]["value"]) {
              this.channelData[i].uploadFileNameLengthEnum = this.uploadFileNameLengthEnumList[j]["label"]
            }
          }

          for (let j = 0; j < this.uploadFileSingleByteEnumList.length; j++) {
            if (this.channelData[i].uploadFileSingleByteEnum == this.uploadFileSingleByteEnumList[j]["value"]) {
              this.channelData[i].uploadFileSingleByteEnum = this.uploadFileSingleByteEnumList[j]["label"]
            }
          }
          for (let j = 0; j < this.ftpPassiveModeEnumList.length; j++) {
            if (this.channelData[i].ftpPassiveModeEnum == this.ftpPassiveModeEnumList[j]["value"]) {
              this.channelData[i].ftpPassiveModeEnum = this.ftpPassiveModeEnumList[j]["label"]
            }
          }
          for (let j = 0; j < this.channelFileRuleEnumList.length; j++) {
            if (this.channelData[i].channelFileRuleEnum == this.channelFileRuleEnumList[j]["value"]) {
              this.channelData[i].channelFileRuleEnum = this.channelFileRuleEnumList[j]["label"]
            }
          }
          for (let j = 0; j < this.tableData1.length; j++) {
            if (this.channelData[i].uploadObjectId == this.tableData1[j].id) {
              this.channelData[i].uploadObjectId = this.tableData1[j]
            }
          }

          if (this.channelData[i].uploadObjectId.uploadProtocolEnum == "ftp" || this.channelData[i].uploadObjectId.uploadProtocolEnum == "sftp") {
            let data1 = []
            this.$axios.get("/uploadURL/" + this.channelData[i].id).then(res => {
              for (let x = 0; x < this.tableData1.length; x++) {
                if (this.tableData1[x].id == this.channelData[i].uploadObjectId.id) {
                  var data = this.tableData1[x].uploadFileType.split(",")
                  for (let n = 0; n < data.length; n++) {
                    for (let j = 0; j < this.uploadFileTypeList.length; j++) {
                      if (data[n] == this.uploadFileTypeList[j]["label"]) {
                        var data2 = {
                          label: this.uploadFileTypeList[j]["label"] + "路径:",
                          value: this.uploadFileTypeList[j]["value"],
                          url: ""
                        }
                        for (let y = 0; y < res.data.length; y++) {

                          if (res.data[y].fileTypeEnum == this.uploadFileTypeList[j]["value"]) {
                            data2.url = res.data[y].uploadURL
                          }
                        }
                        data1.push(data2)
                      }
                    }
                  }
                }
              }
            })
            this.channelData[i].backupA = data1
          }
        }
        //console.log("获取通道信息成功")
      }).catch(error => {
        this.$message.error('获取通道信息出错' + error)
      })
    },
    getAll() {
      this.$axios.get("/uploadObject/").then(res => {
        this.tableData1 = res.data
        // console.log(this.tableData1)
        this.loading = false
        for (let i = 0; i < this.tableData1.length; i++) {
          //添加编辑标识
          this.$set(this.tableData1, 'edit', false)
          //添加省调枚举标识转换
          for (let j = 0; j < this.uploadProtocolEnumList.length; j++) {
            if (this.tableData1[i].uploadProtocolEnum == this.uploadProtocolEnumList[j]["value"]) {
              this.tableData1[i].uploadProtocolEnum = this.uploadProtocolEnumList[j]["label"]
            }
          }
          for (let j = 0; j < this.uploadFileCharSetEnumList.length; j++) {
            if (this.tableData1[i].uploadFileCharSetEnum == this.uploadFileCharSetEnumList[j]["value"]) {
              this.tableData1[i].uploadFileCharSetEnum = this.uploadFileCharSetEnumList[j]["label"]
            }
          }
          const data = this.tableData1[i].uploadFileType.split(",");
          let data1 = "";
          for (let n = 0; n < data.length; n++) {
            for (let j = 0; j < this.uploadFileTypeList.length; j++) {
              if (data[n] == this.uploadFileTypeList[j]["value"]) {
                data1 = data1 + this.uploadFileTypeList[j]["label"] + ","
              }
            }
          }
          data1 = data1.substr(0, data1.length - 1)
          this.tableData1[i].uploadFileType = data1
          this.getAllChannel()
        }
        // console.log("获取通道对象信息成功")
      }).catch(error => {
        this.$message.error('获取通道对象信息出错' + error)
      })
    },
    getChannelStatusEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getChannelStatusEnum").then(res => {
          resolve(res.data)
          // console.log("获取通道状态枚举类型成功")
        }).catch((error) => {
          this.$message.error('获取通道状态枚举类型出错' + error)
        })

      });
    },
    getUploadProtocolEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getUploadProtocolEnum").then(res => {
          resolve(res.data)
          // console.log("获取上报协议枚举类型成功")
        }).catch((error) => {
          this.$message.error('获取上报协议枚举类型出错' + error)
        })
      });
    },
    getUploadFileCharSetEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getUploadFileCharSetEnum").then(res => {
          resolve(res.data)
          // console.log("获取上报文件字符集类型成功")
        }).catch((error) => {
          this.$message.error('获取上报文件字符集类型出错' + error)
        })
      });
    },
    getUploadFileNameLengthEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getUploadFileNameLengthEnum").then(res => {
          resolve(res.data)
          // console.log("获取上报文件名称长度枚举类型成功")
        }).catch((error) => {
          this.$message.error('获取上报文件名称长度枚举出错' + error)
        })
      });
    },
    getUploadFileSingleByteEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getUploadFileSingleByteEnum").then(res => {
          resolve(res.data)
          // console.log("获取上报文件单次传输字节枚举类型成功")
        }).catch((error) => {
          this.$message.error('获取上报文件单次传输字节枚举类型出错' + error)
        })
      });
    },
    getFtpPassiveModeEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getFtpPassiveModeEnum").then(res => {
          resolve(res.data)
          // console.log("获取ftp模式成功")
        }).catch((error) => {
          this.$message.error('获取ftp模式出错' + error)
        })
      });
    },
    getChannelFileRuleEnum() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadFileChannel/getChannelFileRuleEnum").then(res => {
          resolve(res.data)
          // console.log("获取ftp模式成功")
        }).catch((error) => {
          this.$message.error('获取ftp模式出错' + error)
        })
      });
    },
    getFileType() {
      const a = this.$axios
      return new Promise(function (resolve, reject) {
        a.get("/uploadObject/getFileTypeByProvince").then(res => {
          resolve(res.data)
          // console.log("获取上报文件类型成功")
        }).catch((error) => {
          this.$message.error('获取上报文件类型出错' + error)
        })
      });
    },
    getUploadFileType() {
      return this.form.uploadFileType

    },
    //转换通道状态
    formatechannelStatusEnum({cellValue}) {
      const item = this.channelStatusEnumList.find(item => item.value === cellValue)
      return item ? item.label : ''
    },
    //转上报D5000
    formateuploadD5000({cellValue}) {
      const item = this.uploadD5000List.find(item => item.value === cellValue)
      return item ? item.label : ''
    },
    check(){
      this.visible = true
      this.ipData = ["查询本地网卡状态中","。。。。。。。"]
      this.$axios.get("/inspectionReport/getIp").then(res=>{
        this.ipData = res.data
      })
    },
    check1(){
      this.visible1 = true
      this.pingData = ["ping 数据交互对方ip","------------------"]
      this.ping1(0)


      // this.i = 0
      // this.pingData.push("继续。。。")
      // this.ping2()
      // this.pingData.push("完毕！！！")
    },
    ping1(i){
      if (this.tableData.length>i){
        if(this.tableData[i].remoteIp!=undefined&&this.tableData[i].remoteIp!=null){
          this.$axios.get("/inspectionReport/getPing/"+this.tableData[i].remoteIp).then(res=>{
            if(res.data!=null){
              this.pingData.push("["+this.tableData[i].tunnelName+"]：")
              for(let j = 0;j<res.data.length;j++){
                this.pingData.push(res.data[j])
              }
              this.pingData.push("...")
              i++
              this.ping1(i)
            }
          })
        }else {
          i++
          this.ping1(i)
        }
      }else{
        this.pingData.push("ping 数据交互结束！！！")
        this.pingData.push("------------------")
        this.pingData.push("------------------")
        this.pingData.push("ping 上报交互ip中")
        this.pingData.push("------------------")
        this.ping2(0)
      }
    },
    ping2(i){
      if (this.channelData.length>i+1){
        if(this.channelData[i].remoteIp!=undefined&&this.channelData[i].remoteIp!=null){
          this.$axios.get("/inspectionReport/getPing/"+this.channelData[i].remoteIp).then(res=>{
            this.pingData.push("["+this.channelData[i].channelName+"]：")
            if(res.data!=null) {
              for(let j = 0;j<res.data.length;j++){
                this.pingData.push(res.data[j])
              }
              this.pingData.push("...")
              i++
              this.ping2(i)
            }
          })
        }else {
          i++
          this.ping2(i)
        }
      }else{
        this.pingData.push("ping 上报交互结束！！！")
        return
      }
    },
    check2(){

      this.visible2 = true
      this.lsofData = ["检查数据交互本地ip","------------------"]
      this.lsof1(0)


      // this.i = 0
      // this.pingData.push("继续。。。")
      // this.ping2()
      // this.pingData.push("完毕！！！")
    },
    lsof1(i){
      if (this.tableData.length>i){
        if(this.tableData[i].selfPort!=undefined&&this.tableData[i].selfPort!=null){
          this.$axios.get("/inspectionReport/getLsof/"+this.tableData[i].selfPort).then(res=>{
            if(res.data!=null){
              this.lsofData.push("["+this.tableData[i].tunnelName+"]：")
              for(let j = 0;j<res.data.length;j++){
                this.lsofData.push(res.data[j])
              }
              this.lsofData.push("...")
              i++
              this.lsof1(i)
            }
          })
        }else {
          i++
          this.lsof1(i)
        }
      }else{
        this.lsofData.push("检查数据交互本地ip结束！！！")
        this.lsofData.push("------------------")
        this.lsofData.push("------------------")
        this.lsofData.push("检查上报交互本地ip中")
        this.lsofData.push("------------------")
        this.lsof2(0)
      }
    },
    lsof2(i){
      if (this.channelData.length>i+1){
        if(this.channelData[i].localPort!=undefined&&this.channelData[i].localPort!=null){
          this.$axios.get("/inspectionReport/getLsof/"+this.channelData[i].localPort).then(res=>{
            this.lsofData.push("["+this.channelData[i].channelName+"]：")
            if(res.data!=null) {
              for(let j = 0;j<res.data.length;j++){
                this.lsofData.push(res.data[j])
              }
              this.lsofData.push("...")
              i++
              this.lsof2(i)
            }
          })
        }else {
          i++
          this.lsof2(i)
        }
      }else{
        this.lsofData.push("检查上报交互本地ip结束！！！")
        return
      }
    },
    closeDialog() {
      this.visible = false
      this.ipData = []
    },
    closeDialog1() {
      this.visible1 = false
      this.pingData = []
    },
    closeDialog2() {
      this.visible2 = false
      this.lsofData = []
    },
    ping(ip){
      this.visible1 = true
      this.pingData.push("ping 对方ip中。。。")
      this.$axios.get("/inspectionReport/getPing/"+ip).then(res=>{
        if(res.data!=null) {
          for(let j = 0;j<res.data.length;j++){
            this.pingData.push(res.data[j])
          }
          this.pingData.push("结束。。。")
        }
      })
    },
    lsof(port){
      this.visible2 = true
        this.$axios.get("/inspectionReport/getLsof/"+port).then(res=>{
          if(res.data!=null) {
            for(let j = 0;j<res.data.length;j++){
              this.lsofData.push(res.data[j])
            }
          }
        })
    }
  }
}
</script>

<style scoped>
#tunnelinfo {
  padding-left: 20px;
}
</style>
