<template>
  <!-- 网元创建对话框 -->
  <el-dialog @close="close"
             @opened="createDeviceInit"
             style="font-size: 10px;" width='950px'
             :title=title
             :visible.sync="createAndCopyDeviceVisible">

    <el-row>
      <el-form :model="form" inline="true" ref="form">

        <el-row>
          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item
              :label="'*'+ $t('DeviceConfigurationManagement.ipAddress')+':'"
              :label-width="formLabelWidth"
              prop="string">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.ipAddress"
                        autocomplete="off"
                        v-on:blur="ipCheck"
                        style="width:200px"></el-input>
            </el-form-item>
            <el-form-item prop="number"
                          :label="'*'+ $t('DeviceConfigurationManagement.uuid')+':'"
                          :label-width="formLabelWidth">
              <el-input type="age" size='mini' :placeholder="$t('common.placeholder')" v-model="form.uuid"
                        v-on:blur="uuidCheck "
                        autocomplete="off"
                        style="width:200px"></el-input>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item :label="'*'+ $t('DeviceConfigurationManagement.nodeType')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size='mini' v-model="form.deviceTypeKey" :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         style="width:200px">
                <el-option v-for="item in deviceTypeList" :key="item.deviceTypeKey" :label="item.deviceTypeKey"
                           :value="item.deviceTypeKey"></el-option>

              </el-select>
            </el-form-item>
            <el-form-item
              :label="'*'+ $t('DeviceConfigurationManagement.displayName')+':'"
              :label-width="formLabelWidth"
              prop="string">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.displayName"
                        autocomplete="off"
                        v-on:blur="deviceNameCheck"
                        style="width:200px"></el-input>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item prop="string"
                          :label="'*'+ $t('DeviceConfigurationManagement.nodeModel')+':'"
                          :label-width="formLabelWidth">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.deviceModel"
                        v-on:blur="deviceModelCheck"
                        autocomplete="off"
                        style="width:200px"></el-input>
            </el-form-item>
            <el-form-item :label="'*'+ $t('DeviceConfigurationManagement.subnetKey')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size='mini' v-model="form.subnetKey" filterable :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         style="width:200px">
                <el-option v-for="item in subnetList" :key="item.subnetKey" :label="item.subnetName"
                           :value="item.subnetKey"></el-option>

              </el-select>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item unselectable="on"
                          :label="'*'+ $t('DeviceConfigurationManagement.snmpVersion')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size='mini' v-model="deviceSNMP" :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         v-on:change="deviceSNMPCheck"
                         style="width:200px">
                <el-option v-for="item in deviceSNMPList" :key="item.key" :label="item.label"
                           :value="item.key"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="'*'+ $t('DeviceConfigurationManagement.snmpPort')+':'"
                          :label-width="formLabelWidth" prop="string">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.snmpPort" autocomplete="off"
                        v-on:blur="getnumberCheck"
                        style="width:200px"></el-input>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item :label="'*'+ $t('DeviceConfigurationManagement.trapPort')+':'"
                          :label-width="formLabelWidth" prop="string">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.trapPort" autocomplete="on"
                        v-on:blur="trapnumberCheck"
                        style="width:200px"></el-input>
            </el-form-item>
            <el-form-item style=" width:400px">
              <el-button style="margin-bottom: -10px;" size='mini' type="primary" @click="GetDevieceInfo">
                {{$t("DeviceConfigurationManagement.GetDevieceInfo")}}
              </el-button>
              <label style="width: 120px"> </label>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item prop="string"
                          :label="$t('DeviceConfigurationManagement.nodeName')+':'"
                          :label-width="formLabelWidth">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.hostName"
                        autocomplete="off"
                        style="width:200px"></el-input>
            </el-form-item>
            <el-form-item prop="string"
                          :label="$t('DeviceConfigurationManagement.nodeVersion')+':'"
                          :label-width="formLabelWidth">
              <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.deviceVersion"
                        autocomplete="off"
                        style="width:200px"></el-input>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item
              :label="$t('DeviceConfigurationManagement.nodeStatus')+':'"
              :label-width="formLabelWidth"
              prop="string">
              <el-select clearable size='mini' v-model="valueState" :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         v-on:change="valueStateCheck " style="width:200px">
                <!--:formatter="formatStateKey"-->
                <el-option v-for="item in deviceStatusList" :key="item.key" :label="item.label"
                           :value="item.key"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label=" $t('DeviceConfigurationManagement.locationKey')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size="mini" v-model="form.locationKey"
                         :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         filterable
                         v-on:change="queryCabinetByCondition"
                         v-on:clear="clearCabinetKey"
                         @blur = "selectBlur3"
                         style="width:200px">
                <el-option v-for="item in locationList" :key="item.locationKey" :label="item.locationName"
                           :value="item.locationKey"></el-option>
              </el-select>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: 0px;float:left">
            <el-form-item :label=" $t('DeviceConfigurationManagement.cabinetKey')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size='mini' v-model="form.cabinetKey" :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off"
                         filterable
                         v-on:change="queryLocationByCondition"
                         @blur = "selectBlur4"
                         style="width:200px">
                <el-option v-for="item in cabinetList" :key="item.cabinetKey" :label="item.cabinetName"
                           :value="item.cabinetKey"></el-option>

              </el-select>
            </el-form-item>
            <el-form-item :label=" $t('DeviceConfigurationManagement.railwayAdmin')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-select clearable size='mini' v-model="form.railwayAdmin" filterable :placeholder="$t('common.placeholderSelect')"
                         autocomplete="off" @blur = "selectBlur1"
                         v-on:change="queryLocationByCondition"
                         style="width:200px">
                <el-option v-for="item in railwayAdminList" :key="item.areaKey" :label="item.areaName"
                           :value="item.areaKey"></el-option>

              </el-select>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: -10px; float:left">
            <el-form-item :label=" $t('DeviceConfigurationManagement.railwayDivision')+':'"
                                         :label-width="formLabelWidth"
                                         prop="string">
            <el-select clearable size='mini' v-model="form.railwayDivision" filterable :placeholder="$t('common.placeholderSelect')"
                       autocomplete="off" @blur = "selectBlur2"
                       v-on:change="queryLocationByCondition"
                       style="width:200px">
              <el-option v-for="item in railwayDivisionList" :key="item.areaKey" :label="item.areaName"
                         :value="item.areaKey"></el-option>

            </el-select>
          </el-form-item>
            <el-form-item :label=" $t('DeviceConfigurationManagement.startTime')+':'"
                          :label-width="formLabelWidth"
                          prop="string">
              <el-input size='mini' :placeholder="$t('common.timeFormat')" v-model="form.startTime"
                        autocomplete="off"
                        v-on:blur="timeCheak"
                        style="width:200px"></el-input>
            </el-form-item>
          </el-form-item>

          <el-form-item style="margin-bottom: -10px; float:left">
            <el-form-item :label="$t('DeviceConfigurationManagement.nodeDesc')+':'" :label-width="formLabelWidth">
              <el-input type="textarea" :rows="3" :placeholder="$t('common.placeholder')" v-model="form.deviceDesc"
                        autocomplete="off" style="width: 620px; margin-top: 10px;"></el-input>
            </el-form-item>
          </el-form-item>

        </el-row>
      </el-form>
    </el-row>
    <el-row style="margin-bottom: 0px;" slot="footer" class="dialog-footer">

      <el-button style="margin-bottom: -10px;" size='mini' type="primary" :disabled="state"
                 @click="createDevice" v-loading.fullscreen.lock="fullscreenLoading">{{$t("common.createBtn")}}
      </el-button>
      <el-button style="margin-bottom: -10px;" size='mini' @click="close">{{$t("common.cancel")}}</el-button>
    </el-row>
  </el-dialog>

