<template>
  <a-modal
    v-model="opened"
    :title="title"
    centered
    :maskClosable="false"
    :footer="null"
    @cancel="cancel"
    width="500px">
    <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 }}{{ form.printStatus=='UNABLE_PRINT'?'（暂不打印）':form.printStatus=='CANCEL_PRINT'?'（取消打印）':'' }}</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="printStatus">
          <a-radio-group v-model="printStatus">
            <a-radio value="NO_PRINT">
              允许打印
            </a-radio>
            <a-radio value="CANCEL_PRINT" v-if="form.printStatus=='UNABLE_PRINT'">
              取消打印
            </a-radio>
          </a-radio-group>
        </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: 'PrintModal',
  props: {
    show: [Boolean],
    info: {
      type: Object,
      default: () => {
        return null
      }
    }
  },
  data () {
    return {
      opened: this.show,
      spinning: false,
      title: '收款打印状态',
      confirmLoading: false,
      formItemLayout: {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 18
        }
      },
      form: {
        no: undefined,
        payerName: undefined,
        printStatus: '',
        id: '',
        type: undefined
      },
      printStatus: '',
    }
  },
  methods: {
    //  保存
    handleSubmit () {
      const _this = this
      const ajax_form = {
        id: this.form.id,
        printStatus: this.printStatus
      }
      if(!this.printStatus){
        this.$message.info("请选择收款打印状态")
        return
      }
      
      _this.spinning = true
      _this.confirmLoading = true
      updateFinanceBookDetail(ajax_form,0).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.printStatus = ''
      this.$refs.ruleForm.resetFields()
    }
  },
  watch: {
    show (newValue, oldValue) {
      this.opened = newValue
      if (!newValue) {
        this.printStatus = ''
        this.$refs.ruleForm.resetFields()
      } else {
        this.form = this.info
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .ant-form-item{
    margin-bottom:0 !important;
  }
</style>
