From bf901f4031b1a1af505bb0397161558fa8b8c68e Mon Sep 17 00:00:00 2001 From: Timi Date: Wed, 28 Oct 2026 11:44:15 +0800 Subject: [PATCH] add notice bar for HomeTab.vue --- src/api/EventRecordAPI.ts | 5 +- src/api/FulfillmentAPI.ts | 13 +- src/api/SalesOrderAPI.ts | 8 +- .../component/FundCancelActionPopup.vue | 9 +- src/pages/tabs/HomeTab.vue | 160 +++++++++--------- src/pages/tabs/component/PendingNoticeBar.vue | 25 +++ src/store/pendingNoticeStore.ts | 81 +++++++++ src/utils/pendingNoticeEvents.ts | 8 + 8 files changed, 213 insertions(+), 96 deletions(-) create mode 100644 src/pages/tabs/component/PendingNoticeBar.vue create mode 100644 src/store/pendingNoticeStore.ts create mode 100644 src/utils/pendingNoticeEvents.ts diff --git a/src/api/EventRecordAPI.ts b/src/api/EventRecordAPI.ts index c7f6b81..32adfbe 100644 --- a/src/api/EventRecordAPI.ts +++ b/src/api/EventRecordAPI.ts @@ -1,8 +1,9 @@ +import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; import { axios } from "timi-web-api"; import type { PageResult } from "timi-web-api"; import type { CustomerEventRankView, EventOptionStat, EventRecord, EventRecordPage, EventRecordPageResult, EventRecordRankPage } from "@/types/EventRecord"; import type { Customer } from "@/types/Customer.ts"; -import { withCurrentStoreId } from "@/utils/store"; +import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store"; const BASE_URI = "/gao/event/record"; @@ -33,9 +34,11 @@ async function update(record: EventRecord): Promise { } async function verify(id: string): Promise { + const storeId = getCurrentStoreId(); await axios.post(`${BASE_URI}/verify`, undefined, { params: { id } }); + pendingNoticeEvents.emit("changed", storeId); } async function remove(id: string): Promise { diff --git a/src/api/FulfillmentAPI.ts b/src/api/FulfillmentAPI.ts index d2ec987..a23ab4b 100644 --- a/src/api/FulfillmentAPI.ts +++ b/src/api/FulfillmentAPI.ts @@ -1,5 +1,6 @@ +import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; import { axios } from "timi-web-api"; -import { withCurrentStoreId } from "@/utils/store"; +import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store"; import type { FulfillmentActionRequest, FulfillmentPage, @@ -37,10 +38,16 @@ async function quickCreate(request: QuickFulfillmentCreateRequest): Promise { - return await axios.post(`${URI}/prepare-stock`, request); + const storeId = getCurrentStoreId(); + const result = await axios.post(`${URI}/prepare-stock`, request); + pendingNoticeEvents.emit("changed", storeId); + return result; } async function verify(request: FulfillmentActionRequest): Promise { - return await axios.post(`${URI}/verify`, request); + const storeId = getCurrentStoreId(); + const result = await axios.post(`${URI}/verify`, request); + pendingNoticeEvents.emit("changed", storeId); + return result; } async function reject(request: FulfillmentActionRequest): Promise { return await axios.post(`${URI}/reject`, request); diff --git a/src/api/SalesOrderAPI.ts b/src/api/SalesOrderAPI.ts index 450dc2c..9b64c62 100644 --- a/src/api/SalesOrderAPI.ts +++ b/src/api/SalesOrderAPI.ts @@ -1,5 +1,6 @@ +import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; import { axios } from "timi-web-api"; -import { withCurrentStoreId } from "@/utils/store"; +import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store"; import type { DirectProductOrderCreateRequest, FundRecord, @@ -45,7 +46,10 @@ async function receivePaymentAndVerify(request: OrderPaymentReceiveRequest): Pro return await axios.post(`${ORDER_URI}/payment/receive-and-verify`, request); } async function verifyPayment(id: string): Promise { - return await axios.post(`${ORDER_URI}/payment/verify`, undefined, { params: { id } }); + const storeId = getCurrentStoreId(); + const result = await axios.post(`${ORDER_URI}/payment/verify`, undefined, { params: { id } }); + pendingNoticeEvents.emit("changed", storeId); + return result; } async function rejectPayment(request: OrderPaymentActionRequest): Promise { return await axios.post(`${ORDER_URI}/payment/reject`, request); diff --git a/src/pages/salesOrder/component/FundCancelActionPopup.vue b/src/pages/salesOrder/component/FundCancelActionPopup.vue index dd6bf5e..0e70f4a 100644 --- a/src/pages/salesOrder/component/FundCancelActionPopup.vue +++ b/src/pages/salesOrder/component/FundCancelActionPopup.vue @@ -83,7 +83,7 @@ import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelect import FundRecordDetailPopup from "./FundRecordDetailPopup.vue"; import type { PhotoItem } from "@/types/Photo"; import type { FundRecord } from "@/types/SalesOrder"; -import { formatPackageAmount, formatPackageAmountInput, parsePackageAmount } from "@/utils/package"; +import { formatPackageAmount, formatPackageAmountInput } from "@/utils/package"; type FundAction = "REFUND" | "REVOKE"; type FundActionForm = { @@ -121,13 +121,6 @@ const emit = defineEmits<{ }>(); const actionText = computed(() => props.selection?.action === "REFUND" ? "退款" : "冲正"); -const isComplete = computed(() => { - const selection = props.selection; - if (!selection) return false; - const amount = parsePackageAmount(selection.form.amountText); - const hasPhoto = [...selection.form.photoItems, ...props.sharedPhotoItems].some(item => !!item.tempFileId); - return hasPhoto && (selection.action !== "REFUND" || (amount !== undefined && 0 < amount)); -}); function updateVisible(visible: boolean): void { emit("update:modelValue", visible); diff --git a/src/pages/tabs/HomeTab.vue b/src/pages/tabs/HomeTab.vue index b8dc7ad..018dd4c 100644 --- a/src/pages/tabs/HomeTab.vue +++ b/src/pages/tabs/HomeTab.vue @@ -1,95 +1,93 @@ + +
+ +
+

+
+
+ +
+ +

+

+
+
+

+
+ + + + + +
- -
- - - - - - -
-
+ + + + diff --git a/src/store/pendingNoticeStore.ts b/src/store/pendingNoticeStore.ts new file mode 100644 index 0000000..f2d5038 --- /dev/null +++ b/src/store/pendingNoticeStore.ts @@ -0,0 +1,81 @@ +import { useUserStore } from "timi-web-api"; + +import EventRecordAPI from "@/api/EventRecordAPI"; +import FulfillmentAPI from "@/api/FulfillmentAPI"; +import SalesOrderAPI from "@/api/SalesOrderAPI"; +import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; +import { permissionCodes } from "@/utils/permission"; +import { getCurrentStoreId } from "@/utils/store"; +import { useCurrentStoreStore } from "./currentStoreStore"; + +export const usePendingNoticeStore = defineStore("pendingNotice", () => { + const userStore = useUserStore(); + const currentStoreStore = useCurrentStoreStore(); + const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0 }); + let pendingRequestId = 0; + const pendingNoticeList = computed(() => { + const notices: string[] = []; + if (pendingCounts.fulfillment) { + notices.push(`有 ${pendingCounts.fulfillment} 条履约待核销`); + } + if (pendingCounts.fund) { + notices.push(`有 ${pendingCounts.fund} 条资金流水待核销`); + } + if (pendingCounts.stock) { + notices.push(`有 ${pendingCounts.stock} 条履约等待库存`); + } + if (pendingCounts.event) { + notices.push(`有 ${pendingCounts.event} 条事件待核销`); + } + return notices; + }); + + async function refreshPendingNotices(): Promise { + const requestId = ++pendingRequestId; + const tasks: Promise[] = []; + const load = async (key: keyof typeof pendingCounts, request: () => Promise<{ total?: number }>): Promise => { + try { + const result = await request(); + if (requestId === pendingRequestId) { + pendingCounts[key] = result.total || 0; + } + } catch (error) { + if (requestId === pendingRequestId) { + console.warn("待处理通知加载失败", error); + } + } + }; + if (userStore.hasPermissions(permissionCodes.orderFulfillment.read)) { + tasks.push(load("fulfillment", () => FulfillmentAPI.list({ index: 0, size: 1, status: "PENDING" }))); + tasks.push(load("stock", () => FulfillmentAPI.list({ index: 0, size: 1, status: "WAITING_STOCK" }))); + } + if (userStore.hasPermissions(permissionCodes.fundRecord.read)) { + tasks.push(load("fund", () => SalesOrderAPI.fundRecordList({ index: 0, size: 1, status: "PENDING" }))); + } + if (userStore.hasPermissions(permissionCodes.eventRecord.read)) { + tasks.push(load("event", () => EventRecordAPI.list({ index: 0, size: 1, verificationStatus: "PENDING" }))); + } + await Promise.all(tasks); + } + + watch( + () => [currentStoreStore.currentStoreId, userStore.loginUser.user?.id || userStore.loginUser.id || ""], + ([, userId]) => { + pendingRequestId++; + Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0 }); + if (userId) { + void refreshPendingNotices(); + } + }, + { immediate: true } + ); + + const unregister = pendingNoticeEvents.register("changed", storeId => { + if (!storeId || storeId === getCurrentStoreId()) { + void refreshPendingNotices(); + } + }); + onScopeDispose(unregister); + + return { pendingNoticeList }; +}); diff --git a/src/utils/pendingNoticeEvents.ts b/src/utils/pendingNoticeEvents.ts new file mode 100644 index 0000000..04a94f7 --- /dev/null +++ b/src/utils/pendingNoticeEvents.ts @@ -0,0 +1,8 @@ +import { Events } from "timi-ts"; + +interface PendingNoticeEventMap { + changed: [storeId: string]; +} + +/** 待处理通知发生变化。 */ +export const pendingNoticeEvents = new Events();