<template>
  <a-modal
    v-model="opened"
    :title="title"
    centered
    :maskClosable="false"
    :footer="null"
    @cancel="cancel"
    width="550px">
    <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 {
  updateDetailInvoiceDate
} from '@/api/financeBook.js'
export default {
  name: 'NoteModal',
  props: {
    show: [Boolean]
  },
  data () {
    return {
      opened: this.show,
      spinning: false,
      title: '备注',

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