11 小时以前 08bb5d242135e2c1f0fc17d2b5f7ae548275a3a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<script lang="ts" setup>
  import type { VbenFormSchema } from "#/adapter/form";
 
  import { useVbenModal } from "@vben/common-ui";
  import { MesProBatchStatusEnum } from "@vben/constants";
 
  import { message } from "ant-design-vue";
 
  import { useVbenForm } from "#/adapter/form";
  import { getBatchSimpleList } from "#/api/mes/pro/batch";
  import { bindPalletBatch } from "#/api/mes/pro/pallet";
  import { $t } from "#/locales";
 
  defineOptions({ name: "MesProPalletBindBatch" });
 
  interface ModalData {
    ids: number[];
  }
 
  const emit = defineEmits(["success"]);
 
  const [Form, formApi] = useVbenForm({
    commonConfig: {
      componentProps: {
        class: "w-full",
      },
      labelWidth: 100,
    },
    layout: "horizontal",
    schema: [],
    showDefaultActions: false,
  });
 
  const [Modal, modalApi] = useVbenModal({
    async onConfirm() {
      const { valid } = await formApi.validate();
      if (!valid) return;
      const data = modalApi.getData<ModalData>();
      const values = await formApi.getValues();
      modalApi.lock();
      try {
        await bindPalletBatch({ batchId: values.batchId, ids: data.ids });
        message.success($t("ui.actionMessage.operationSuccess"));
        emit("success");
        await modalApi.close();
      } finally {
        modalApi.unlock();
      }
    },
    async onOpenChange(isOpen: boolean) {
      if (!isOpen) return;
      modalApi.lock();
      try {
        // 仅已补录正式信息且生产中的批次允许绑定
        const batches = await getBatchSimpleList();
        const options = batches
          .filter(
            (batch) =>
              batch.status === MesProBatchStatusEnum.PRODUCING && batch.code,
          )
          .map((batch) => ({ label: batch.code!, value: batch.id! }));
        const schema: VbenFormSchema[] = [
          {
            fieldName: "batchId",
            label: "生产批次",
            component: "Select",
            componentProps: {
              options,
              optionFilterProp: "label",
              placeholder: "请选择已补录且生产中的批次",
              showSearch: true,
            },
            rules: "selectRequired",
          },
        ];
        await formApi.setState({ schema });
      } finally {
        modalApi.unlock();
      }
    },
  });
</script>
 
<template>
  <Modal title="托盘码绑定生产批次" class="w-2/5">
    <Form class="mx-4" />
  </Modal>
</template>