<template>
  <!-- 网元创建对话框 -->
  <el-dialog @close="close"
             width='450px'
             :title="$t('DeviceCommands.updateBookInfo')"
             v-dialogDrag
             :visible.sync="createAndCopyDeviceVisible">
    <el-main>
      <el-form :model="form" inline>
        <el-form-item :label="$t('DeviceConfigurationManagement.stationSite') + ':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.station"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.locationKey') + ':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.locationName"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.manager')+':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.manager"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.phone')+':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.managerPhone"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.brand')+':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.brand"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.brandManager')+':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.manufacturerLiaison"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('DeviceConfigurationManagement.brandPhone')+':'"
                      style="margin-bottom: -7px"
                      :label-width="formLabelWidth">
          <el-input size='mini'
                    :placeholder="$t('common.placeholder')"
                    v-model="form.manufacturerPhone"
                    clearable="true"
                    style="width: 180px;">
          </el-input>
        </el-form-item>
      </el-form>
    </el-main>
    <div slot="footer" class="dialog-footer">
      <el-button size='mini' type="primary" @click="updateDeviceBook" icon='el-icon-circle-check'>
        {{$t("common.ok")}}
      </el-button>
      <el-button size='mini' @click="close" icon='el-icon-circle-close'>{{$t("common.cancel")}}</el-button>
    </div>
  </el-dialog>
</template>
<script>
import legitimacyCheck from '../../../utils/legitimacyCheck'
import DeviceService from '@/domain/services/DeviceService'
import SubnetService from '@/domain/services/SubnetService.js'
import CabinetService from '@/domain/services/CabinetService.js'
import RailwayService from '@/domain/services/RailwayService.js'
import HelperUtil from '../../../utils/HelperUtil'

export default {
  name: 'DeviceBookUpdateDialog',

  components: {},

  props: ['command'],

  data () {
    return {
      createAndCopyDeviceVisible: true,
      initList: this.command.target,
      showBook: false,
      check: null,

      formLabelWidth: '150px',

      // 双向绑定弹出窗口ipput域
      form: {
        manufacturerLiaison: '',
        manufacturerPhone: '',
        manager: '',
        brand: '',
        managerPhone: '',
        station: '',
        locationName: ''
      }
    }
  },

  methods: {
    stationBlur: function (e) {
      this.form.station = e.target.value
    },
    close () {
      this.command.done()
    },
    /**
     * @Description  : 所属车站校验
     * @author       : ls
     * @date         : 2020/6/8 17:35
     * @param        :
     * @return       :
     */
    staionCheck: function () {
      if (!this.check.textNullCheck(this.form.station)) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE), this.$t('DeviceConfigurationManagement.stationSite'))
        return false
      }
      return true
    },
    /**
       * @Description  : 创建网元信息初始化
       * @author       : ls
       * @date         : 2020/5/1 15:07
       * @param        :
       * @return       :
       */
    createDeviceInit: function () {
      this.form.station = this.initList.station
      this.form.locationName = this.initList.locationName
      this.form.manager = this.initList.manager
      this.form.managerPhone = this.initList.managerPhone
      this.form.brand = this.initList.brand
      this.form.manufacturerLiaison = this.initList.manufacturerLiaison
      this.form.manufacturerPhone = this.initList.manufacturerPhone
    },
    /**
       * @Description  :创建网元
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
    updateDeviceBook: function () {
      this.initList.station = this.form.station
      this.initList.locationName = this.form.locationName
      this.initList.manager = this.form.manager
      this.initList.managerPhone = this.form.managerPhone
      this.initList.brand = this.form.brand
      this.initList.manufacturerLiaison = this.form.manufacturerLiaison
      this.initList.manufacturerPhone = this.form.manufacturerPhone

      let _this = this
      // 打开loaing
      let loadingInstance = _this.Loading.openLoading()
      // 调用函数
      DeviceService.modifyDevice(_this.initList).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)
      })
    }
  },
  // 初始化函数，加载数据
  created: function () {
    this.check = legitimacyCheck()
    this.createDeviceInit()
  }
}
</script>

<style scoped>

</style>
