<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="支付id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'paymentId', validatorRules.paymentId]" placeholder="请输入支付id" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="订单id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'orderId', validatorRules.orderId]" placeholder="请输入订单id" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="用户" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'userId', validatorRules.userId]" placeholder="请输入用户" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="账户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'userName', validatorRules.userName]" placeholder="请输入账户姓名"></a-input>
        </a-form-item>
          
        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'idcardNumber', validatorRules.idcardNumber]" placeholder="请输入身份证号"></a-input>
        </a-form-item>
          
        <a-form-item label="银行卡号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cardNumber', validatorRules.cardNumber]" placeholder="请输入银行卡号"></a-input>
        </a-form-item>
          
        <a-form-item label="支付总额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'payment', validatorRules.payment]" placeholder="请输入支付总额" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择创建时间" v-decorator="[ 'createTime', validatorRules.createTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="创建者" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'createBy', validatorRules.createBy]" placeholder="请输入创建者"></a-input>
        </a-form-item>
          
        <a-form-item label="更新时间（第一次创建时，请将创建时间同步至更新时间，后续操作只修改更新时间，便于页面展示）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择更新时间（第一次创建时，请将创建时间同步至更新时间，后续操作只修改更新时间，便于页面展示）" v-decorator="[ 'updateTime', validatorRules.updateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="更新者（第一次创建时，请将创建者同步至更新者，后续操作只修改更新者，便于页面展示）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'updateBy', validatorRules.updateBy]" placeholder="请输入更新者（第一次创建时，请将创建者同步至更新者，后续操作只修改更新者，便于页面展示）"></a-input>
        </a-form-item>
          
        <a-form-item label="数据权限" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sysOrgCode', validatorRules.sysOrgCode]" placeholder="请输入数据权限"></a-input>
        </a-form-item>
          
        <a-form-item label="状态（0：待付款 1：付款中 2：付款成功 3：付款失败 4：已补发）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'status', validatorRules.status]" placeholder="请输入状态（0：待付款 1：付款中 2：付款成功 3：付款失败 4：已补发）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="失败原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'failureReason', validatorRules.failureReason]" placeholder="请输入失败原因"></a-input>
        </a-form-item>
          
        <a-form-item label="是否删除（0：未删除 1：已删除）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'delFlag', validatorRules.delFlag]" placeholder="请输入是否删除（0：未删除 1：已删除）"></a-input>
        </a-form-item>
          
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "HwPaymentDetailModal",
    components: { 
      JDate,
    },
    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!' }]},
        orderId:{rules: [{ required: true, message: '请输入订单id!' }]},
        userId:{rules: [{ required: true, message: '请输入用户!' }]},
        userName:{rules: [{ required: true, message: '请输入账户姓名!' }]},
          paymentBy:{rules: [{ required: true, message: '请输入账户姓名!' }]},
        idcardNumber:{rules: [{ required: true, message: '请输入身份证号!' }]},
        cardNumber:{rules: [{ required: true, message: '请输入银行卡号!' }]},
        payment:{rules: [{ required: true, message: '请输入支付总额!' }]},
        createTime:{rules: [{ required: true, message: '请输入创建时间!' }]},
        createBy:{rules: [{ required: true, message: '请输入创建者!' }]},
        updateTime:{rules: [{ required: true, message: '请输入更新时间（第一次创建时，请将创建时间同步至更新时间，后续操作只修改更新时间，便于页面展示）!' }]},
        updateBy:{rules: [{ required: true, message: '请输入更新者（第一次创建时，请将创建者同步至更新者，后续操作只修改更新者，便于页面展示）!' }]},
        sysOrgCode:{},
        status:{rules: [{ required: true, message: '请输入状态（0：待付款 1：付款中 2：付款成功 3：付款失败 4：已补发）!' }]},
        failureReason:{},
        delFlag:{rules: [{ required: true, message: '请输入是否删除（0：未删除 1：已删除）!' }]},
        },
        url: {
          add: "/hwpayment/hwPaymentDetail/add",
          edit: "/hwpayment/hwPaymentDetail/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'paymentId','orderId','userId','userName','idcardNumber','cardNumber','payment','createTime','createBy','updateTime','updateBy','sysOrgCode','status','failureReason','delFlag','paymentBy'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            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()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'paymentId','orderId','userId','userName','idcardNumber','cardNumber','payment','createTime','createBy','updateTime','updateBy','sysOrgCode','status','failureReason','delFlag','paymentBy'))
      }
      
    }
  }
</script>