2 天以前 d2cd585f4d3b015789a5f6c8d75e352605932f85
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<script lang="ts" setup>
  import type { VbenFormSchema } from "#/adapter/form";
  import type { MesProBagCodeApi } from "#/api/mes/pro/bagCode";
 
  import { useVbenModal } from "@vben/common-ui";
 
  import { message } from "ant-design-vue";
 
  import { useVbenForm } from "#/adapter/form";
  import { replaceBagCodes } from "#/api/mes/pro/bagCode";
 
  defineOptions({ name: "MesProBagCodeReplaceForm" });
 
  interface ModalData {
    batchId: number;
    batchCode?: string;
    ids: number[];
  }
 
  const emit = defineEmits<{
    success: [result: MesProBagCodeApi.ReplaceResult];
  }>();
 
  const schema: VbenFormSchema[] = [
    {
      fieldName: "batchCode",
      label: "生产批次",
      component: "Input",
      componentProps: {
        disabled: true,
      },
    },
    {
      fieldName: "bagCount",
      label: "替换袋数",
      component: "InputNumber",
      componentProps: {
        class: "!w-full",
        disabled: true,
      },
    },
    {
      fieldName: "reason",
      label: "破损原因",
      component: "Textarea",
      formItemClass: "col-span-2",
      componentProps: {
        maxlength: 255,
        placeholder: "请输入破损原因",
        rows: 3,
        showCount: true,
      },
      rules: "required",
    },
  ];
 
  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 {
        const result = await replaceBagCodes({
          batchId: data.batchId,
          oldIds: data.ids,
          reason: values.reason,
        });
        message.success(`已成功替换 ${result.count ?? data.ids.length} 个袋码`);
        emit("success", result);
        await modalApi.close();
      } finally {
        modalApi.unlock();
      }
    },
    onOpenChange(isOpen: boolean) {
      if (!isOpen) return;
      const data = modalApi.getData<ModalData>();
      void formApi.setValues({
        bagCount: data.ids.length,
        batchCode: data.batchCode,
        reason: undefined,
      });
    },
  });
</script>
 
<template>
  <Modal title="破损袋码替换" class="w-2/5">
    <Form class="mx-4" />
  </Modal>
</template>