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
<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 { bindBagCodeBatch } from "#/api/mes/pro/bagCode";
  import { getBatchSimpleList } from "#/api/mes/pro/batch";
  import { $t } from "#/locales";
 
  defineOptions({ name: "MesProBagCodeBindBatch" });
 
  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 bindBagCodeBatch({ 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>