<template>
  <a-modal
    v-model="opened"
    :title="title"
    centered
    :maskClosable="false"
    :footer="null"
    @cancel="cancel"
    width="40%">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-form-model
        id="chooseCustom-form"
        ref="ruleForm"
        :model="form"
        :label-col="formItemLayout.labelCol"
        :wrapper-col="formItemLayout.wrapperCol">
        <a-form-model-item label="收款单号:" prop="no"> <span>{{ form.no }}</span>
        </a-form-model-item>
        <a-form-model-item label="付款方:" prop="payerName"> <span>{{ form.payerName }}</span>
        </a-form-model-item>
        <a-form-model-item label="备注:" prop="remarks">
          <a-textarea
            v-model="form.remarks"
            placeholder="请输入备注(最多100字符)"
            :auto-size="{ minRows: 3, maxRows: 5 }"
            :maxLength="100"
          />
        </a-form-model-item>
        <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;margin-top: 50px;">
          <a-button @click="cancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
          <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">确定
          </a-button>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import {
  updateFinanceBookDetail
} from '@/api/financeBook.js'
export default {
  name: 'NoteModal',
  props: {
    show: [Boolean]
  },
  data () {
    return {
      opened: this.show,
      spinning: false,
      title: '备注',

      confirmLoading: false,
      formItemLayout: {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 18
        }
      },
      form: {
        no: undefined,
        payerName: undefined,
        remarks: '',
        id: ''
      }
    }
  },
  methods: {
    //  保存
    handleSubmit () {
      const _this = this
      const ajax_form = {
        id: this.form.id,
        remarks: this.form.remarks
      }
      _this.spinning = true
      _this.confirmLoading = true
      updateFinanceBookDetail(ajax_form).then(res => {
        if (res.status == 200) {
          _this.$message.success(res.message)
          _this.cancel()
          _this.spinning = false
        } else {
          _this.spinning = false
        }
        _this.confirmLoading = false
      })
    },
    cancel () {
      this.opened = false
      this.$emit('cancel')
      this.$refs.ruleForm.resetFields()
    },
    setData (data) {
      this.form = JSON.parse(data)
    }
  },
  watch: {
    show (newValue, oldValue) {
      this.opened = newValue
      if (!newValue) {
        this.cancel()
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .ant-form-item{
    margin-bottom:0 !important;
  }
</style>
