<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label=" " :colon="false" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <div>
            <div>
              账户余额： ￥20000
            </div>
            <div>
              本次支付： ￥19311.22
            </div>
          </div>
        </a-form-item>
        <a-form-item label="复核结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-model="formData.user" placeholder="请选择用户" dictCode="sys_user,realname,id"/>
        </a-form-item>

        <a-form-item label="拒绝原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea
            placeholder="请输入拒绝原因"
            :autosize="{ minRows: 2, maxRows: 6 }"
          />
        </a-form-item>
        <HlgPaymentRechargeModal ref="RechargeModel"></HlgPaymentRechargeModal>
        <HlgPaymentErrorModal ref="errorModal" @ok="handleReviewAgain"></HlgPaymentErrorModal>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import HlgPaymentRechargeModal from './HlgPaymentRechargeModal'
  import HlgPaymentErrorModal from './HlgPaymentErrorModal'

  export default {
    name: 'HlgPaymentReviewModal',
    components: {
      JDate,
      HlgPaymentRechargeModal,
      HlgPaymentErrorModal
    },
    data() {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },

        confirmLoading: false,
        validatorRules: {
          paymentId: { rules: [{ required: true, message: '请输入支付id!' }] },
          userId: { rules: [{ required: true, message: '请输入用户!' }] }
        },
        url: {
          add: '/hlgpayment/hlgPaymentDetail/add',
          edit: '/hlgpayment/hlgPaymentDetail/edit'
        }

      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true

      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            if (values.success) {

            } else {
              if (values.success) {
                this.$error({
                  title: '失败',
                  content: '余额不足，请充值',
                  okText: '确定',
                  centered: true,
                  onOk: () => {
                    this.$refs.RechargeModel.edit(this.model)
                    this.$refs.RechargeModel.title = '我要充值'
                    this.$refs.RechargeModel.disableSubmit = false
                  }
                })
              }
              if (values.success) {
                this.$refs.errorModal.edit(this.model)
                this.$refs.errorModal.title = '提示'
                this.$refs.errorModal.disableSubmit = false

              }

            }

            // that.confirmLoading = true;
            // let httpurl = '';
            // let method = '';
            // if(!this.model.id){
            //   httpurl+=this.url.add;
            //   method = 'post';
            // }else{
            //   httpurl+=this.url.edit;
            //   method = 'put';
            // }
            // let formData = Object.assign(this.model, values);
            // console.log("表单提交数据",formData)
            // httpAction(httpurl,formData,method).then((res)=>{
            //   if(res.success){
            //     that.$message.success(res.message);
            //     that.$emit('ok');
            //   }else{
            //     that.$message.warning(res.message);
            //   }
            // }).finally(() => {
            //   that.confirmLoading = false;
            //   that.close();
            // })
          }

        })
      },
      handleCancel() {
        this.close()
      },
      handleChange(value) {
        console.log(value)
      },
      handleReviewAgain() {
        // do something
      }
    }
  }
</script>
