<template>
  <a-modal :open="visible" title="新增盘点托盘" cancelText="取消" okText="提交" @ok="submit" @cancel="cancel">
    <a-form ref="formRef" :model="formState" :rules="formRules" :label-col="labelCol" :wrapper-col="wrapperCol">

      <a-form-item ref="invoiceCode" label="盘点单据号" name="invoiceCode">
        <a-input v-model:value="formState.invoiceCode" placeholder="请输入盘点单据号" />
      </a-form-item>
      <a-form-item ref="palletCode" label="托盘号" name="palletCode">
        <a-input v-model:value="formState.palletCode" placeholder="请输入托盘号" />
      </a-form-item>
      <!-- <a-form-item label="状态" name="status">
        <a-select v-model:value="formState.status" :options="pickStatus" placeholder="请选择状态">
        </a-select>
      </a-form-item> -->
      <a-form-item ref="skuCode" label="物料编号" name="skuCode">
        <a-input v-model:value="formState.skuCode" placeholder="请输入物料编号" />
      </a-form-item>
      <a-form-item ref="skuName" label="物料名称" name="skuName">
        <a-input v-model:value="formState.skuName" placeholder="请选择物料名称" />
      </a-form-item>
      <a-form-item ref="batch" label="批次" name="batch">
        <a-input v-model:value="formState.batch" placeholder="请选择批次" />
      </a-form-item>
      <a-form-item ref="serial" label="序列号" name="serial">
        <a-input v-model:value="formState.serial" placeholder="请输入序列号" />
      </a-form-item>
     <a-form-item label="特殊库存" name="spInv">
       <a-select v-model:value="formState.spInv" :options="checkBillDetailSpInv" placeholder="请选择特殊库存">
       </a-select>
     </a-form-item>
     <a-form-item label="库存类型" name="invType">
       <a-select v-model:value="formState.invType" :options="checkBillDetailInvType" placeholder="请选择库存类型">
       </a-select>
     </a-form-item>
      <a-form-item label="质量标志" name="qualityFlag">
        <a-select v-model:value="formState.qualityFlag" :options="pickQualityFlag" placeholder="请选择换质量标志">
        </a-select>
      </a-form-item>
      <a-form-item ref="qty" label="数量" name="qty">
        <a-input v-model:value="formState.qty" placeholder="请输入数量" />
      </a-form-item>
      <a-form-item ref="actQty" label="实际数量" name="actQty">
        <a-input v-model:value="formState.actQty" placeholder="请输入实际数量" />
      </a-form-item>
      <a-form-item ref="unit" label="单位" name="unit">
        <a-input v-model:value="formState.unit" placeholder="请输入单位" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
    import {
    message
  } from '@hwork/ant-design-vue';
  import {
    save
  } from "@/api/wms/checkPlt";
  import {
    defineComponent,
    reactive,
    ref,
    toRaw,
    watch
  } from "vue";
  export default defineComponent({
    props: {
      visible: {
        type: Boolean,
      },
      record: {
        type: Object,
      }
    },
    emit: ["close"],
    setup(props, context) {

      const formRef = ref();
      const checkBillDetailInvType = ref([{
          value: '满托',
          label: '满托',
        },
        {
          value: '非满托',
          label: '非满托',
        },
        {
          value: '混托',
          label: '混托',
        },
        {
          value: '非混托',
          label: '非混托',
        },
      ]);


      const checkBillDetailSpInv = ref([{
        value: '1',
        label: '是',
      }, ]);

      const pickQualityFlag = ref([{
          value: 'Q',
          label: '合格',
        },
        {
          value: 'N',
          label: '不合格',
        },
        {
          value: 'W',
          label: '待检',
        },
        {
          value: 'E',
          label: '免检',
        },
        {
          value: 'T',
          label: '试验料',
        },
        {
          value: 'S',
          label: '待确定',
        },
        {
          value: 'C',
          label: '待验',
        },
        {
          value: 'D',
          label: '冻结',
        },
      ]);



      const formState = reactive({


      });

      watch(props, (props) => {
        formState.itemCode = props.record.itemCode;
      })


      const formRules = {
        groupName: [{
          required: true,
          message: '请输入组名',
          trigger: 'blur'
        }],
        peopleNum: [{
          required: true,
          message: '请输入人数',
          trigger: 'blur',
          type: "number",
        }],
        plantingQty: [{
          required: true,
          message: '请输入种植数量',
          trigger: 'blur',
          type: "number",
        }],
        plantingDate: [{
          required: true,
          message: '请选择种植日期',
          trigger: 'blur',
          type: 'date',
        }],

      };
      const submit = (e) => {
        formRef.value
          .validate()
          .then(() => {
            save(toRaw(formState)).then((response) => {
              console.log("监听报错", response)
              if (response.success) {
                message.success({
                  content: '保存成功',
                  duration: 1
                }).then(() => {
                  cancel();
                });
              } else {
                message.error({
                  content: response.msg,
                  duration: 1
                }).then(() => {
                  // cancel();
                });
              }
            });
          })
          .catch(error => {
            console.log('error', error);
          });
      }


      const cancel = (e) => {
        formRef.value.resetFields();
        context.emit("close", false);
      };
      const handleChange = (e) => {
        context.emit("状态值改变事件", e);
      };
      return {
        submit,
        cancel,
        formRef,
        formState,
        formRules,
        pickQualityFlag,
        checkBillDetailInvType,
        checkBillDetailSpInv,

        labelCol: {
          span: 8
        },
        wrapperCol: {
          span: 12
        },
      };
    },
  });
</script>
