<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="[ 'subcontractorAccountId', validatorRules.subcontractorAccountId]" 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-number v-decorator="[ 'paymentId', validatorRules.paymentId]" placeholder="请输入所属支付" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="类型（0：入账 1：支付）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'type', validatorRules.type]" placeholder="请输入类型（0：入账 1：支付）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="数额（入账就是转包费用，出账就是支付，都不含服务费）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'amount', validatorRules.amount]" placeholder="请输入数额（入账就是转包费用，出账就是支付，都不含服务费）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="服务费（仅针对入账）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'serviceFee', validatorRules.serviceFee]" placeholder="请输入服务费（仅针对入账）" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="流水号（仅针对入账）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'serialNumber', validatorRules.serialNumber]" 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="生成时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择生成时间" v-decorator="[ 'generateTime', validatorRules.generateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
          
        <a-form-item label="生成者" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'generateBy', validatorRules.generateBy]" placeholder="请输入生成者"></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: "HwSubcontractorAccountDetailModal",
    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:{
        subcontractorAccountId:{rules: [{ required: true, message: '请输入服务商账户总表!' }]},
        requirementId:{rules: [{ required: true, message: '请输入所属需求!' }]},
        paymentId:{rules: [{ required: true, message: '请输入所属支付!' }]},
        type:{rules: [{ required: true, message: '请输入类型（0：入账 1：支付）!' }]},
        amount:{rules: [{ required: true, message: '请输入数额（入账就是转包费用，出账就是支付，都不含服务费）!' }]},
        serviceFee:{},
        serialNumber:{},
        sysOrgCode:{},
        generateTime:{rules: [{ required: true, message: '请输入生成时间!' }]},
        generateBy:{rules: [{ required: true, message: '请输入生成者!' }]},
        },
        url: {
          add: "/subcontratormanager/hwSubcontractorAccountDetail/add",
          edit: "/subcontratormanager/hwSubcontractorAccountDetail/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,'subcontractorAccountId','requirementId','paymentId','type','amount','serviceFee','serialNumber','sysOrgCode','generateTime','generateBy'))
        })
      },
      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,'subcontractorAccountId','requirementId','paymentId','type','amount','serviceFee','serialNumber','sysOrgCode','generateTime','generateBy'))
      }
      
    }
  }
</script>