<!-- <template>
  <a-modal :open="visible" title="新增托盘出入库记录" cancelText="取消" okText="提交" @ok="submit" @cancel="cancel" :width='1200'>
    <a-form ref="formRef" :model="formState" :rules="formRules" :label-col="labelCol" :wrapper-col="wrapperCol">
      <div>
        <page-layout>
          <a-row :gutter="[0, 0]">
            <a-col :span="24">
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="invoiceCode" label="单据号" name="invoiceCode">
                    <a-input v-model:value="formState.invoiceCode" placeholder="请输入单据号" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="taskCode" label="任务号" name="taskCode">
                    <a-input v-model:value="formState.taskCode" placeholder="请输入任务号" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="方向标志" name="directFlag">
                    <a-select v-model:value="formState.directFlag" placeholder="请选择方向标志" :options="directFlags">
                    </a-select>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="palletCode" label="托盘号" name="palletCode">
                    <a-input v-model:value="formState.palletCode" placeholder="请输入托盘号" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="skuCode" label="物料编号" name="skuCode">
                    <a-input v-model:value="formState.skuCode" placeholder="请输入物料编号" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="skuName" label="物料描述" name="skuName">
                    <a-input v-model:value="formState.skuName" placeholder="请输入物料描述" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="skuType" label="物料类型" name="skuType">
                    <a-input v-model:value="formState.skuType" placeholder="请输入物料类型" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="batch" label="批次" name="batch">
                    <a-input v-model:value="formState.batch" placeholder="请输入批次" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="serial" label="序列号" name="serial">
                    <a-input v-model:value="formState.serial" placeholder="请输入序列号" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="master" label="货主" name="master">
                    <a-input v-model:value="formState.master" placeholder="请输入货主" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="producer" label="厂家" name="producer">
                    <a-input v-model:value="formState.producer" placeholder="请输入厂家" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="customer" label="客户" name="customer">
                    <a-input v-model:value="formState.customer" placeholder="请输入客户" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="produceDate" label="生产日期" name="produceDate">
                    <a-date-picker v-model:value="formState.produceDate" style="width: 100%" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="overdue" label="过期日期" name="overdue">
                    <a-date-picker v-model:value="formState.overdue" style="width: 100%" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="skuQty" label="物料数量" name="skuQty">
                    <a-input v-model:value="formState.skuQty" placeholder="请输入物料数量" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="baseUnit" label="物流单位" name="baseUnit">
                    <a-input v-model:value="formState.baseUnit" placeholder="请输入物流单位" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="convertQty" label="换算数量" name="convertQty">
                    <a-input v-model:value="formState.convertQty" placeholder="请输入换算数量" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="primaryUnit" label="换算单位" name="primaryUnit">
                    <a-input v-model:value="formState.primaryUnit" placeholder="请输入换算单位" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item label="特殊库存" name="spInv">
                    <a-select v-model:value="formState.spInv" placeholder="请选择特殊库存" :options="spInvs">
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="invType" label="库存类型" name="invType">
                    <a-input v-model:value="formState.invType" placeholder="请输入库存类型" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="质量状态" name="qualityStatus">
                    <a-select v-model:value="formState.qualityStatus" placeholder="请选择质量状态" :options="qualityStatuss">
                    </a-select>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="weight" label="重量" name="weight">
                    <a-input v-model:value="formState.weight" placeholder="请输入重量" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="weightUnit" label="重量单位" name="weightUnit">
                    <a-input v-model:value="formState.weightUnit" placeholder="请输入重量单位" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="sourceLoc" label="源位置" name="sourceLoc">
                    <a-input v-model:value="formState.sourceLoc" placeholder="请输入源位置" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-item ref="targetLoc" label="目标位置" name="targetLoc">
                    <a-input v-model:value="formState.targetLoc" placeholder="请输入目标位置" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item ref="finishDate" label="完成时间" name="finishDate">
                    <a-date-picker v-model:value="formState.finishDate" style="width: 100%" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="备注" name="remark">
                    <a-textarea v-model:value="formState.remark" />
                  </a-form-item>
                </a-col>
              </a-row>
            </a-col>
          </a-row>
        </page-layout>
      </div>
    </a-form>
  </a-modal>
</template>
<script>
    import {
    message
  } from '@hwork/ant-design-vue';
  import {
    save,
  } from "@/api/wms/palletLog";
  import {
    defineComponent,
    reactive,
    ref,
    toRaw,
    watch,
  } from "vue";
  export default defineComponent({
    props: {
      visible: {
        type: Boolean,
      },
    },
    emit: ["close"],
    setup(props, context) {

      const formRef = ref();

      const state = reactive({});

      const formState = reactive({});

      const directFlags = ref([{
        value: 'In',
        label: '向里',
      }, {
        value: 'Out',
        label: '向外',
      }, {
        value: 'Move',
        label: '移动',
      }]);

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

      const qualityStatuss = 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 formRules = {
        invoiceCode: [{
          required: true,
          message: '请输入单据号',
          trigger: 'blur'
        }],
        taskCode: [{
          required: true,
          message: '请输入任务号',
          trigger: 'blur'
        }],
        directFlag: [{
          required: true,
          message: '请选择方向标志',
          trigger: 'blur'
        }],
        palletCode: [{
          required: true,
          message: '请输入托盘号',
          trigger: 'blur'
        }],
        skuCode: [{
          required: true,
          message: '请输入物料编号',
          trigger: 'blur'
        }],
        skuName: [{
          required: true,
          message: '请输入物料名称',
          trigger: 'blur'
        }],
        skuType: [{
          required: true,
          message: '请输入物料类别',
          trigger: 'blur'
        }],
        skuQty: [{
          required: true,
          message: '请输入物料数量',
          trigger: 'blur',
        }],
        baseUnit: [{
          required: true,
          message: '请输入物流单位',
          trigger: 'blur',
        }],
        convertQty: [{
          required: true,
          message: '请输入换算数量',
          trigger: 'blur',
        }],
        primaryUnit: [{
          required: true,
          message: '请输入换算单位',
          trigger: 'blur',
        }],
        sourceLoc: [{
          required: true,
          message: '请输入源位置',
          trigger: 'blur',
        }],
        targetLoc: [{
          required: true,
          message: '请输入目标位置',
          trigger: 'blur',
        }],
      }
      const saveKey = "save";

      const submit = (e) => {
        message.loading({
          content: '提交中...',
          key: saveKey
        });
        formRef.value
          .validate()
          .then(() => {
            save(toRaw(formState)).then((response) => {
              if (response.success) {
                message.success({
                  content: '保存成功',
                  key: saveKey,
                  duration: 1
                }).then(() => {
                  cancel();
                });
              } else {
                message.error({
                  content: response.msg,
                  key: saveKey,
                  duration: 1
                }).then(() => {
                  // cancel();
                });
              }
            });
          })
          .catch(error => {
            console.log('error', error);
          });
      };

      const cancel = (e) => {
        formRef.value.resetFields();
        context.emit("close", false);
      };

      return {
        state,
        submit,
        cancel,
        formRef,
        formState,
        directFlags,
        spInvs,
        qualityStatuss,
        formRules,
        labelCol: {
          span: 8
        },
        wrapperCol: {
          span: 12
        },
      };
    },
  });
</script> -->
