<template>
  <!-- 业务类型建对话框 -->
  <el-dialog @close="close"
             @opened="createServiceTypeInit"
             v-dialogDrag
             v-if="createAndCopyServiceTypeVisible"
             style="font-size: 10px;" width='450px'
             :title=title
             :visible.sync="createAndCopyServiceTypeVisible">
    <el-form :model="form" inline="true">
      <el-form-item :label="'*'+ $t('ServiceTypeConfigurationManagement.ServiceTypeID')+':'"
                    :label-width="formLabelWidth" style="margin-bottom: -10px;">
        <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.serviceTypeID"
                  v-on:blur="serviceTypeIDCheck" autocomplete="off" style="width: 152px;"></el-input>
      </el-form-item>
      <el-form-item :label="'*'+ $t('ServiceTypeConfigurationManagement.ServiceTypeName')+':'"
                    :label-width="formLabelWidth" style="margin-bottom: -10px; margin-left: 0px;">
        <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.serviceTypeName"
                  v-on:blur="serviceTypeNameCheck" autocomplete="off" style="width: 152px;">
        </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size='mini' type="primary" @click="createServiceType" v-loading.fullscreen.lock="fullscreenLoading">
        {{$t("common.createBtn")}}
      </el-button>
      <el-button size='mini' @click="close">{{$t("common.cancel")}}</el-button>
    </div>
  </el-dialog>
</template>
<script>

  import ServiceTypeService from '@/domain/services/Business/ServiceTypeService.js'
  import legitimacyCheck from "../../../utils/legitimacyCheck";
  import HelperUtil from "../../../utils/HelperUtil";

  export default {
    props: ['command'],

    data() {
      return {

        title: this.command.title,
        initList: this.command.target,
        createAndCopyServiceTypeVisible: false,
        formLabelWidth: '200px',

        //双向绑定弹出窗口input域
        form: {
          serviceTypeID: null,
          serviceTypeName: null,
          delFlag: null,
          modifyTime: null,
        },

      }
    },
    methods: {

      close() {
        this.command.done();
      },
      /**
       * @Description  ：创建业务类型初始化
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      createServiceTypeInit: function () {
        this.form.serviceTypeID = this.initList.serviceTypeID
        this.form.serviceTypeName = this.initList.serviceTypeName
        this.form.delFlag = this.initList.delFlag
        this.form.modifyTime = this.initList.modifyTime

      },
      /**
       * @Description  ：创建业务类型
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/3/12
       */
      createServiceType: function () {
        let _this = this;
        console.log('业务类型创建信息：')
        if (!(_this.totalCheck())) {
          return
        } else {
          let serviceType = {};
          serviceType.serviceTypeKey = "",
            serviceType.serviceTypeID = _this.form.serviceTypeID,
            serviceType.serviceTypeName = _this.form.serviceTypeName,
            //删除标识，0-未删除，1-已删除
            serviceType.delFlag = 0,
            serviceType.modifyTime = ''
//          console.log(serviceType)
//          console.log("serviceType")
          let loadingInstance = _this.Loading.openLoading();
          ServiceTypeService.addServiceType(serviceType).then(result => {
            //成功
            _this.Loading.closeLoading(loadingInstance);
            _this.InfoTip.successTip(_this,HelperUtil.getStatusCodeObjectByCode(_this.successCode.ADD_CODE));
            _this.close()
          }).catch(err => {
            //失败
            _this.Loading.closeLoading(loadingInstance);
            _this.InfoTip.errorTip(_this, err);
          });
//          this.command.done();
        }
      },
      //--------------------------------------开始校验--------------------------------
      /**
       * @Description  ：业务类型名称非空校验
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/3/13
       */
      serviceTypeNameCheck: function () {

        let serviceTypeCheck = legitimacyCheck()
        if (!serviceTypeCheck.textNullCheck(this.form.serviceTypeName)) {
          // let message='业务类型名称不可为空！ '
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.SERVICE_TYPE_NAME_CANNOT_BE_EMPTY))
//          this.$message({
//            type: 'warning',
//            message: '业务类型名称不可为空！ ',
//            duration: 10000,
//            showClose: true,
//          });
          return false
        }
        this.textLengthCheck(this.form.serviceTypeName)
        return true

      },


      /**
       * @Description  ：业务类型ID非空校验
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/3/13
       */
      serviceTypeIDCheck: function () {

        let serviceTypeCheck = legitimacyCheck()
        if (!serviceTypeCheck.textNullCheck(this.form.serviceTypeID)) {
         // let message='业务类型编号不可为空！ '
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.SERVICE_TYPE_ID_CANNOT_BE_EMPTY))
//          this.$message({
//            type: 'warning',
//            message: '业务类型编号不可为空！ ',
//            duration: 10000,
//            showClose: true,
//          });
          return false
        } else if (!this.numCheck(this.form.serviceTypeID)) {
          return false
        }
        else if (!this.textLengthCheck(this.form.serviceTypeID)) {
          return false
        }
        return true
      },

      /**
       * @Description  ：输入数字
       * @author       : bjh
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/1/15 16:09
       */
      numCheck: function (checkNumber) {
        let _this = this
        let serviceTypeCheck = legitimacyCheck()
        if (!serviceTypeCheck.numberCheck(checkNumber)) {
          // let message = '请输入有效的数字'
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_ENTER_A_VALID_NUMBER))
//          this.$message({
//            type: 'warning',
//            message: '请输入有效的数字！ ',
//            duration: 10000,
//            showClose: true,
//          });
          return false
        }
        return true
      },


      /**
       * @Description  ：文本框所输入的字符长度校验： 控制在20之内
       * @author       : bjh
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/1/15 16:09
       */
      textLengthCheck: function (checkString) {
        let serviceTypeCheck = legitimacyCheck()
        if (!serviceTypeCheck.textLengthCheck(checkString)) {
          // let message='所输文本长度必须控制在20之内！ '
          this.InfoTip.warningTip(this,{message: message})
//          this.$message({
//            type: 'warning',
//            message: '所输文本长度必须控制在20之内！ ',
//            duration: 10000,
//            showClose: true,
//          });
          return false
        }
        return true
      },

      totalCheck(){
        if(!this.serviceTypeNameCheck()){
          return false
        }else   if(!this.serviceTypeIDCheck()){
          return false
        }
        return true
      }

      //--------------------------------------结束校验--------------------------------
    },
    created() {
      console.log('创建初始化加载数据')
    },
    mounted() {
      this.createAndCopyServiceTypeVisible = true
    },

  }

</script>

<style scoped>
  /*!* 外层布局容器样式 *!*/
  .el-header {
    background-color: #f9fafc;
    color: #333;
    line-height: 40px;
  }

  .el-input {
    width: 330px;
  }

  /deep/ .el-textarea__inner {
    font-size: 10px;
  }
</style>
