UpdateDevicePort.vue 9.99 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
<template>
  <!-- 端口创建对话框 -->
  <el-dialog v-dialogDrag
             @close="close"
             @opened="createPortInit"
             :title="$t('DeviceCreatPort.updatePortInfo')"
             width="450px"
             v-if="CreateAndCopyDevicePort"
             :visible.sync="CreateAndCopyDevicePort">
    <el-form :model="form" inline="true" ref="form">
      <el-form-item prop="number" style="margin-bottom: -10px;" :label="$t('DeviceCreatPort.deviceKey')+': '"
                    :label-width="formLabelWidth">
        <el-select  size='mini' v-model="form.deviceKey" :placeholder="$t('common.placeholderSelect')"
                    v-on:change="deviceKeyCheck(form.deviceKey)">
          <el-option v-for="item in deviceList" :key="item.deviceKey" :label="item.displayName"
                     :value="item.deviceKey"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="number" style="margin-bottom: -10px;" :label="$t('DeviceCreatPort.portName')+': '"
                    :label-width="formLabelWidth">
        <el-select clearable size='mini' v-model="form.portName" :placeholder="$t('common.placeholderSelect')"
                   filterable @blur="selectBlur">
          <el-option v-for="item in portNameList" :key="item.resourceKey" :label="item.portName"
                     :value="item.portName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-bottom: -10px;" prop="string" :label="$t('DeviceCreatPort.purpose')+': '"
                    :label-width="formLabelWidth">
        <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.businessDesc" autocomplete="off"
                  v-on:blur="purposeCheck" style="width: 178px"></el-input>
      </el-form-item>
    </el-form>
    <el-row style="margin-bottom: 0px;" slot="footer" class="dialog-footer">
      <el-button style="margin-bottom: -10px;" id="save" icon="el-icon-circle-check" size='mini' type="primary" @click="createPort">
        {{$t("common.ok")}}
      </el-button>
      <el-button style="margin-bottom: -10px;" icon="el-icon-circle-check" size='mini' @click="close">
        {{$t("common.cancel")}}
      </el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import PortService from '@/domain/services/PortListService.js'
import DeviceService from '@/domain/services/DeviceService'
import legitimacyCheck from '../../../utils/legitimacyCheck'
import HelperUtil from '../../../utils/HelperUtil'