</template>

<script>
  import DeviceManager from "../../../domain/models/DeviceManager";
  import DeviceStateService from "../../../domain/services/DeviceStateService";
  import SubnetManager from "../../../domain/models/SubnetManager";
  import legitimacyCheck from "../../../utils/legitimacyCheck";
  import DeviceService from '@/domain/services/DeviceService';
  import SubnetService from '@/domain/services/SubnetService.js';
  import LocationService from '@/domain/services/LocationService.js';
  import CabinetService from '@/domain/services/CabinetService.js';
  import cabinetManager from '../../../domain/models/CabinetManager.js';
  import locationManager from '@/domain/models/LocationManager.js';
  import RailwayService from '@/domain/services/RailwayService.js'
  import HelperUtil from '../../../utils/HelperUtil'

  export default {
    name: "CreateAndCopyDeviceDialog",

    components: {},

    props: ['command'],

    data() {
      return {
        createAndCopyDeviceVisible: true,
        initList: this.command.target,
        title: this.command.title,

        deviceInfo: {},

        formLabelWidth: '200px',
        fullscreenLoading: false,

        cabinetList: [],
        cabinetListInit: [],
        locationList: [],
        locationListInit: [],
        subnetList: [],
        railwayList:[],
        railwayAdminList:[],
        railwayDivisionList:[],
        deviceTypeList:[],

        state: true,
//        disableFlag: true,

        //双向绑定弹出窗口ipput域
        form: {
          deviceKey: '',
          uuid: '',
          hostName: '',
          displayName: '',
          deviceTypeKey: '',
          deviceModel: '',
          switchType: '',
          locationKey: '',
          cabinetKey: '',
          subnetKey: '',
          ipAddress: '',
          otherIpAddress:'',
          mac:'',
          snmpVersion: '',
          snmpPort: 161,
          trapPort: 162,
          deviceStatus: '',
          deviceVersion: '',
          firmwareKey:'',
          firmwareFileName:'',
          masterNode:'',
          deviceDesc:'',
          railwayAdmin:'',
          railwayDivision:'',
          startTime: '',
          manageType:'',
          configFileKey: '',
          configFileName: '',

        },


        //网元状态下拉菜单
        deviceStatusList: [
          {
            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',
        disableFlag: true,

      }
    },

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

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

      /**
       * @Description  :机房支持下拉和输入
       * @author       ::
       * @date         :
       */
      selectBlur3(e){
        this.form.locationKey = e.target.value
      },

      /**
       * @Description  :机架支持下拉和输入
       * @author       ::
       * @date         :
       */
      selectBlur4(e){
        this.form.cabinetKey = e.target.value
      },

      close() {
//        this.$emit("update:createAndCopyDeviceVisible", false);
        this.command.done()
      },
  //     changeSubnet: function () {
  //       alert(this.form.subnetKey)
  // },

      //获取当前时间
      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         :
       */
      createDeviceInit: function () {
        this.state = true
        this.deviceSNMP = this.initList.snmpVersion
        this.valueState = this.initList.deviceStatus.toString()
        this.form.cabinetKey = this.initList.cabinetKey
        this.form.uuid = this.initList.uuid
        this.form.hostName = this.initList.hostName
        this.form.deviceTypeKey = this.initList.deviceTypeKey
        this.form.deviceModel = this.initList.deviceModel
        this.form.deviceVersion = this.initList.deviceVersion
        this.form.switchType = this.initList.switchType
        this.form.locationKey = this.initList.locationKey
        this.form.cabinetKey = this.initList.cabinetKey
        this.form.subnetKey = this.initList.subnetKey
        this.form.ipAddress = this.initList.ipAddress
        this.form.otherIpAddress = this.initList.otherIpAddress
        this.form.mac = this.initList.mac
        this.form.snmpVersion = this.initList.snmpVersion
        this.form.snmpPort = this.initList.snmpPort
        this.form.trapPort = this.initList.trapPort
        this.form.railwayAdmin = this.initList.railwayAdmin
        this.form.railwayDivision = this.initList.railwayDivision
        this.form.deviceDesc = this.initList.deviceDesc
        this.form.firmwareKey = this.initList.firmwareKey
        this.form.firmwareFileName =this.initList.firmwareFileName
        this.form.manageType = this.initList.manageType
        this.form.masterNode = this.initList.masterNode
        // this.form.startTime = this.getCurentTime()
        this.form.startTime = this.initList.startTime
        this.form.delFlag = this.initList.delFlag
        this.form.modifyTime = this.initList.modifyTime
      },


      /**
       * @Description  :为修改功能显示deviceType将数字key转换为中文名称
       */
      // formatdeviceTypeForupdate: function () {
      //   if (this.form.deviceType == '0')
      //     this.form.deviceTypeLabel = this.$t('DeviceConfigurationManagement.traditional')
      //   else if (this.form.deviceType == '1')
      //     this.form.deviceTypeLabel = 'SDN'
      //   else
      //     this.form.deviceTypeLabel = ''
      //
      // },

      /**
       * @Description  :手动获取设备信息
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date
       */
      GetDevieceInfo: function () {
//        有用的，先注掉
        if (!this.ipCheck()) {
          return false
        }
        else if (!this.deviceModelCheck()){
          return false;
        }
        else if (!this.deviceTypeCheck()){
          return false;
        }
        else {
          let _this = this;
          _this.state = false
          let deviceInfo = {};
          deviceInfo.deviceKey = this.form.deviceKey;
          deviceInfo.uuid = this.form.uuid;
          deviceInfo.hostName = this.form.hostName;
          deviceInfo.displayName = this.form.displayName;
          deviceInfo.deviceTypeKey = this.form.deviceTypeKey;
          deviceInfo.deviceModel = this.form.deviceModel;
          deviceInfo.switchType = this.form.switchType;
          deviceInfo.locationKey = this.form.locationKey;
          deviceInfo.cabinetKey = this.form.cabinetKey;
          deviceInfo.subnetKey = this.form.subnetKey;
          deviceInfo.ipAddress = this.form.ipAddress;
          deviceInfo.otherIpAddress = this.form.otherIpAddress;
          deviceInfo.mac = this.form.mac;
          deviceInfo.snmpVersion = this.deviceSNMP;
          deviceInfo.snmpPort = this.form.snmpPort;
          deviceInfo.trapPort = this.form.trapPort;
          deviceInfo.deviceStatus = this.valueState;
          deviceInfo.deviceVersion = this.form.deviceVersion;
          deviceInfo.firmwareKey = this.form.firmwareKey;
          deviceInfo.firmwareFileName = this.form.firmwareFileName;
          deviceInfo.startTime = this.form.startTime;
          deviceInfo.railwayAdmin = this.form.railwayAdmin;
          deviceInfo.railwayDivision = this.form.railwayDivision;
          deviceInfo.deviceDesc = this.form.deviceDesc;
          deviceInfo.manageType = this.form.manageType;
          deviceInfo.masterNode = this.form.masterNode;
          deviceInfo.delFlag = this.form.delFlag;
          deviceInfo.modifyTime = this.form.modifyTime;
          //打开loaing
          let loadingInstance = _this.Loading.openLoading();
          //调用函数
          DeviceService.postDeviceInfo(deviceInfo).then(result => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance);
            //成功
            _this.form.uuid = result.uuid
            _this.form.deviceTypeKey = result.deviceTypeKey
            _this.form.hostName = result.hostName
            _this.form.deviceModel = result.deviceModel
            _this.form.deviceVersion = result.deviceVersion
            _this.form.displayName = result.displayName
            _this.form.deviceModel = result.deviceModel
            _this.form.deviceVersion = result.deviceVersion
            _this.form.deviceStatus = result.deviceStatus
            _this.form.cabinetKey = result.cabinetKey
            _this.form.subnetKey = result.subnetKey
            _this.form.locationKey = result.locationKey
            _this.form.railwayAdmin = result.railwayAdmin
            _this.form.railwayDivision = result.railwayDivision
            _this.form.deviceDesc = result.deviceDesc
          }).catch(err => {
            //关闭loading
            _this.Loading.closeLoading(loadingInstance);
            //失败
            _this.InfoTip.errorTip(_this, err);
            console.log(err)
          })

        }
      },

      /**
       * @Description  :创建网元
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      createDevice: function () {
        if (!this.totalCheck()) {
          return
        }
        let device = {};
        device.deviceKey = this.form.deviceKey;
        device.uuid = this.form.uuid;
        device.hostName = this.form.hostName;
        device.displayName = this.form.displayName;
        device.deviceTypeKey = this.form.deviceTypeKey;
        device.deviceModel = this.form.deviceModel;
        device.switchType = this.form.switchType;
        device.locationKey = this.form.locationKey;
        device.cabinetKey = this.form.cabinetKey;
        device.subnetKey = this.form.subnetKey;
        device.ipAddress = this.form.ipAddress;
        device.otherIpAddress = this.form.otherIpAddress;
        device.mac = this.form.mac;
        device.snmpVersion = this.deviceSNMP;
        device.snmpPort = this.form.snmpPort;
        device.trapPort = this.form.trapPort;
        device.deviceStatus = this.valueState;
        device.deviceVersion = this.form.deviceVersion;
        device.firmwareKey = this.form.firmwareKey;
        device.firmwareFileName = this.form.firmwareFileName;
        device.startTime = this.form.startTime;
        device.railwayAdmin = this.form.railwayAdmin;
        device.railwayDivision = this.form.railwayDivision;
        device.deviceDesc = this.form.deviceDesc;
        device.manageType = this.form.manageType;
        device.masterNode = this.form.masterNode;
        device.delFlag = this.form.delFlag;
        device.modifyTime = this.form.modifyTime;

        let _this = this;
        //打开loaing
        let loadingInstance = _this.Loading.openLoading();
        //调用函数
        DeviceService.addDevice(device).then(result => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.ADD_CODE))
          _this.close()
        }).catch(err => {
          //关闭loading
          _this.Loading.closeLoading(loadingInstance);
          //失败
          _this.InfoTip.errorTip(_this, err);
//          _this.command.done();

        });
      },

      /**
       * @Description  :为了新增修改复制功能机房机架级联条件查询,根据机架显示机房
       * @author       :
       * @param        :
       * @date         :
       */
      queryLocationByCondition: function () {

        //已知机架，查询机房
        //直接改变，locationList的值，其他地方不会受影响
        let locMgr = locationManager(this.locationListInit)
        this.form.locationKey = locMgr.findCabinetLocation(this.form.cabinetKey, this.cabinetListInit, this.locationListInit).locationKey

//        根据查询来的机房显示机架
        let cabMgr = cabinetManager(this.cabinetListInit)
        this.cabinetList = cabMgr.findLocationCabinet(this.form.locationKey, this.cabinetListInit)


      },
      clearCabinetKey() {
        this.form.cabinetKey = null
      },


      /**
       * @Description  :为了增加修改复制功能机房机架级联条件查询，根据机房显示机架
       * @author       :
       * @param        :
       * @date         :
       */
      queryCabinetByCondition: function () {
//        已知机房，重新加载机架列表，直接修改cabnetList
        if (this.form.locationKey) {
          let cabMgr = cabinetManager(this.cabinetListInit)
          this.cabinetList = cabMgr.findLocationCabinet(this.form.locationKey, this.cabinetListInit)
          this.form.cabinetKey = null

        }
        else {
          this.cabinetList = this.cabinetListInit

        }

      },

      //-------------------------------------转换---------------------------
      /**
       * @Description  :为修改功能显示deviceType将数字key转换为中文名称
       */
      // formatdeviceTypeForupdate: function () {
      //   if (this.form.deviceType == '0')
      //     this.form.deviceTypeLabel = '传统'
      //   else if (this.form.deviceType == '1')
      //     this.form.deviceTypeLabel = 'SDN'
      //   else
      //     this.form.deviceTypeLabel = ''
      //
      // },


      //-------------------初始化获取子网机房机架---------------------------

      /**
       * @Description  :获取全部机房信息，
       * @author       :
       * @date         : 2018/12/13
       */
      getAllLocation: function () {
        let _this = this;
        //就这句没改
        LocationService.getAllLocationCollection().then(result => {
          //成功
          _this.locationListInit = result
          _this.locationList = Object.values(result)

        }).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.cabinetListInit = result
          _this.cabinetList = 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)
        })
      },

      /**
       * @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);
        })
      },

//     ------------------------------- 开始合法性校验--------------

      //时间合法性验证
      timeCheak: function () {
//        var result = false
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.timeCheck(this.form.startTime)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_VALID_TIME))

          return false
        }
        return true
      },

      // 验证IP合法性
      ipCheck: function () {

        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.ipCheck(this.form.ipAddress)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_VALID_DEVICE_IP_ADDRESS))
          return false
        }
        return true

      },


      //输入文本长度验证
      textLengthCheck: function (checkString) {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textLengthCheck(checkString)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.LENGTH_CODE))
          return false
        }
        return true
      },

      getnumberCheck: function () {

        let deviceCheck = legitimacyCheck()

        if (!deviceCheck.textNullCheck(this.form.snmpPort)) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.snmpPort'))
          return false
        }
        var result = deviceCheck.numberCheck(this.form.snmpPort)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_VALID_NUMBER))
          return false
        }
        if (!this.textLengthCheck(this.form.snmpPort)) {
          return false
        }
        return true
      },
      trapnumberCheck: function () {

        let deviceCheck = legitimacyCheck()
        if (!deviceCheck.textNullCheck(this.form.trapPort)) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.trapPort'))
          return false
        }
        var result = deviceCheck.numberCheck(this.form.trapPort)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_VALID_NUMBER))
          return false
        }
        if (!this.textLengthCheck(this.form.trapPort)) {
          return false
        }
        return true
      },

      uuidCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.form.uuid)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.uuid'))
          return false
        }
        if (!this.textLengthCheck(this.form.uuid)) {
          return false
        }

        return true
      },

      deviceNameCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.form.displayName)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.displayName'))
          return false
        }
        if (!this.textLengthCheck(this.form.displayName)) {
          return false
        }

        return true
      },

      deviceModelCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.form.deviceModel)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.nodeModel'))
          return false
        }
        if (!this.textLengthCheck(this.form.deviceModel)) {
          return false
        }

        return true
      },

      subnetCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.form.subnetKey)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.subnetKey'))
          return false
        }
        if (!this.textLengthCheck(this.form.subnetKey)) {
          return false
        }

        return true
      },

      deviceTypeCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.form.deviceTypeKey)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.nodeType'))
          return false
        }
        if (!this.textLengthCheck(this.form.deviceTypeKey)) {
          return false
        }

        return true
      },

      deviceSNMPCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.deviceSNMP)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.snmpVersion'))
          return false
        }
        return true
      },

      valueStateCheck: function () {
        let deviceCheck = legitimacyCheck()

        var result = deviceCheck.textNullCheck(this.valueState)
        if (!result) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.deviceStatus'))
          return false
        }
        return true

      },


      totalCheck: function () {

        if (!this.timeCheak()) {
          return false;
        }
        if (!this.ipCheck()) {
          return false;
        }
        if (!this.getnumberCheck()) {
          return false;
        }
        if (!this.trapnumberCheck()) {
          return false;
        }
        if (!this.uuidCheck()) {
          return false;
        }
        if (!this.deviceNameCheck()) {
          return false;
        }
        if (!this.deviceSNMPCheck()) {
          return false;
        }
        if (!this.valueStateCheck()) {
          return false;
        }
        if (!this.deviceModelCheck()){
          return false;
        }
        if (!this.subnetCheck()){
          return false;
        }
        return true
      },

//     ------------------------------- 结束合法性校验--------------
    },

    computed: {},

    //初始化函数，加载数据
    created: function () {
      this.getAllSubnet();
      this.getAllCabinet();
      this.getAllLocation();
      this.getAllDeviceType();
      this.getAllRailway();
      this.initList.startTime = this.getCurentTime()
      this.createDeviceInit()

    },

    watch: {
      '$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>

</style>
