<template>
  <!-- 子网修改对话框 -->
  <el-dialog
    @close="close"
    @opened="updateSubnetInit"
    v-dialogDrag
    v-if="UpdateSubnetVisible"
    :title="$t('SubnetConfigurationManagement.updateSubnetInfo')"
    style="font-size: 10px;" width='450px'
    :visible.sync="UpdateSubnetVisible">
    <el-form :model="form" inline="true">
      <el-form-item :label="'*'+ $t('SubnetConfigurationManagement.subnetName')+':'" :label-width="formLabelWidth"
                    style="margin-bottom: -10px;">
        <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.subnetName"
                  v-on:blur="subnetNameCheck" autocomplete="off" style="width: 152px;"></el-input>
      </el-form-item>
      <el-form-item :label="$t('SubnetConfigurationManagement.domain')+':'" :label-width="formLabelWidth"
                    style="margin-bottom: -10px; margin-left: 0px;">
        <el-input type="textarea" :rows="4" :placeholder="$t('common.placeholder')" v-model="form.domain"
                  autocomplete="off" style="width: 152px; margin-top: 10px;"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size='mini' type="primary" @click="updateSubnet" v-loading.fullscreen.lock="fullscreenLoading">
        {{$t("common.updateBtn")}}
      </el-button>
      <el-button size='mini' @click="close">{{$t("common.cancel")}}</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import SubnetService from '@/domain/services/SubnetService.js'
  import legitimacyCheck from "../../../utils/legitimacyCheck";
  import HelperUtil from"../../../utils/HelperUtil";

  export default {
    props: ['command'],

    data: function () {
      return {
        UpdateSubnetVisible: false,
        initList: this.command.target,

        formLabelWidth: '120px',
        form: {
          subnetKey:null,
          subnetName: null,
          domain: null,
        },
      }
    },
    methods: {
      close() {
        this.command.done();
      },

      //------------------------------------创建开始-------------------------------------------------------------------
      updateSubnetInit(){
        this.form.subnetKey = this.initList.subnetKey;
        this.form.subnetName = this.initList.subnetName;
        this.form.domain = this.initList.domain;

      },

      updateSubnet(){
        if(!this.subnetNameCheck()){
          return
        }
        else{
          let subnet = {};
          subnet.subnetKey = this.form.subnetKey;
          subnet.subnetName = this.form.subnetName;
          subnet.domain = this.form.domain;
          subnet.delFlag = 0;
          subnet.modifyTime = '';

          SubnetService.modifySubnet(subnet).then(result => {
            //成功
            /*this.$message({
              type: 'success',
              message: '修改子网成功 ',
              duration: 10000,
              showClose: true,
            });*/
            this.InfoTip.successTip(this,HelperUtil.getStatusCodeObjectByCode(this.successCode.MODIFY_CODE));
            this.command.done()
          }).catch(err =>{
            //失败
            //this.$message.error('Error ' + err.errorCode+":"+err.errorCause)
            this.InfoTip.errorTip(this,err);
//            this.command.done()
          });

        }
      },

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

      //------------------------------------验证开始-------------------------------------------------------------------
      /**
       * @Description  ：子网名称校验： 不能为空
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      subnetNameCheck: function () {
        let subnetCheck =  legitimacyCheck()
        if (!subnetCheck.textNullCheck(this.form.subnetName)) {
          //输入不可为空
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE),this.$t('SubnetConfigurationManagement.subnetName'))
          return false
        }
        if(!this.textLengthCheck(this.form.subnetName)) return false
        return true
      },

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

    },
    created() {
      console.log('初始化加载数据')
    },
    mounted(){
      this.UpdateSubnetVisible = true;
    }


  }
</script>
