<template>
  <div class="box">
    <h3>创建退款单：</h3>
    <el-form
      :inline="false"
      :model="loanInfo"
      :rules="rules"
      ref="loanInfo"
      label-width="200px"
    >
      <el-form-item label="借款编号：" prop="loanNo">
        <el-input
          placeholder="请输入客户编号"
          v-model="loanInfo.loanNo"
        ></el-input>
      </el-form-item>
      <el-form-item label="退款金额：" prop="refundAmt">
        <el-input
          placeholder="请输入退款金额"
          v-model="loanInfo.refundAmt"
        ></el-input>
      </el-form-item>
      <el-form-item label="备注信息：" prop="memo">
        <el-input
          placeholder="请输入备注信息"
          v-model="loanInfo.memo"
        ></el-input>
      </el-form-item>
    </el-form>

    <el-button class="btn" type="primary" @click="trueSet('loanInfo')"
      >确定创建</el-button
    >
  </div>
</template>

<script>
export default {
  name: "CreateRefund",
  data() {
    return {
      loanInfo: {
        loanNo: "", //借款编号
        refundAmt: "", //退款金额
        memo: "", //备注
        creator: "", //创建人
      },
        creators: "", //创建人
      rules: {
        loanNo: [
          { required: true, message: "请输入借款编号", trigger: "blur" },
        ],
        refundAmt: [
          { required: true, message: "请输入退款金额", trigger: "blur" },
        ],
        memo: [
          { required: true, message: "填输入备注信息", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    //获取登录名
    this.creators = localStorage.getItem("loginName");
    // console.log(this.creators,'445')
  },
  methods: {
    open() {
      this.$confirm("此操作将为您创建退款单，是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
        //   console.log(this.creators,this.loanInfo,'zhegeshi canshu') 
        if(this.creators){
            this.loanInfo.creator=this.creators
        }
          this.$$post(`/refund/createRefund`, this.loanInfo).then((res) => {
            if (res.data.code != 200) {
              this.$message.error(res.data.message);
              return;
            } 
            else {
              this.loanInfo = {};
              this.$message({
                type: "success",
                message: "创建成功!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消创建",
          });
          this.loanInfo = {};
        });
    },
    //点击确定提交信息
    trueSet(loanInfo) {
      this.$refs[loanInfo].validate((valid) => {
        if (valid) {
          this.open();
        } else {
          console.log("提交失败!!!");
          return false;
        }
      });
    },
  },
};
</script>

<style >
.box {
  padding: 30px;
}
h3 {
  margin-left: 50px;
  margin-bottom: 30px;
}
.el-input__inner {
  width: 250px;
}
.btn {
  margin-left: 120px;
}
</style>