<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="所属企业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'companyId', validatorRules.companyId]" placeholder="请输入所属企业" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="所属服务商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'subcontractorId', validatorRules.subcontractorId]" placeholder="请输入所属服务商" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="所属需求" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'requirementId', validatorRules.requirementId]" placeholder="请输入所属需求" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="付款单" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'paymentCode', validatorRules.paymentCode]" 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">
          <a-input-number v-decorator="[ 'taxRate', validatorRules.taxRate]" placeholder="请输入税率（付款时从税率表同步过来）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="计税方式（0：应付计税 1：实付计税）（付款时从税率表同步过来）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'taxType', validatorRules.taxType]" placeholder="请输入计税方式（0：应付计税 1：实付计税）（付款时从税率表同步过来）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="需求名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'requirementName', validatorRules.requirementName]" placeholder="请输入需求名称"></a-input>
        </a-form-item>
          
        <a-form-item label="需求描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['requirementDescription']" rows="4" placeholder="请输入需求描述"/>
        </a-form-item>
          
        <a-form-item label="需求时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择需求时间" v-decorator="[ 'requirmentTime', validatorRules.requirmentTime]" :trigger-change="true" style="width: 100%"/>
        </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="创建时间" :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="状态（0：待复核 1：付款中 2：复核未通过 3：已付款）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'status', validatorRules.status]" placeholder="请输入状态（0：待复核 1：付款中 2：复核未通过 3：已付款）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="复核未通过原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'refuseReason', validatorRules.refuseReason]" 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: "HlgPaymentModal",
    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:{
        companyId:{rules: [{ required: true, message: '请输入所属企业!' }]},
        subcontractorId:{rules: [{ required: true, message: '请输入所属服务商!' }]},
        requirementId:{rules: [{ required: true, message: '请输入所属需求!' }]},
        paymentCode:{rules: [{ required: true, message: '请输入付款单!' }]},
        payment:{rules: [{ required: true, message: '请输入实发总金额!' }]},
        taxRate:{rules: [{ required: true, message: '请输入税率（付款时从税率表同步过来）!' }]},
        taxType:{rules: [{ required: true, message: '请输入计税方式（0：应付计税 1：实付计税）（付款时从税率表同步过来）!' }]},
        requirementName:{},
        requirementDescription:{},
        requirmentTime:{},
        sysOrgCode:{},
        createTime:{rules: [{ required: true, message: '请输入创建时间!' }]},
        createBy:{rules: [{ required: true, message: '请输入创建者!' }]},
        updateTime:{},
        updateBy:{},
        status:{rules: [{ required: true, message: '请输入状态（0：待复核 1：付款中 2：复核未通过 3：已付款）!' }]},
        refuseReason:{},
        delFlag:{rules: [{ required: true, message: '请输入是否删除（0：否 1：是）!' }]},
        },
        url: {
          add: "/hlgpayment/hlgPayment/add",
          edit: "/hlgpayment/hlgPayment/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,'companyId','subcontractorId','requirementId','paymentCode','payment','taxRate','taxType','requirementName','requirementDescription','requirmentTime','sysOrgCode','createTime','createBy','updateTime','updateBy','status','refuseReason','delFlag'))
        })
      },
      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,'companyId','subcontractorId','requirementId','paymentCode','payment','taxRate','taxType','requirementName','requirementDescription','requirmentTime','sysOrgCode','createTime','createBy','updateTime','updateBy','status','refuseReason','delFlag'))
      }
      
    }
  }
</script>