<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-header height="auto">
        <!-- 通用工具栏 -->
        <div class="header-button-box">
          <el-button size='mini' icon="el-icon-upload2" type="primary"
                     @click="importToExcelInit"
                     v-if="importCommand.visible">
            {{$t("common.importBtn")}}
          </el-button>
          <el-button size='mini' icon="el-icon-download" type="primary" @click="exportToExcelInit">
            {{$t("common.exportBtn")}}
          </el-button>
          <el-button size='mini' icon="el-icon-circle-plus-outline" type="primary"
                     v-if="createAndCopyCommand.visible"
                     @click="createDeviceInit">
            {{$t("common.createBtn")}}
          </el-button>
          <el-button size='mini' icon="el-icon-document" type="primary"
                     v-if="createAndCopyCommand.visible"
                     @click="copyDeviceInit">
            {{$t("common.copyBtn")}}
          </el-button>
          <el-button size='mini' icon="el-icon-edit" type="primary"
                     v-if="updateCommand.visible"
                     @click="updateDeviceInit">{{$t("common.updateBtn")}}
          </el-button>
          <el-button size='mini' icon="el-icon-delete" type="primary"
                     v-if="deleteCommand.visible"
                     @click="deleteDeviceInit">{{$t("common.deleteBtn")}}
          </el-button>
          <el-button size='mini'  icon="el-icon-upload2" type="primary" @click="uploadConfigInit">
            {{$t("DeviceConfigurationManagement.profileUpload")}}
          </el-button>
          <el-button size='mini' icon="el-icon-refresh" type="primary"
                     v-if="downloadConfigToDeviceCommand.visible"
                     @click="updateConfigInit">
            {{$t("DeviceConfigurationManagement.profileUpdate")}}
          </el-button>
          <el-button size='mini' icon="el-icon-document" type="primary"
                     v-if="historyConfigToDeviceCommand.visible"
                     @click="restoryConfigInit">
            {{$t("DeviceConfigurationManagement.profileHistory")}}
          </el-button>
          <el-button size='mini'  icon="el-icon-download"   type="primary" @click="downloadLog">
            {{$t("DeviceConfigurationManagement.downloadLog")}}
          </el-button>
        </div>

        <div class="header-search">
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.nodeName')}}：</label>
            <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="querySelectNetworkName"
                      clearable></el-input>
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.nodeType')}}：</label>
            <el-select clearable size='mini' v-model="querySelectNetworkType"
                       :placeholder="$t('common.placeholderSelect')" autocomplete="off">
              <el-option v-for="item in deviceTypeList"
                         :key="item.deviceTypeKey"
                         :label="item.deviceTypeKey"
                         :value="item.deviceTypeKey"></el-option>
            </el-select>
            <!--<el-input size='mini':placeholder="$t('common.placeholder')" v-model="querySelectNetworkType" clearable></el-input>-->
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.locationKey')}}：</label>
            <el-select clearable size="mini" v-model="querySelectlocationKey"
                       :placeholder="$t('common.placeholderSelect')" autocomplete="off"
                       v-on:change="queryCabinetByConditionForQuery">
              <el-option v-for="item in locationList"
                         :key="item.locationKey"
                         :label="item.locationName"
                         :value="item.locationKey">
              </el-option>
            </el-select>
            <!--<el-input size='mini':placeholder="$t('common.placeholder')" v-model="querySelectlocationKey" clearable></el-input>-->
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.subnetKey') }}：</label>
            <el-select clearable="true" size='mini' v-model="querySelectSubnet" :placeholder="$t('common.placeholderSelect')"  autocomplete="off">
              <el-option v-for="item in subnetList"
                         :key="item.subnetKey"
                         :label="item.subnetName"
                         :value="item.subnetKey">
              </el-option>
            </el-select>
          </div>

          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.cabinetKey')}}：</label>
            <el-select clearable size='mini' v-model="querySelectFrame" :placeholder="$t('common.placeholderSelect')" autocomplete="off"  v-on:input="queryLocationByConditionForQuery">
              <el-option v-for="item in cabinetList"
                         :key="item.cabinetKey"
                         :label="item.cabinetName"
                         :value="item.cabinetKey">
              </el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.railwayAdmin')}}：</label>
            <el-select clearable size='mini' v-model="querySelectAdmin" filterable :placeholder="$t('common.placeholderSelect')" @blur = "selectBlur1" autocomplete="off">
              <el-option v-for="item in railwayAdminList"
                         :key="item.areaKey"
                         :label="item.areaName"
                         :value="item.areaName"></el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.railwayDivision')}}：</label>
            <el-select clearable size='mini' v-model="querySelectDivision" filterable :placeholder="$t('common.placeholderSelect')" @blur = "selectBlur2" autocomplete="off">
              <el-option v-for="item in railwayDivisionList"
                         :key="item.areaKey"
                         :label="item.areaName"
                         :value="item.areaName"></el-option>
            </el-select>
          </div>
          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.nodeStatus')}}：</label>
            <el-select clearable size='mini' v-model="querySelectNetworkStatus"
                       :placeholder="$t('common.placeholderSelect')"
                       autocomplete="off">
              <el-option v-for="item in deviceStatusList"
                         :key="item.key"
                         :label="item.label"
                         :value="item.key">
              </el-option>
            </el-select>
          </div>

          <div class="search-input-box">
            <label>{{ $t('DeviceConfigurationManagement.ipAddress')}}：</label>
            <el-input size='mini' :placeholder="$t('common.placeholder')"
                      v-model="querySelectNetworkAddress" clearable>
            </el-input>
          </div>
          <div class="search-input-box">
            <el-button size='mini' icon="el-icon-search" type="primary" @click="queryDeviceByCondition"
                       v-loading.fullscreen.lock="fullscreenLoading">{{ $t("common.queryBtn")}}
            </el-button>
          </div>
        </div>
      </el-header>

      <el-main class="adapt-height-box">
        <el-table
          :empty-text="$t('common.noData')"
          border
          header-row-class-name="table-header"
          cell-class-name="table-cell"
          class="adapt-height"
          height="auto"
          ref="singleTable"
          :data="deviceList"
          highlight-current-row
          stripe
          tooltip-effect="dark"
          @current-change="handleCurrentChange"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            :selectable='checkboxForMain'
            width="28">
          </el-table-column>
          <!--:selectable='checkboxForMain'-->
          <el-table-column
            prop="uuid"
            :label="$t('DeviceConfigurationManagement.uuid')"
            fixed
            :show-overflow-tooltip="true"
            width="100"
            style="font-size: 10px;">
          </el-table-column>
          <el-table-column
            width="100"
            :show-overflow-tooltip="true"
            prop="hostName"
            fixed
            :label="$t('DeviceConfigurationManagement.nodeName')">
          </el-table-column>
          <el-table-column
            width="100"
            :show-overflow-tooltip="true"
            prop="displayName"
            fixed
            :label="$t('DeviceConfigurationManagement.displayName')">
          </el-table-column>
          <el-table-column
            prop="deviceTypeKey"
            :label="$t('DeviceConfigurationManagement.nodeType')"
            :show-overflow-tooltip="true"
            width="100">
          </el-table-column>
          <el-table-column
            prop="deviceModel"
            :label="$t('DeviceConfigurationManagement.nodeModel')"
            width="100"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="locationKey"
            :label="$t('DeviceConfigurationManagement.locationKey')"
            :show-overflow-tooltip="true"
            width="150"
            :formatter="formatLocationKey">
          </el-table-column>
          <el-table-column
            prop="cabinetKey"
            :label="$t('DeviceConfigurationManagement.cabinetKey')"
            :show-overflow-tooltip="true"
            width="150"
            :formatter="formatCabinetKey">
          </el-table-column>
          <el-table-column
            prop="subnetKey"
            width="150"
            :label="$t('DeviceConfigurationManagement.subnetKey')"
            :show-overflow-tooltip="true"
            :formatter="formatSubnetKey">
          </el-table-column>
          <el-table-column
            prop="railwayAdmin"
            width="150"
            :label="$t('DeviceConfigurationManagement.railwayAdmin')"
            :show-overflow-tooltip="true"
            :formatter="formatRailwayAdmin">
          </el-table-column>
          <el-table-column
            prop="railwayDivision"
            width="150"
            :label="$t('DeviceConfigurationManagement.railwayDivision')"
            :show-overflow-tooltip="true"
            :formatter="formatRailwayDivision">
          </el-table-column>
          <el-table-column
            prop="ipAddress"
            width="130"
            :show-overflow-tooltip="true"
            :label="$t('DeviceConfigurationManagement.ipAddress')">
          </el-table-column>
          <el-table-column
            prop="snmpVersion"
            width="100"
            :label="$t('DeviceConfigurationManagement.snmpVersion')"
            :show-overflow-tooltip="true"
            :formatter="formatsnmpVersion">
          </el-table-column>
          <el-table-column
            width="95"
            prop="snmpPort"
            :label="$t('DeviceConfigurationManagement.snmpPort')"
            :show-overflow-tooltip="true"
            :formatter="formatsnmpPort">
          </el-table-column>
          <el-table-column
            width="100"
            prop="trapPort"
            :label="$t('DeviceConfigurationManagement.trapPort')"
            :show-overflow-tooltip="true"
            :formatter="formattrapPort">
          </el-table-column>
          <el-table-column
            prop="deviceStatus"
            :label="$t('DeviceConfigurationManagement.nodeStatus')"
            :show-overflow-tooltip="true"
            width="100"
            :formatter="formatdeviceStatus">
          </el-table-column>
          <el-table-column
            prop="deviceVersion"
            :show-overflow-tooltip="true"
            width="110"
            :label="$t('DeviceConfigurationManagement.nodeVersion')">
          </el-table-column>
          <el-table-column
            prop="masterNode"
            :show-overflow-tooltip="true"
            width="110"
            :label="$t('DeviceConfigurationManagement.masterNode')"
            :formatter="formatMasterNode">
          </el-table-column>
          <el-table-column
            width="200"
            prop="manageType"
            :label="$t('DeviceConfigurationManagement.manageType')"
            :show-overflow-tooltip="true"
            :formatter="formatManageType">
          </el-table-column>
          <el-table-column
            width="200"
            prop="startTime"
            :label="$t('DeviceConfigurationManagement.startTime')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            width="200"
            prop="configFileName"
            :label="$t('ProfileManagement.configFileName')"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            width="200"
            prop="deviceDesc"
            :label="$t('DeviceConfigurationManagement.nodeDesc')"
            :show-overflow-tooltip="true">
          </el-table-column>


        </el-table>
      </el-main>
    </el-container>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>