export default {
  props: ['command'],
  data: function () {
    return {
      initList: this.command.target,
      CreateAndCopyDevicePort: false,
      formLabelWidth: '100px',
      deviceList: [],
      portCheck: null,
      portNameList: [],
      form: {

        portKey: '',
        deviceKey: '',
        portName: '',
        businessDesc: '',
        delFlag: '',
        modifyTime: ''

      }
    }
  },
  methods: {
    /**
       * @Description  : 端口支持手动输入
       * @author       : ls
       * @date         : 2020/10/13 18:02
       * @param        :
       * @return       :
       */
    selectBlur: function (e) {
      this.form.portName = e.target.value
    },
    close () {
      this.command.done()
    },

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

    // ------------------------------------创建开始-------------------------------------------------------------------
    createPortInit () {
      this.form.portKey = ''
      this.form.deviceKey = this.initList.deviceKey
      this.form.portName = this.initList.portName
      this.form.businessDesc = this.initList.businessDesc
      this.form.delFlag = this.initList.delFlag
      this.form.modifyTime = this.initList.modifyTime
      // this.deviceKeyCheck(this.form.deviceKey)
    },

    createPort () {
      let _this = this
      if (this.form.deviceKey === '') {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceCreatPort.deviceKeyForTable'))
        return false
      } else if (!_this.portNameCheck()) {

      } else if (!_this.purposeCheck()) {

      } else {
        let port = {}
        port.portKey = _this.initList.portKey
        port.deviceKey = _this.form.deviceKey
        port.portName = _this.form.portName
        port.businessDesc = _this.form.businessDesc
        port.delFlag = _this.form.delFlag
        port.modifyTime = _this.form.modifyTime

        // 打开loading
        let loadingInstance = _this.Loading.openLoading()
        PortService.modifyPort(port).then(result => {
          // 关闭loading
          _this.Loading.closeLoading(loadingInstance)
          // 成功
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.MODIFY_CODE))
          _this.close()
        }).catch(err => {
          // 关闭loading
          _this.Loading.closeLoading(loadingInstance)
          // 失败
          _this.InfoTip.errorTip(_this, err)
        })
      }
    },

    // ------------------------------------创建结束-------------------------------------------------------------------

    // ------------------------------------验证开始-------------------------------------------------------------------
    /**
       * @Description  :端口名称校验: 不能为空
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
    portNameCheck: function () {
      if (!this.portCheck.textNullCheck(this.form.portName)) {
        // 输入不可为空
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceCreatPort.portNameForTable'))
        return false
      }
      return true

      // if (!this.portCheck.textNullCheck(this.form.portName)) {
      //   // 输入不可为空
      //   this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceCreatPort.portNameForTable'))
      //   return false
      // } else if (parseInt(this.form.portName) > 99 || parseInt(this.form.portName) < 0) {
      //   this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.START_DEVICE_PORT_BETWEEN_0_99))
      //   return false
      // }
      // if (!(this.textLengthCheck(this.form.portName))) { return false }
      // if (!this.numCheck(this.form.portName)) { return false }
      // return true
    },
    numCheck: function (checkNumber) {
      if (!this.portCheck.numberCheck(checkNumber)) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_VALID_NUMBER))

        return false
      }
      return true
    },

    /**
       * @Description  :端口名称校验: 不能为空
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
    purposeCheck: function () {
      if (!this.portCheck.textNullCheck(this.form.businessDesc)) {
        // 输入不可为空
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceCreatPort.purposeForTable'))
        return false
      }
      // this.textLengthCheck(this.form.businessDesc)
      return true
    },
    /**
       * @Description  : 端口名称获取
       * @author       : ls
       * @date         : 2020/10/13 18:01
       * @param        :
       * @return       :
       */
    deviceKeyCheck: function (val) {
      let _this = this
      var flag = false
      _this.portNameList = []
      _this.form.portName = ''
      var deviceTy = _this.deviceList[val].deviceTypeKey
      if (deviceTy === 'SERVER' || deviceTy === 'STORAGE') {
        flag = true
      }
      if (flag) {
        _this.portNameList = [
          // {
          //   key: 'IPMI',
          //   portName: 'IPMI'
          // },
          // {
          //   key: '网络端口1',
          //   portName: '网络端口1'
          // },
          // {
          //   key: '网络端口2',
          //   portName: '网络端口2'
          // }
        ]
      } else {
        let selectList = []
        selectList.push(
          {
            quaryAttribute: 'deviceKey',
            compareSymbol: '=',
            compareValue: val
          },
          {
            quaryAttribute: 'deviceParam',
            compareSymbol: '=',
            compareValue: 'PORT_NAME'
          }
        )
        DeviceService.getDevicePortStatus(selectList).then(result => {
          _this.portNameList = result
        }).catch(err => {
          _this.InfoTip.errorTip(_this, err)
        })
      }
    },

    /**
       * @Description  :文本框所输入的字符长度校验: 控制在20之内
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/1/15 16:09
       */
    textLengthCheck: function (checkString) {
      if (!this.portCheck.textLengthCheck(checkString)) {
        // 所输文本长度必须控制在20之内
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.LENGTH_CODE))
        return false
      }
      return true
    }

    // ------------------------------------验证结束-------------------------------------------------------------------

  },

  created () {
    console.log('接入业务创建初始化加载数据')
    this.getAllDeviceInit()
    this.portCheck = legitimacyCheck()
  },
  mounted () {
    this.CreateAndCopyDevicePort = true
  }
}
</script>