From 27c8277d717b34b55f3ea967027b53b067f77df3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 20 八月 2026 16:58:49 +0800
Subject: [PATCH] feat 功能变更

---
 src/views/erp/purchase/plan/index.vue |  300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 300 insertions(+), 0 deletions(-)

diff --git a/src/views/erp/purchase/plan/index.vue b/src/views/erp/purchase/plan/index.vue
new file mode 100644
index 0000000..671a09f
--- /dev/null
+++ b/src/views/erp/purchase/plan/index.vue
@@ -0,0 +1,300 @@
+<script lang="ts" setup>
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { ErpPurchasePlanApi } from '#/api/erp/purchase/plan';
+
+import { ref } from 'vue';
+import { useRouter } from 'vue-router';
+
+import { confirm, Page, useVbenModal } from '@vben/common-ui';
+import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
+
+import { message, Tag } from 'ant-design-vue';
+
+import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
+import {
+  deletePurchasePlan,
+  exportPurchasePlan,
+  generatePlanFromStockAlert,
+  generatePurchaseRequests,
+  getApproveProcessList,
+  getPurchasePlanPage,
+} from '#/api/erp/purchase/plan';
+import { $t } from '#/locales';
+
+import { useGridColumns, useGridFormSchema } from './data';
+import Form from './modules/form.vue';
+import ProcessSelectModal from './modules/process-select-modal.vue';
+
+/** ERP 閲囪喘璁″垝鍒楄〃 */
+defineOptions({ name: 'ErpPurchasePlan' });
+
+const router = useRouter();
+
+const [FormModal, formModalApi] = useVbenModal({
+  connectedComponent: Form,
+  destroyOnClose: true,
+});
+
+const [ProcessModal, processModalApi] = useVbenModal({
+  connectedComponent: ProcessSelectModal,
+  destroyOnClose: true,
+});
+
+/** 鍒锋柊琛ㄦ牸 */
+function handleRefresh() {
+  gridApi.query();
+}
+
+/** 瀵煎嚭琛ㄦ牸 */
+async function handleExport() {
+  const data = await exportPurchasePlan(await gridApi.formApi.getValues());
+  downloadFileFromBlobPart({ fileName: '閲囪喘璁″垝.xls', source: data });
+}
+
+/** 鏂板閲囪喘璁″垝 */
+function handleCreate() {
+  formModalApi.setData({ formType: 'create' }).open();
+}
+
+/** 缂栬緫閲囪喘璁″垝 */
+function handleEdit(row: ErpPurchasePlanApi.PurchasePlan) {
+  formModalApi.setData({ formType: 'edit', id: row.id }).open();
+}
+
+/** 鍒犻櫎閲囪喘璁″垝 */
+async function handleDelete(ids: number[]) {
+  const hideLoading = message.loading({
+    content: $t('ui.actionMessage.deleting'),
+    duration: 0,
+  });
+  try {
+    await deletePurchasePlan(ids);
+    message.success($t('ui.actionMessage.deleteSuccess'));
+    handleRefresh();
+  } finally {
+    hideLoading();
+  }
+}
+
+/** 搴撳瓨棰勮鐢熸垚閲囪喘璁″垝 */
+async function handleGenerateFromStockAlert() {
+  const hideLoading = message.loading({
+    content: '姝e湪鏍规嵁搴撳瓨棰勮鐢熸垚閲囪喘璁″垝...',
+    duration: 0,
+  });
+  try {
+    const planId = await generatePlanFromStockAlert({});
+    hideLoading();
+    message.success(`宸茬敓鎴愰噰璐鍒掞紙缂栧彿 ${planId}锛夛紝璇锋牳瀵规槑缁嗗悗鎻愪氦瀹℃壒`);
+    handleRefresh();
+  } catch {
+    hideLoading();
+  }
+}
+
+/** 鎻愪氦瀹℃壒 - 鍏堣幏鍙栨祦绋嬪垪琛� */
+async function handleSubmit(row: ErpPurchasePlanApi.PurchasePlan) {
+  const hideLoading = message.loading({
+    content: '鑾峰彇瀹℃壒娴佺▼...',
+    duration: 0,
+  });
+  try {
+    const processList = await getApproveProcessList(row.id!);
+    hideLoading();
+    if (!processList || processList.length === 0) {
+      message.warning('鏆傛棤鍙敤瀹℃壒娴佺▼锛岃鍏堥厤缃� BPM 娴佺▼');
+      return;
+    }
+    processModalApi.setData({ id: row.id, processList }).open();
+  } catch {
+    hideLoading();
+  }
+}
+
+/** 鐢熸垚閲囪喘鐢宠 */
+function handleGenerateRequests(row: ErpPurchasePlanApi.PurchasePlan) {
+  confirm({
+    content: `纭鏍规嵁璁″垝銆�${row.name}銆嶇敓鎴愰噰璐敵璇凤紵`,
+  }).then(() => {
+    const hideLoading = message.loading({
+      content: '姝e湪鐢熸垚閲囪喘鐢宠...',
+      duration: 0,
+    });
+    generatePurchaseRequests(row.id!)
+      .then((requestIds) => {
+        message.success(`宸茬敓鎴愰噰璐敵璇凤紙缂栧彿 ${requestIds.join(', ')}锛塦);
+        handleRefresh();
+      })
+      .finally(() => {
+        hideLoading();
+      });
+  });
+}
+
+const checkedIds = ref<number[]>([]);
+function handleRowCheckboxChange({
+  records,
+}: {
+  records: ErpPurchasePlanApi.PurchasePlan[];
+}) {
+  checkedIds.value = records.map((item) => item.id!);
+}
+
+/** 鏌ョ湅璇︽儏 */
+function handleDetail(row: ErpPurchasePlanApi.PurchasePlan) {
+  formModalApi.setData({ formType: 'detail', id: row.id }).open();
+}
+
+/** 鏌ョ湅瀹℃壒璇︽儏 */
+function handleViewProcess(row: ErpPurchasePlanApi.PurchasePlan) {
+  if (!row.processInstanceId) {
+    message.warning('璇ヨ鍒掑皻鏈彁浜ゅ鎵�');
+    return;
+  }
+  router.push({ name: 'BpmProcessInstanceDetail', query: { id: row.processInstanceId } });
+}
+
+const [Grid, gridApi] = useVbenVxeGrid({
+  formOptions: {
+    schema: useGridFormSchema(),
+  },
+  gridOptions: {
+    columns: useGridColumns(),
+    height: 'auto',
+    keepSource: true,
+    proxyConfig: {
+      ajax: {
+        query: async ({ page }, formValues) => {
+          return await getPurchasePlanPage({
+            pageNo: page.currentPage,
+            pageSize: page.pageSize,
+            ...formValues,
+          });
+        },
+      },
+    },
+    rowConfig: {
+      keyField: 'id',
+      isHover: true,
+    },
+    toolbarConfig: {
+      refresh: true,
+      search: true,
+    },
+  } as VxeTableGridOptions<ErpPurchasePlanApi.PurchasePlan>,
+  gridEvents: {
+    checkboxAll: handleRowCheckboxChange,
+    checkboxChange: handleRowCheckboxChange,
+  },
+});
+</script>
+
+<template>
+  <Page auto-content-height>
+    <FormModal @success="handleRefresh" />
+    <ProcessModal @success="handleRefresh" />
+    <Grid table-title="閲囪喘璁″垝鍒楄〃">
+      <template #toolbar-tools>
+        <TableAction
+          :actions="[
+            {
+              label: $t('ui.actionTitle.create', ['閲囪喘璁″垝']),
+              type: 'primary',
+              icon: ACTION_ICON.ADD,
+              auth: ['erp:purchase-plan:create'],
+              onClick: handleCreate,
+            },
+            {
+              label: '搴撳瓨棰勮鐢熸垚',
+              type: 'primary',
+              icon: ACTION_ICON.ADD,
+              auth: ['erp:purchase-plan:create'],
+              popConfirm: {
+                title: '鏍规嵁瀹夊叏搴撳瓨缂洪噺鑷姩鐢熸垚鑽夌閲囪喘璁″垝锛�',
+                confirm: handleGenerateFromStockAlert,
+              },
+            },
+            {
+              label: $t('ui.actionTitle.export'),
+              type: 'primary',
+              icon: ACTION_ICON.DOWNLOAD,
+              auth: ['erp:purchase-plan:export'],
+              onClick: handleExport,
+            },
+            {
+              label: '鎵归噺鍒犻櫎',
+              type: 'primary',
+              danger: true,
+              disabled: isEmpty(checkedIds),
+              icon: ACTION_ICON.DELETE,
+              auth: ['erp:purchase-plan:delete'],
+              popConfirm: {
+                title: `鏄惁鍒犻櫎鎵�閫変腑鏁版嵁锛焋,
+                confirm: handleDelete.bind(null, checkedIds),
+              },
+            },
+          ]"
+        />
+      </template>
+      <template #status="{ row }">
+        <Tag v-if="row.status === 0" color="default">鏈彁浜�</Tag>
+        <Tag v-else-if="row.status === 10" color="processing">瀹℃壒涓�</Tag>
+        <Tag v-else-if="row.status === 20" color="success">瀹℃牳閫氳繃</Tag>
+        <Tag v-else-if="row.status === 30" color="error">瀹℃牳涓嶉�氳繃</Tag>
+        <Tag v-else-if="row.status === 40" color="warning">宸插彇娑�</Tag>
+      </template>
+      <template #actions="{ row }">
+        <TableAction
+          :actions="[
+            {
+              label: $t('common.detail'),
+              type: 'link',
+              icon: ACTION_ICON.VIEW,
+              auth: ['erp:purchase-plan:query'],
+              onClick: handleDetail.bind(null, row),
+            },
+            {
+              label: $t('common.edit'),
+              type: 'link',
+              icon: ACTION_ICON.EDIT,
+              auth: ['erp:purchase-plan:update'],
+              ifShow: () => row.status === 0,
+              onClick: handleEdit.bind(null, row),
+            },
+            {
+              label: '鎻愪氦',
+              type: 'link',
+              ifShow: () => row.status === 0 || row.status === 30,
+              onClick: handleSubmit.bind(null, row),
+            },
+            {
+              label: '鐢熸垚鐢宠',
+              type: 'link',
+              auth: ['erp:purchase-plan:generate-request'],
+              ifShow: () => row.status === 20 && !row.generatedFlag,
+              onClick: handleGenerateRequests.bind(null, row),
+            },
+            {
+              label: '鏌ョ湅瀹℃壒',
+              type: 'link',
+              ifShow: () => row.status !== 0,
+              onClick: handleViewProcess.bind(null, row),
+            },
+            {
+              label: $t('common.delete'),
+              type: 'link',
+              danger: true,
+              icon: ACTION_ICON.DELETE,
+              auth: ['erp:purchase-plan:delete'],
+              ifShow: () => row.status === 0,
+              popConfirm: {
+                title: $t('ui.actionMessage.deleteConfirm', [row.no]),
+                confirm: handleDelete.bind(null, [row.id!]),
+              },
+            },
+          ]"
+        />
+      </template>
+    </Grid>
+  </Page>
+</template>

--
Gitblit v1.9.3