</template>

<script>
  import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item.vue"
  import CreateAndCopyDeviceDialog from "@/components/DialogComponents/DiviceDialog/CreateAndCopyDeviceDialog.vue"
  import UpdateDeviceDialog from "@/components/DialogComponents/DiviceDialog/UpdateDeviceDialog.vue"
  import DeleteDialog from "@/components/DialogComponents/DiviceDialog/DeleteDeviceDialog.vue"
  import ImportDeviceDialog from '@/components/DialogComponents/DiviceDialog/ImportDeviceDialog.vue'
  import DeviceService from '@/domain/services/DeviceService.js'
  import SubnetService from '@/domain/services/SubnetService.js'
  import LocationService from '@/domain/services/LocationService.js'
  import CabinetService from '@/domain/services/CabinetService.js'
  import ConfigFileService from '@/domain/services/ConfigFileService.js'
  import CommandExecuteContext from '@/commands/CommandExecuteContext'
  import DeviceCommands from '@/commands/DeviceCommands'
  import RailwayService from '@/domain/services/RailwayService.js'

  import DownloadConfigToDevice from '@/components/DialogComponents/ConfigDialog/DownloadConfigToDevice.vue'
  import HelperUtil from '../../../utils/HelperUtil'
  import {SYSTEM_MODE_TRAD} from '@/utils/constantCollection.js'

  export default {

    components: {
      CommandExecuteContext,
      ElFormItem,
    },
    name: 'DeviceConfigurationManagement',
    data: function () {   //存放 数据

      return {
        // 命令
        commandContext: {},
        updateDeviceShow: false,
        importDeviceShow: false,
        configurationUpdateshow: false,
        deviceList: [],
        cabinetList: [],
        locationList: [],
        subnetList: [],
        deviceTypeList:[],
        railwayAdminList:[],
        railwayList:[],
        railwayDivisionList:[],

        //设备配置更新时传的devicekey
        updateConfigFileKey: null,

        //网元状态下拉菜单
        deviceStatusList: [
          {
            key: '0',
            label: this.$t('DeviceConfigurationManagement.inUse')
          },
          {
            key: '1',
            label: this.$t('DeviceConfigurationManagement.notInUse')
          },
          {
            key: '2',
            label: this.$t('DeviceConfigurationManagement.unplanned')
          },

        ],
        //网元状态表格过滤
        deviceStatusListForTable: [
          {
            key: '0',
            label: this.$t('DeviceConfigurationManagement.inUse')
          },
          {
            key: '1',
            label: this.$t('DeviceConfigurationManagement.notInUse')
          },
          {
            key: '2',
            label: this.$t('DeviceConfigurationManagement.unplanned')
          },
        ],
        valueState: '1',
        //SNMP版本下拉菜单
        deviceSNMPList: [
          {
            key: '0',
            label: 'v1'
          },
          {
            key: '1',
            label: 'v2c'
          },
          {
            key: '3',
            label: 'v3'
          }
        ],
        deviceSNMP: '1',


        //  查询条件变量
        querySelectNetworkName: '',//网元名称"
        querySelectNetworkType: null,//网元类型"
        querySelectIpNetworkSegment: '',//Ip网段"
        querySelectNetworkStatus: null,//网元状态"
        querySelectlocationKey: null,//所属机房"
        querySelectFrame: null,//所属机架
        querySelectSubnet:null,//所属子网"
        querySelectAdmin:null,//所属路局
        querySelectDivision:null,//所属路段
        querySelectNetworkAddress: '',//网元地址

        formLabelWidth: '120px',

        //存创建初始化信息和复制初始化信息，传给子组件用
        createAndCopyInitList: [],
        createAndCopyTitle: '',
        updateInitList: [],
        deleteList: [],
        multipleSelection: [],
      }
    },

    methods: {
      /**
       * @Description  :路局支持下拉和输入
       * @author       ::
       * @date         :
       */
      selectBlur1(e){
        this.querySelectAdmin = e.target.value
      },

      /**
       * @Description  :路段支持下拉和输入
       * @author       ::
       * @date         :
       */
      selectBlur2(e){
        this.querySelectDivision = e.target.value
      },

      /**
       * @Description  :获取全部网元信息
       * @author       ::
       * @date         :
       */
      getAllDeviceInit: function () {
        let _this = this;
        console.log('获取全部网元信息:')
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          _this.deviceList = Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :增删改后调用，重新加载table
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      getAllDevice: function (vue) {
        let _this = this;
        DeviceService.getAllDeviceCollection().then(result => {
          //成功
          vue.deviceList = Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :获取全部网元类型
       * @author       :zyh
       * @date         :2020/1/7
       */
      getAllDeviceType: function() {
        let _this = this;
        DeviceService.getAllDeviceTypeCollection().then(result => {
          _this.deviceTypeList = Object.values(result)
        }).catch(err => {
          _this.InfoTip.errorTip(_this,err)
        })
      },

      //主页未规划设备不支持选中功能的实现
      checkboxForMain(row, rowIndex) {

        if (row.deviceStatus == '1') {
//            tempRow.push(i)
//            console.log(row.deviceStatus+"未禁用")
          return true
        }
        else    if (row.deviceStatus == '0') {
//            tempRow.push(i)
//            console.log(row.deviceStatus+"未禁用")
          return true
        }
        else if (row.deviceStatus == '2') {
//            tempRow.push(i)
//            console.log(row.deviceStatus+"禁用")
          return false
        }
      },

      //获取当前时间
      getCurentTime() {
        //获取当前时间
        var date = new Date()
        var seperator1 = '-'
        var seperator2 = ':'
        var year = date.getFullYear()
        var month = date.getMonth() + 1
        var strDate = date.getDate()
        var hour = date.getHours() + ''
        if (hour.length < 2) {
          hour = '0' + hour
        }
        var minu = date.getMinutes() + ''
        if (minu.length < 2) {
          minu = '0' + minu
        }
        var sec = date.getSeconds() + ''
        if (sec.length < 2) {
          sec = '0' + sec
        }
        var ms = date.getMilliseconds() + ''
        if (ms.length == 1) {
          ms = '00' + ms
        }
        else if (ms.length == 2) {
          ms = '0' + ms
        }
        if (month >= 1 && month <= 9) {
          month = '0' + month
        }
        if (strDate >= 0 && strDate <= 9) {
          strDate = '0' + strDate
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate + ' ' + hour + seperator2 + minu + seperator2 + sec + '.' + ms

        return currentdate
      },

      /**
       * @Description  :主表格多选框改变时，将所选行进行保存
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      /**
       * @Description  ：导入文件
       * @author       : bjh
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2018/12/19 18:39
       */
      importToExcelInit: function () {
        this.importCommand.execute()
      },
      //导出
      /**
       * @Description  :导出文件
       */
      exportToExcelInit: function () {
        //传参
        var selectList = new Array()

        if (this.querySelectNetworkName != '') {
          selectList.push({
            quaryAttribute: 'hostName',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkName,
          })
        }
        if (this.querySelectlocationKey != '' && this.querySelectlocationKey != null) {
          selectList.push({
            quaryAttribute: 'locationKey',
            compareSymbol: 'like',
            compareValue: this.querySelectlocationKey,
          })


        }
        if (this.querySelectSubnet != ''&&this.querySelectSubnet != null) {
          selectList.push({
            quaryAttribute: 'subnetKey',
            compareSymbol: 'like',
            compareValue: this.querySelectSubnet,
          })
        }
        if (this.querySelectNetworkType != null) {
          selectList.push({
            quaryAttribute: 'deviceTypeKey',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkType,
          })
        }
        if (this.querySelectNetworkStatus != null) {
          selectList.push({
            quaryAttribute: 'deviceStatus',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkStatus,
          })
        }
        if (this.querySelectFrame != '' && this.querySelectFrame != null) {
          selectList.push({
            quaryAttribute: 'cabinetKey',
            compareSymbol: 'like',
            compareValue: this.querySelectFrame,
          })
        }
        if (this.querySelectAdmin != '' && this.querySelectAdmin != null) {
          selectList.push({
            quaryAttribute: 'railwayAdmin',
            compareSymbol: 'like',
            compareValue: this.querySelectAdmin,
          })
        }
        if (this.querySelectDivision != '' && this.querySelectDivision != null) {
          selectList.push({
            quaryAttribute: 'railwayDivision',
            compareSymbol: 'like',
            compareValue: this.querySelectDivision,
          })
        }
        if (this.querySelectNetworkAddress != null && this.querySelectNetworkAddress != '') {
          selectList.push({
            quaryAttribute: 'ipAddress',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkAddress,
          })

        }


        let _this = this;
        //打开loading

        let loadingInstance = _this.Loading.openLoading();
        console.log(this.selectList)
        DeviceService.downloadDeviceFile(selectList).then(result => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          //成功
        }).catch(err => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      //创建
      createDeviceInit() {
        console.log("开始")
        this.createAndCopyTitle =  this.$t('DeviceConfigurationManagement.createDeviceInfo');//{{$t('DeviceConfigurationManagement.copyDeviceInfo')"}}
        var currentdate = this.getCurentTime()

        this.createAndCopyInitList = {
          "deviceKey": "",
          "uuid": "",
          "hostName": "",
          "displayName":"",
          "deviceTypeKey": "",
          "deviceModel": "",
          "switchType":'',
          "locationKey": "",
          "cabinetKey": "",
          "subnetKey": "",
          "ipAddress": "",
          "otherIpAddress":"",
          "mac":"",
          "snmpVersion": "1",
          "snmpPort": 161,
          "trapPort": 162,
          "deviceStatus": '1',
          "deviceVersion": "",
          "deviceDesc": "",
          "startTime": currentdate,
          "firmwareKey":"",
          "firmwareFileName":"",
          "railwayAdimin": "",
          "railwayDivision": "",
          "masterNode": "",
          "manageType": "",
          "configFileKey": "",
          "configFileName": "",
          "delFlag": 0,
          "modifyTime": ""
        }

        this.createAndCopyCommand.execute()

      },
      //复制
      copyDeviceInit() {

        this.createAndCopyTitle = this.$t('DeviceConfigurationManagement.copyDeviceInfo');//$t('DeviceConfigurationManagement.createDeviceInfo')

        if (this.multipleSelection.length == 0) {

          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.COPY_SELECT_CODE))

          return
        } else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.COPY_ONLY_ONE_CODE))
          return
        }
        else {
          var currentdate = this.getCurentTime()

          this.createAndCopyInitList = this.multipleSelection[0]
          this.createAndCopyInitList.startTime = currentdate
          this.createAndCopyCommand.execute()
        }
      },
      //修改
      updateDeviceInit() {

        this.updateTitle = "设备信息的修改" //$t('DeviceConfigurationManagement.createDeviceInfo')

        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPDATE_SELECT_CODE))
          return
        } else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPDATE_ONLY_ONE_CODE))
          return
        }
        else {

          this.updateInitList = this.multipleSelection[0]
//          this.updateInitList.deviceType = ""
//          this.updateInitList.deviceModel = ""
//          this.updateInitList.deviceVersion = ""
//          this.updateInitList.startTime = currentdate
          this.updateCommand.execute()
        }
      },

      /**
       * @Description  :上传配置信息初始化
       * @author       :
       * @param        :
       * @date         :
       */
      uploadConfigInit: function () {
        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_AT_LEASE_ONE_CONFIGURATION_FILE_TO_UPLOAD))
          return
        }
        else {
//          上传配置信息
          this.$options.methods.uploadProfile(this)

        }
      },

      /**
       * @Description  :上传配置信息过程
       * @author       :
       * @param        :
       * @date         :
       */
      uploadProfile: function (vue) {
        //开始上传到后台

        var selectList = new Array()
        for (var i = 0; i < vue.multipleSelection.length; i++) {
          selectList[i] = vue.multipleSelection[i]['deviceKey']
          console.log(vue.multipleSelection[i]['deviceKey'])

        }

        let _this = vue;
        //调用函数
        //打开loading
        let loadingInstance = _this.Loading.openLoading();
        ConfigFileService.batchUploadConfigFile(selectList).then(result => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          //成功
          _this.InfoTip.successTip(_this,HelperUtil.getStatusCodeObjectByCode(_this.successCode.OTHERS_CODE))
        }).catch(err => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          //失败
          _this.InfoTip.errorTip(_this,err);

        });


      },

      /**
       * @Description  :第一步：更新配置信息初始化
       * @author       :
       * @param        :
       * @date         :
       */
      updateConfigInit: function () {
        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_AT_LEASE_ONE_DEVICE_TO_UPDATE_CONFIGURATION))
          return
        }
        else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_ONLY_ONE_DEVICE_DATA_TO_UPDATE_THE_CONFIGURATION))

          return
        }
        else {
          this.updateConfigFileKey = this.multipleSelection[0].deviceKey
          this.downloadConfigToDeviceCommand.execute();

        }
      },



      /**
       * @Description  :第一步：恢复配置信息初始化
       * @author       :
       * @param        :
       * @date         :
       */
      restoryConfigInit: function () {
        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_AT_LEASE_ONE_DEVICE_TO_QUERY_CONFIGURATION_HISTORY))
          return
        }
        else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_ONLY_ONE_DEVICE_DATA_FOR_CONFIGURATION_HISTORY_QUERY))
          return
        }
        else {
          this.updateConfigFileKey = this.multipleSelection[0].deviceKey
          this.historyConfigToDeviceCommand.execute();
        }
      },


      //----------------------------------------------过滤--------------------------------------------------
      // /**
      //  * @Description  :过滤locationKey，转为显示lacationName
      //  * @author       :
      //  */
      // formatLocationKey: function (row, column) {
      //
      //
      //   if (this.locationList[row.locationKey] !== undefined) {
      //     return this.locationList[row.locationKey].locationName
      //   }
      //   else {
      //     return row.locationKey
      //   }
      //
      // },



      /**
       * @Description  :过滤locationKey，转为显示lacationName
       * @author       :
       */
      formatCabinetKey: function (row, column) {

        for (var i = 0; i < this.cabinetList.length; i++) {
          if (this.cabinetList[i]['cabinetKey'] == row.cabinetKey) {
            return this.cabinetList[i]['cabinetName']
            break
          }
          else if(this.cabinetList[i]['cabinetName'] == row.cabinetKey){
            return this.cabinetList[i]['cabinetName']
            break
          }
        }
      },


      /**
       * @Description  :过滤locationKey，转为显示lacationName
       * @author       :
       */
      formatLocationKey: function (row, column) {
        for (var i = 0; i < this.locationList.length; i++) {
          if (this.locationList[i]['locationKey'] == row.locationKey) {
            return this.locationList[i]['locationName']
            break
          }
          else if(this.locationList[i]['locationName'] == row.locationKey){
            return this.locationList[i]['locationName']
            break
          }
        }
      },

      /**
       * @Description  :过滤locationKey，转为显示lacationName
       * @author       :
       */
      formatSubnetKey: function (row, column) {
        for (var i = 0; i < this.subnetList.length; i++) {
          if (this.subnetList[i]['subnetKey'] == row.subnetKey) {
            return this.subnetList[i]['subnetName']
            break
          }
        }
      },

      /**
       * @Description  :过滤路局
       * @author       :zyh
       */
      formatRailwayAdmin: function (row,colum){
        for (var i=0; i < this.railwayList.length;i++) {
          if (this.railwayList[i]['areaKey'] == row.railwayAdmin) {
            return this.railwayList[i]['areaName']
            break
          }
          else if(this.railwayList[i]['areaName'] == row.railwayAdmin){
            return this.railwayList[i]['areaName']
            break
          }
          else{
            return row.railwayAdmin
          }
        }
      },

      /**
       * @Description  :过滤路段
       * @author       :zyh
       */
      formatRailwayDivision: function (row,colum){
        for (var i=0; i < this.railwayList.length;i++) {
          if (this.railwayList[i]['areaKey'] == row.railwayDivision) {
            return this.railwayList[i]['areaName']
            break
          }
          else if(this.railwayList[i]['areaName'] == row.railwayDivision){
            return this.railwayList[i]['areaName']
            break
          }
          else{
            return row.railwayDivision
          }
        }
      },

      /**
       * @Description  :deviceStatusKey，转为显示deviceStatusName
       * @author       :
       */
      formatdeviceStatus: function (row, column) {

//        for (var i = 0; i < this.deviceList.length; i++) {
//         for (var j = 0; j < this.deviceStatusListForTable.length; j++) {
//           if (row.deviceStatus == this.deviceStatusListForTable[j]['key']) {
//             return this.deviceStatusListForTable[j]['label']
//           }
//           if (row.deviceStatus == -999) {
//             return ''
//           }
//         }

        let result = row.deviceStatus;
        if (row.deviceStatus === 0){
          result = this.$t('DeviceConfigurationManagement.inUse')
        }
        if (row.deviceStatus === 1){
          result = this.$t('DeviceConfigurationManagement.notInUse')
        }
        if (row.deviceStatus === 2){
          result = this.$t('DeviceConfigurationManagement.unplanned')
        }
        return result
      },

      /**
       * @Description  :
       * @author       :
       */
      formatsnmpPort: function (row, column) {
//        for (var i = 0; i < this.deviceList.length; i++) {
        if (row.snmpPort == -999) {
          return ''

        }
        if (row.snmpPort != -999) {
          return row.snmpPort

        }

//      }
      },
      /**
       * @Description  :
       * @author       :
       */
      formattrapPort: function (row, column) {
//        for (var i = 0; i < this.deviceList.length; i++) {
        if (row.trapPort == -999) {
          return ''

        }
        if (row.trapPort != -999) {
          return row.trapPort

        }

//      }
      },

      /**
       * @Description  :snmpVersionKey，转为显示snmpVersionName
       * @author       :
       */
      formatsnmpVersion: function (row, column) {
//        for (var i = 0; i < this.deviceList.length; i++) {
        for (var j = 0; j < this.deviceSNMPList.length; j++) {
          if (row.snmpVersion == this.deviceSNMPList[j]['key']) {
            return this.deviceSNMPList[j]['label']
          }
//          break
        }

//      }
      },


      /**
       * @Description  :marster节点过滤
       * @author       :
       */
      formatMasterNode: function (row,colum){
        let result = row.masterNode;
        if (row.masterNode === 0){
          result = this.$t('DeviceConfigurationManagement.yes')
        }
        if (row.masterNode === 1){
          result = this.$t('DeviceConfigurationManagement.no')
        }
        return result
      },


      formatManageType:function (row,colum){
        let result = row.manageType;
        if (row.manageType === 0){
          result = this.$t('DeviceConfigurationManagement.SNMP')
        }
        if (row.manageType === 1){
          result = this.$t('DeviceConfigurationManagement.ping')
        }
        if (row.manageType === 2){
          result = this.$t('DeviceConfigurationManagement.byStatus')
        }
        return result
      },


      /**
       * @Description  :条件查询
       * @author       :
       * @param        :
       * @date         :
       */
      queryDeviceByCondition: function () {
        let _this = this;

        var selectList = new Array()
        if (this.querySelectNetworkName != '' && this.querySelectNetworkName != null) {
          selectList.push({
            quaryAttribute: 'hostName',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkName,
          })
        }
        if (this.querySelectlocationKey != '' && this.querySelectlocationKey != null) {
          selectList.push({
            quaryAttribute: 'locationKey',
            compareSymbol: '=',
            compareValue: this.querySelectlocationKey,
          })
        }
        if (this.querySelectSubnet != ''&&this.querySelectSubnet != null) {
          selectList.push({
            quaryAttribute: 'subnetKey',
            compareSymbol: '=',
            compareValue: this.querySelectSubnet,
          })
        }
        if (this.querySelectNetworkType != null && this.querySelectNetworkType != '') {
          selectList.push({
            quaryAttribute: 'deviceTypeKey',
            compareSymbol: '=',
            compareValue: this.querySelectNetworkType,
          })
        }
        if (this.querySelectNetworkStatus != null && this.querySelectNetworkStatus != '') {
          selectList.push({
            quaryAttribute: 'deviceStatus',
            compareSymbol: '=',
            compareValue: this.querySelectNetworkStatus,
          })
        }
        if (this.querySelectFrame != '' && this.querySelectFrame != null) {
          selectList.push({
            quaryAttribute: 'cabinetKey',
            compareSymbol: '=',
            compareValue: this.querySelectFrame,
          })
        }
        if (this.querySelectAdmin != '' && this.querySelectAdmin != null) {
          selectList.push({
            quaryAttribute: 'railwayAdmin',
            compareSymbol: '=',
            compareValue: this.querySelectAdmin,
          })
        }
        if (this.querySelectDivision != '' && this.querySelectDivision != null) {
          selectList.push({
            quaryAttribute: 'railwayDivision',
            compareSymbol: '=',
            compareValue: this.querySelectDivision,
          })
        }

        if (this.querySelectNetworkAddress != null && this.querySelectNetworkAddress != '') {
          selectList.push({
            quaryAttribute: 'ipAddress',
            compareSymbol: 'like',
            compareValue: this.querySelectNetworkAddress,
          })

        }

        console.log(selectList)
        // if (
        //   this.querySelectNetworkName == '' &&
        //     this.querySelectlocationKey == null &&
        //     this.querySelectSubnet == null &&
        //     this.querySelectNetworkType == null &&
        //     this.querySelectNetworkStatus == null &&
        //     this.querySelectFrame == null &&
        //     this.querySelectAdmin == null &&
        //     this.querySelectDivision == null &&
        //     this.querySelectNetworkAddress ==''
        //
        // ) {
        //   this.getAllDevice(this)
        // }
        // else {
          let loadingInstance = _this.Loading.openLoading();
          DeviceService.conditionQueryDevice(selectList).then(result => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance)
            //成功
            _this.deviceList =  Object.values(result)
            if(_this.deviceList.length === 0){
              _this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))

            }else{
              _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.QUERY_CODE));
            }

          }).catch(err => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance)
            //失败
            _this.InfoTip.errorTip(_this,err);
          })

        // }

      },


      //删除
      deleteDeviceInit() {

        if (this.multipleSelection.length == 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.DELETE_SELECT_CODE))
          return
        } else {

          this.deleteList = new Array()
          for (var i = 0; i < this.multipleSelection.length; i++) {
            // this.deleteList [i] = this.multipleSelection[i]['deviceKey']
            var obj = {'deviceKey': this.multipleSelection[i]['deviceKey']}
            this.deleteList.push(obj)

          }
          this.deleteCommand.execute();
        }
      },

      /***
       * @Description  : 下载日志
       * @author       :
       * @date         :
       */
      downloadLog: function () {
        let _this = this;
        if (this.multipleSelection.length === 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_ONE_RECORD_TO_DOWNLOAD))
          return
        } else if (this.multipleSelection.length > 1) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_ONLY_ONE_RECORD_TO_DOWNLOAD))

          return
        } else {
          //打开loaing
          let loadingInstance = this.Loading.openLoading();
          DeviceService.downloadDeviceLog(this.multipleSelection[0]["deviceKey"]).then(result => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance)
            //成功
            _this.InfoTip.successTip(_this,HelperUtil.getStatusCodeObjectByCode(_this.successCode.OTHERS_CODE))
          }).catch(err => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance)
            //失败
            _this.InfoTip.errorTip(_this,err);
          })
        }
      },


      //-------------------初始化获取网元类型路局路段子网机房机架---------------------------

      /**
       * @Description  :获取全部机房信息，
       * @author       :
       * @date         : 2018/12/13
       */
      getAllLocation: function () {
        console.log('获取全部机房信息:')
        let _this = this;
        //就这句没改
        LocationService.getAllLocationCollection().then(result => {
          //成功
          _this.locationList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :获取全部路局路段信息，
       * @author       :zyh
       * @date         :2020/1/7
       */
      getAllRailway:function() {
        let _this = this;
        RailwayService.getAllRailwayCollection().then(result =>{
          _this.railwayList = Object.values(result)
          for (var i = 0; i < this.railwayList.length; i++) {
            if (this.railwayList[i]['areaType'] === 0 ) {
              _this.railwayAdminList.push(this.railwayList[i])
            }else{
              _this.railwayDivisionList.push(this.railwayList[i])
            }
          }
        }).catch(err => {
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :获取全部子网信息，
       * @author       :
       * @date         : 2018/12/13
       */
      getAllSubnet() {
        let _this = this;
        SubnetService.getAllSubnetCollection().then(result => {
          //成功
          _this.subnetList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },


      /**
       * @Description  :获取全部机架信息
       * @author       :
       * @date         : 2018/12/13
       */
      getAllCabinet() {
        let _this = this;
        //就这句没改
        CabinetService.getAllCabinetCollection().then(result => {
          //成功
          _this.cabinetList =  Object.values(result)
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })

      },
      //methods的大括号

      /**
       * @Description  :由机房转入设备（已调通）
       * @author       : ly
       * @date         : 2018/12/21 20:55
       */
      TurnFromLocation: function (msg) {
        let _this = this;
        var selectList = new Array()
        selectList.push({
          quaryAttribute: 'locationKey',
          compareSymbol: 'like',
          compareValue: msg,
        })
        //按条件查询
        DeviceService.conditionQueryDevice(selectList).then(result => {
          //成功
          _this.deviceList =  Object.values(result)
          if(_this.deviceList.length === 0){
            _this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
          }

        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :由机架转入设备（已调通）
       * @author       : ly
       * @date         : 2018/12/21 20:10
       */
      TurnFromCabinet: function (msg) {
        let _this = this;
        var selectList = new Array()
        selectList.push({
          quaryAttribute: 'cabinetKey',
          compareSymbol: 'like',
          compareValue: msg,
        })
        //按条件查询
        DeviceService.conditionQueryDevice(selectList).then(result => {
          //成功
          _this.deviceList =  Object.values(result)
          if(_this.deviceList.length === 0){
            _this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
          }

        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      /**
       * @Description  :由子网转入设备
       * @author       : bjh
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2018/12/22 13:55
       */
      TurnFromSubnet: function (msg) {
        let _this = this;
        var selectList = new Array()
        selectList.push({
          quaryAttribute: 'subnetKey',
          compareSymbol: 'like',
          compareValue: msg,
        })
        //按条件查询
        DeviceService.conditionQueryDevice(selectList).then(result => {
          //成功
          _this.deviceList =  Object.values(result)

          if(_this.deviceList.length === 0){
            _this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.QUERY_NULL_CODE))
          }
        }).catch(err => {
          //失败
          _this.InfoTip.errorTip(_this,err);
        })
      },

      clear:function(){
        this.querySelectNetworkName = ''
        this.querySelectlocationKey = null
        this.querySelectSubnet = null
        this.querySelectNetworkType = null
        this.querySelectNetworkStatus = null
        this.querySelectFrame = null
        this.querySelectAdmin == null
        this.querySelectDivision == null
        this.querySelectNetworkAddress=''
      }
    },
    //初始化函数，加载数据
    created: function () {
      //判断是否由机房、机架页面转入，是的话初始化执行条件查询，否则查询所有设备
      if (this.$route.query.locationKey != null) {
        this.querySelectlocationKey = this.$route.query.locationKey;
        this.TurnFromLocation(this.$route.query.locationKey)
      }
      if (this.$route.query.cabinetKey != null) {
        this.querySelectlocationKey = this.$route.query.locationFromCabinet;
        this.querySelectFrame = this.$route.query.cabinetKey;
        this.TurnFromCabinet(this.$route.query.cabinetKey)
      }
      if (this.$route.query.subnetKey != null) {
        this.querySelectSubnet = this.$route.query.subnetKey;
        this.TurnFromSubnet(this.$route.query.subnetKey)
      }
      if (this.$route.query.locationKey == null && this.$route.query.cabinetKey == null && this.$route.query.subnetKey == null) {
        //获取所有设备信息
        this.getAllDeviceInit()
      }
      //this.getAllDeviceInit()
      this.getAllSubnet();
      this.getAllDeviceType();
      this.getAllCabinet();
      this.getAllLocation();
      this.getAllRailway();

      if(this.$store.state.systemMode == SYSTEM_MODE_TRAD){
        this. deviceStatusList= [
          {
            key: '0',
            label: this.$t('DeviceConfigurationManagement.inUse')
          },
          {
            key: '1',
            label: this.$t('DeviceConfigurationManagement.notInUse')
          },
          {
            key:'2',
            label: this.$t('DeviceConfigurationManagement.unplanned')
          },

        ]
      }
    },

    computed: {


    createAndCopyCommand() {
        return DeviceCommands.createAndCopyDeviceCommand(this.createAndCopyTitle, this.createAndCopyInitList, this.commandContext)
      },
      deleteCommand() {
        return DeviceCommands.deleteDeviceCommand(this.deleteList, this.commandContext)
      },
      updateCommand() {
        return DeviceCommands.updateDeviceCommand(this.updateInitList, this.commandContext)
      },
      importCommand() {
        return DeviceCommands.importDeviceCommand(this.commandContext)
      },

      downloadConfigToDeviceCommand() {
        return DeviceCommands.downloadConfigToDeviceCommand(this.multipleSelection[0], this.commandContext)
      },
      historyConfigToDeviceCommand() {
        return DeviceCommands.historyConfigToDeviceCommand(this.updateConfigFileKey, this.commandContext)
      },
    },
    watch: {
      '$route'(to, from) {
        // 对路由变化作出响应...
        if (to.name === '网元配置' && to.query.locationKey !== undefined) {
          this.querySelectlocationKey = to.query.locationKey;
          this.TurnFromLocation(to.query.locationKey);
        }
        if (to.name === '网元配置' && to.query.cabinetKey !== undefined) {
          this.querySelectlocationKey = to.query.locationFromCabinet;
          this.querySelectFrame = to.query.cabinetKey;
          this.TurnFromCabinet(to.query.cabinetKey);
        }
        if (to.name === '网元配置' && to.query.subnetKey !== undefined) {
          this.querySelectSubnet = to.query.subnetKey;
          this.TurnFromSubnet(to.query.subnetKey);
        }
      },
      commandContext(newVal, oldVal) {
        if (JSON.stringify(newVal) === '{}') {
          this.clear()
          this.getAllDevice(this)
          this.$refs.singleTable.clearSelection();
        }
        deep: true
      },
      '$i18n.locale'() {
        this.deviceStatusList[0].label = this.$t('DeviceConfigurationManagement.inUse');
        this.deviceStatusList[1].label = this.$t('DeviceConfigurationManagement.notInUse');
        this.deviceStatusList[2].label = this.$t('DeviceConfigurationManagement.unplanned');
        // this.deviceTypeList[0].deviceTypeName = this.$t('DeviceConfigurationManagement.traditional');

      }
    },

  }
</script>

<style scoped>
  /*!* 外层布局容器样式 *!*/

  .el-table .warning-row {
    background: oldlace;
  }

  body .el-table colgroup.gutter {
    display: table-cell !important;
  }

  .el-table .current-row {
    background: #FF8040;
  }

</style>
