<template>
  <div style="width: 600px">
    <block-header title="创建减免单" />
    <el-form
        size="small"
        label-suffix=":"
        :model="ruleForm"
        :rules="rules" ref="ruleForm"
        label-width="120px" class="demo-ruleForm">
      <el-form-item label="借款编号" prop="loanNo">
        <el-col :span="20">
          <el-input v-model="ruleForm.loanNo" placeholder="请正确填写借款编号"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="减免金额" prop="derateAmt">
        <el-col :span="20">
          <el-input type='number' v-model="ruleForm.derateAmt" placeholder="请输入减免金额"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="描述信息" prop="applyDesc">
        <el-col :span="20">
          <el-input v-model="ruleForm.applyDesc" placeholder="请输入减免描述信息"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" @click="createDerate('ruleForm')">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "DerateCreate",

  props: {

  },
  data (){
    return {
      ruleForm: {
        loanNo: '',
        derateAmt: '',
        applyUser: '',
        applyDesc: ''
      },
      rules: {
        loanNo: [{required: true, message: '请正确填写借款编号', trigger: 'blur'}],
        derateAmt: [{required: true, message: '请输入减免金额', trigger: 'blur'}],
        applyDesc: [{required: true, message: '请输入减免描述信息', trigger: 'blur'}],
      },
      loginName: '',
    }
  },
  mounted() {
    this.loginName = localStorage.getItem("loginName");
  },

  methods:{

    /** 提交点击 */
    createDerate() {

      this.$refs['ruleForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$confirm('操作将创建减免单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          this.$$post(`/loan/createDerated`, {
            loanNo: this.ruleForm.loanNo,
            derateAmt: this.ruleForm.derateAmt,
            applyDesc: this.ruleForm.applyDesc,
            applyUser: this.loginName,

          }).then(res => {
            if (res.data.code != 200) {
              this.$message.error(res.data.message);
              return
            }
            this.$message({message: '提交成功!', type: 'success'});
            setTimeout(() => {
              window.location.reload();
            }, 1500);

          }).catch(err => {
            this.$message.error("提交减免单失败！！！");
          })


        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });

      })
    },

  }

}
</script>

<style scoped>

</style>
