<template>
  <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="700px" append-to-body>
    <el-form ref="form" :model="form" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="转账备注" prop="transRemark">
            <el-input v-model="form.transRemark" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import ImageUpload from '@/components/ImageUpload/index'
import { getBorrow, updateBorrow } from '@/api/dk/borrow'

export default {
    components: {
      ImageUpload,
    },
    data () {
      return {
        open: false,
        title: '',
        form:{
          id: undefined,
          transRemark: ' ',
        },
        buttonLoading: false,
      }
    },
    created() {
    },
    methods: {
      init (id) {
        this.form.id = id || undefined;
        this.open = true;
        this.$nextTick(() => {
          this.$refs['form'].resetFields();
          getBorrow(id).then(response => {
            this.form.id = response.data.id;
            this.form.transRemark = response.data.transRemark;
            this.open = true;
            this.title = "修改转账备注信息";
          });
        })
      },
      // 表单提交
      submitForm () {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.buttonLoading = true;
            updateBorrow({
              id: this.form.id,
              transRemark: this.form.transRemark || " ",
            }).then(data => {
                this.$modal.msgSuccess("修改成功");
                this.buttonLoading = false;
                this.open = false
                this.$emit('refreshDataList')
            }).catch(() => {
                this.buttonLoading = false;
            });
          }
        })
      },
    }
  }
</script>
