<template>
  <el-dialog class="contact-dialog"
             title="作废借款" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">

    <div class="input">
      <el-form :model="contact" ref="contactForm" :label-width="'100px'">
        <el-form-item label="作废意见:" prop="content">
          <el-input type="textarea" row="3" v-model="memo"></el-input>
        </el-form-item>
      </el-form>
    </div>

    <div slot="footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="submitClick">作 废</el-button>
    </div>
  </el-dialog>
</template>

<script type="text/ecmascript-6">


  export default {
    name: 'CancelLoanDialog',
    props: {
      dialogVisible: {
        type: Boolean
      },
      loanNo: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        contact: {},
        memo: '',
        visible: this.$props.dialogVisible,
      }
    },
    methods: {
      submitClick() {
        this.$$post('/loanRecord/cancel', {loanNo: this.loanNo, memo: this.memo}).then(res => {
          if (res.data.code < 1) {
            this.$message.error(res.data.msg);
            return
          }
          this.$message({message: '操作成功', type: 'success'});
          this.handleClose();
        })

      },
      /** 关闭处理 */
      handleClose() {
        this.visible = false;
        setTimeout(() => {
          this.$emit('update:dialogVisible', false)
        }, 100);
        window.location.reload();
      }
    }
  }
</script>
<style lang="stylus" rel="stylesheet/stylus">

  .client-contact-dialog {
    .input {
      width 60%
      margin auto
    }
  }

</style>
