<template>
  <a-modal
    :title="title"
    :visible="visible"
    :width="width"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    okText="确认退款"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="退款总金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <div style="font-size: 16px;">{{model.totalAmount}}</div>
        </a-form-item>

        <a-form-item label=" " :colon="false" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <div style="color: #1890ff">将扣除账户余额{{model.amount}}元，服务费{{model.serviceFee}}元</div>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { Arithmetic } from '@/mixins/Arithmetic'
  import { httpAction, putAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'HlgAccountRefundModal',
    mixins: [Arithmetic],
    components: {
      JDate

    },
    data() {
      return {
        title: '退款',
        bodyStyle: {
          paddingTop: '30px',
          paddingBottom: '20px',
          'overflow-y': 'auto'
        },
        width: 800,
        serviceRate: 0,
        service_charge: '0.00',
        real_money: '0.00',
        isDisplay: 0,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        form: this.$form.createForm(this),
        disableSubmit: false,
        confirmLoading: false,
        url: {
          refund: '/hlgaccount/hlgAccountDetail/refundA_B'
        }

      }
    },
    mounted() {

    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.model = Object.assign({}, record)
        this.visible = true
      },
      close() {
        this.visible = false
      },
      handleOk() {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.confirmLoading = true
            let formData = Object.assign(this.model, values)
            putAction(this.url.refund, formData).then(data => {

              if (data.success) {
                this.$message.success('退款成功')
                this.$emit('ok')
                this.close()
              } else {
                this.$error({
                  title: '退款失败',
                  content: data.message,
                  okText: '确定',
                  centered: true
                })
              }
              if (data.code === 510) {
                this.$message.warning(res.message)
              }
              this.confirmLoading = false
            })
          }
        })
      },
      handleCancel() {
        this.close()
      },

      //验证金额
      checkMoney(rule, value, callback) {
        const _number = Number(value)
        if (_number <= 0 && value !== '') {
          callback('金额不可小于等于0！')
        }
        if (isNaN(_number)) {
          callback('格式错误！')
        }

        if (_number > this.canRefund) {
          callback('输入金额大于可退款金额！')
        }

        callback()
      },
      //监听隐藏/显示
      editDisplay(e) {
        if (e != null && e != '') {
          this.form.setFieldsValue({ isDisplay: e })
        }
        var isDisplay = this.form.getFieldValue('isDisplay')
        this.model.isDisplay = isDisplay
      },
      //全部
      inputAll() {
        this.form.setFieldsValue({
          refundAmount: this.canRefund
        })
      },
      //退款金额监听
      subServiceFeeChange(value){
        this.service_charge = this.fix(this.accMul(value || 0, this.accDiv(this.serviceRate, 100)))
        this.real_money = this.fix(this.accSub(value || 0, this.service_charge || 0))
      },
    }
  }
</script>