zhangwencui
2026-04-24 759f41097324fa1ade4060fc838d700d8c8fa55f
src/views/productionManagement/processRoute/index.vue
@@ -48,6 +48,14 @@
                     v-model:visible="isShowItemModal"
                     :record="record"
                     @completed="getList" />
    <FileListDialog ref="fileListDialogRef"
                    v-model="fileDialogVisible"
                    :show-upload-button="true"
                    :show-delete-button="true"
                    :delete-method="handleAttachmentDelete"
                    :process-route-id="currentProcessRouteId"
                    :name-column-label="'附件名称'"
                    @upload="handleAttachmentUpload" />
  </div>
</template>
@@ -57,7 +65,14 @@
  import EditProcess from "@/views/productionManagement/processRoute/Edit.vue";
  import RouteItemForm from "@/views/productionManagement/processRoute/ItemsForm.vue";
  import { listPage, del } from "@/api/productionManagement/processRoute.js";
  import {
    listProcessRouteFiles,
    addProcessRouteFile,
    delProcessRouteFile,
  } from "@/api/productionManagement/processRouteFile.js";
  import FileListDialog from "@/components/Dialog/FileListDialog.vue";
  import { useRouter } from "vue-router";
  import { ElMessage, ElMessageBox } from "element-plus";
  const router = useRouter();
  const data = reactive({
@@ -108,6 +123,13 @@
            showItemModal(row);
          },
        },
        {
          name: "附件",
          type: "text",
          clickFun: row => {
            openFileDialog(row);
          },
        },
      ],
    },
  ]);
@@ -123,8 +145,79 @@
    size: 100,
    total: 0,
  });
  // 附件相关
  const fileDialogVisible = ref(false);
  const fileListDialogRef = ref(null);
  const currentProcessRouteId = ref(null);
  const filePage = reactive({
    current: 1,
    size: 1000,
    total: 0,
  });
  const { proxy } = getCurrentInstance();
  // 附件:查询
  const fetchProcessRouteFiles = async processRouteId => {
    const params = {
      current: filePage.current,
      size: filePage.size,
      processRouteId,
    };
    const res = await listProcessRouteFiles(params);
    const records = res?.data?.records || [];
    filePage.total = res?.data?.total || records.length;
    const mapped = records.map(item => ({
      id: item.id,
      name: item.fileName || item.name,
      url: item.fileUrl || item.url,
      raw: item,
    }));
    fileListDialogRef.value?.setList(mapped);
  };
  // 打开附件弹窗
  const openFileDialog = async row => {
    currentProcessRouteId.value = row.id;
    fileDialogVisible.value = true;
    await fetchProcessRouteFiles(row.id);
  };
  // 刷新附件列表
  const refreshFileList = async () => {
    if (!currentProcessRouteId.value) return;
    await fetchProcessRouteFiles(currentProcessRouteId.value);
  };
  // 上传附件
  const handleAttachmentUpload = async filePayload => {
    if (!currentProcessRouteId.value) return;
    const payload = {
      fileName: filePayload?.fileName || filePayload?.name,
      fileUrl: filePayload?.fileUrl || filePayload?.url,
      processRouteId: currentProcessRouteId.value,
    };
    await addProcessRouteFile(payload);
    ElMessage.success("文件上传成功");
    await refreshFileList();
  };
  // 删除附件
  const handleAttachmentDelete = async row => {
    if (!row?.id) return false;
    try {
      await ElMessageBox.confirm("确认删除该附件?", "提示", {
        type: "warning",
      });
    } catch {
      return false;
    }
    await delProcessRouteFile([row.id]);
    ElMessage.success("删除成功");
    await refreshFileList();
  };
  // 查询列表
  /** 搜索按钮操作 */
  const handleQuery = () => {