<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应到人数
应到人数">
          <a-input-number v-decorator="[ 'numberOfPeopleToArrive', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="实到人数">
          <a-input-number v-decorator="[ 'actualNumberOfPeople', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="请假">
          <a-input-number v-decorator="[ 'leave', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="旷工">
          <a-input-number v-decorator="[ 'absenteeism', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="离职">
          <a-input-number v-decorator="[ 'quit', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="出勤工时">
          <a-input-number v-decorator="[ 'attendanceHours', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="加班人数">
          <a-input-number v-decorator="[ 'overtimePeople', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="加班工时">
          <a-input-number v-decorator="[ 'overtimeHours', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="加班原因">
          <a-input placeholder="请输入加班原因" v-decorator="['overtimeReason', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工单配料">
          <a-input-number v-decorator="[ 'workOrderBatching', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工单配料-生产订单号">
          <a-input placeholder="请输入工单配料-生产订单号" v-decorator="['batchingProductionOrderNumberCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="成品收存">
          <a-input-number v-decorator="[ 'storageFinishedProducts', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="成品收存-生产订单号">
          <a-input placeholder="请输入成品收存-生产订单号" v-decorator="['productsProductionOrderNumberCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="原材料收存">
          <a-input-number v-decorator="[ 'storageRawMaterials', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="入库单号">
          <a-input placeholder="请输入入库单号" v-decorator="['stockInNumber', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="研发领用">
          <a-input-number v-decorator="[ 'researchAndDevelopment', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="研发领用-出库单号">
          <a-input placeholder="请输入研发领用-出库单号" v-decorator="['developmentDeliveryOrderNo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目配料">
          <a-input-number v-decorator="[ 'projectIngredients', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目配料-出库单号">
          <a-input placeholder="请输入项目配料-出库单号" v-decorator="['projectDeliveryOrderNo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目发货">
          <a-input-number v-decorator="[ 'projectDelivery', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目发货-项目名称">
          <a-input placeholder="请输入项目发货-项目名称" v-decorator="['deliveryProjectName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目打包">
          <a-input-number v-decorator="[ 'packProject', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目打包-项目名称">
          <a-input placeholder="请输入项目打包-项目名称" v-decorator="['packProjectName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="装车">
          <a-input-number v-decorator="[ 'loading', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="装车-项目名称">
          <a-input placeholder="请输入装车-项目名称" v-decorator="['loadingProjectName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="盘点">
          <a-input-number v-decorator="[ 'inventory', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物料编号">
          <a-input placeholder="请输入物料编号" v-decorator="['itemNumber', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="培训">
          <a-input-number v-decorator="[ 'train', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="培训-备注">
          <a-input placeholder="请输入培训-备注" v-decorator="['trainMemo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="会议">
          <a-input-number v-decorator="[ 'meeting', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="会议-备注">
          <a-input placeholder="请输入会议-备注" v-decorator="['meetingMemo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="5S">
          <a-input-number v-decorator="[ 'fiveS', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="5S-备注">
          <a-input placeholder="请输入5S-备注" v-decorator="['fiveSMemo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="其他">
          <a-input-number v-decorator="[ 'other', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="其他-备注">
          <a-input placeholder="请输入其他-备注" v-decorator="['otherMemo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-input placeholder="请输入备注" v-decorator="['memo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="删除标记0正常1删除">
          <a-input placeholder="请输入删除标记0正常1删除" v-decorator="['delFlag', validatorRules.delFlag ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义字段1">
          <a-input placeholder="请输入自定义字段1" v-decorator="['def1', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义字段2">
          <a-input placeholder="请输入自定义字段2" v-decorator="['def2', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义字段3">
          <a-input placeholder="请输入自定义字段3" v-decorator="['def3', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义字段4">
          <a-input placeholder="请输入自定义字段4" v-decorator="['def4', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义字段5">
          <a-input placeholder="请输入自定义字段5" v-decorator="['def5', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "FbsWarehouseModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        delFlag:{rules: [{ required: true, message: '请输入删除标记0正常1删除!' }]},
        },
        url: {
          add: "/fbsWarehouse/fbsWarehouse/add",
          edit: "/fbsWarehouse/fbsWarehouse/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,'numberOfPeopleToArrive','actualNumberOfPeople','leave','absenteeism','quit','attendanceHours','overtimePeople','overtimeHours','overtimeReason','workOrderBatching','batchingProductionOrderNumberCode','storageFinishedProducts','productsProductionOrderNumberCode','storageRawMaterials','stockInNumber','researchAndDevelopment','developmentDeliveryOrderNo','projectIngredients','projectDeliveryOrderNo','projectDelivery','deliveryProjectName','packProject','packProjectName','loading','loadingProjectName','inventory','itemNumber','train','trainMemo','meeting','meetingMemo','fiveS','fiveSMemo','other','otherMemo','memo','delFlag','def1','def2','def3','def4','def5'))
		  //时间格式化
        });

      },
      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()
      },


    }
  }
</script>

<style scoped>

</style>