2 天以前 46624ce480a3c14da21f39cc4ad5f7eecea2bb1e
src/views/mes/pro/batch/modules/form.vue
@@ -1,5 +1,5 @@
<script lang="ts" setup>
  import type { FormType } from "../data";
  import type { FormType, PalletOption } from "../data";
  import type { VxeTableGridOptions } from "#/adapter/vxe-table";
  import type { MesProBatchApi } from "#/api/mes/pro/batch";
@@ -15,7 +15,13 @@
  import { useVbenForm } from "#/adapter/form";
  import { TableAction, useVbenVxeGrid } from "#/adapter/vxe-table";
  import { createBatch, getBatch, updateBatch } from "#/api/mes/pro/batch";
  import {
    createBatch,
    fillBatchInfo,
    getBatch,
    updateBatch,
  } from "#/api/mes/pro/batch";
  import { getUnboundPalletList } from "#/api/mes/pro/pallet";
  import { $t } from "#/locales";
  import { UserSelect } from "#/views/system/user/components";
@@ -33,7 +39,7 @@
  const formData = ref<MesProBatchApi.Batch>();
  const isEditable = computed(() =>
    ["create", "update"].includes(formType.value)
    ["create", "update", "fill"].includes(formType.value)
  );
  const getTitle = computed(() => {
@@ -43,6 +49,9 @@
      }
      case "update": {
        return $t("ui.actionTitle.edit", ["生产批次"]);
      }
      case "fill": {
        return "补录批次信息";
      }
      default: {
        return $t("ui.actionTitle.create", ["生产批次"]);
@@ -177,7 +186,9 @@
      modalApi.lock();
      try {
        const data = (await formApi.getValues()) as MesProBatchApi.Batch;
        if (formData.value?.id) {
        if (formType.value === "fill") {
          await fillBatchInfo({ ...data, id: formData.value!.id, workers });
        } else if (formData.value?.id) {
          await updateBatch({ ...data, id: formData.value.id, workers });
        } else {
          await createBatch({ ...data, workers });
@@ -196,7 +207,20 @@
      }
      const data = modalApi.getData<{ formType: FormType; id?: number }>();
      formType.value = data.formType;
      formApi.setState({ schema: useFormSchema(formType.value) });
      // 新增/补录/编辑态加载未绑定批次的托盘,供「绑定托盘」多选下拉使用
      let palletOptions: PalletOption[] = [];
      if (formType.value !== "detail") {
        const pallets = await getUnboundPalletList();
        palletOptions = pallets.map((pallet) => ({
          label: `${pallet.tempCode ?? `托盘${pallet.id}`}(已装 ${pallet.bagCount ?? 0} 袋)`,
          value: pallet.id as number,
        }));
      }
      formApi.setState({ schema: useFormSchema(formType.value, palletOptions) });
      if (formType.value !== "detail") {
        // 清空上次打开时勾选的托盘,避免残留值误触发「批次进入生产中」
        await formApi.setFieldValue("palletIds", undefined);
      }
      // 根据表单态切换人员子表列
      workerGridApi.setGridOptions({
        columns: isEditable.value