add notice bar for HomeTab.vue
This commit is contained in:
@@ -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<void> {
|
||||
}
|
||||
|
||||
async function verify(id: string): Promise<void> {
|
||||
const storeId = getCurrentStoreId();
|
||||
await axios.post(`${BASE_URI}/verify`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
pendingNoticeEvents.emit("changed", storeId);
|
||||
}
|
||||
|
||||
async function remove(id: string): Promise<void> {
|
||||
|
||||
@@ -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<Orde
|
||||
return await axios.post(`${URI}/quick/create`, request);
|
||||
}
|
||||
async function prepareStock(request: FulfillmentPrepareStockRequest): Promise<OrderFulfillment> {
|
||||
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<OrderFulfillment> {
|
||||
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<OrderFulfillment> {
|
||||
return await axios.post(`${URI}/reject`, request);
|
||||
|
||||
@@ -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<FundRecord> {
|
||||
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<FundRecord> {
|
||||
return await axios.post(`${ORDER_URI}/payment/reject`, request);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+78
-82
@@ -1,95 +1,93 @@
|
||||
<template>
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="客户"
|
||||
>
|
||||
<template #right>
|
||||
<t-badge
|
||||
v-if="canReadNotify"
|
||||
class="notification-badge"
|
||||
:count="unreadNotifyCount"
|
||||
:offset="[-6, 6]"
|
||||
:max-count="99"
|
||||
:show-zero="false"
|
||||
>
|
||||
<t-button
|
||||
aria-label="通知"
|
||||
@click="router.push('/notify')"
|
||||
theme="default"
|
||||
shape="square"
|
||||
variant="text"
|
||||
size="small"
|
||||
>
|
||||
<t-icon name="notification" size="1.25rem" />
|
||||
</t-button>
|
||||
</t-badge>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="page-content scroll column home-tab">
|
||||
<section
|
||||
v-for="group in visibleEntryGroupList"
|
||||
:key="group.title"
|
||||
class="entry-group"
|
||||
<div class="page-layout navbar home-tab">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
title="客户"
|
||||
>
|
||||
<h2 v-text="group.title"/>
|
||||
<div class="items" :class="group.layout">
|
||||
<div
|
||||
v-for="item in group.entryList"
|
||||
:key="item.path"
|
||||
class="item-wrap"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
<template #right>
|
||||
<t-badge
|
||||
v-if="canReadNotify"
|
||||
class="notification-badge"
|
||||
:count="unreadNotifyCount"
|
||||
:offset="[-6, 6]"
|
||||
:max-count="99"
|
||||
:show-zero="false"
|
||||
>
|
||||
<t-button
|
||||
class="item"
|
||||
:class="{ quick: item.path === '/customer/quick-sign-in' || item.path === '/management/order-fulfillments/quick' }"
|
||||
aria-label="通知"
|
||||
@click="router.push('/notify')"
|
||||
theme="default"
|
||||
shape="square"
|
||||
variant="text"
|
||||
@click="router.push(item.path)"
|
||||
size="small"
|
||||
>
|
||||
<div class="body">
|
||||
<t-icon :name="item.icon" size="1.75rem"/>
|
||||
<h2 v-text="item.title"/>
|
||||
</div>
|
||||
<t-icon name="notification" size="1.25rem" />
|
||||
</t-button>
|
||||
</t-badge>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="page-content scroll column">
|
||||
<pending-notice-bar />
|
||||
<section
|
||||
v-for="group in visibleEntryGroupList"
|
||||
:key="group.title"
|
||||
class="entry-group"
|
||||
>
|
||||
<h2 v-text="group.title"/>
|
||||
<div class="items" :class="group.layout">
|
||||
<div
|
||||
v-for="item in group.entryList"
|
||||
:key="item.path"
|
||||
class="item-wrap"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
>
|
||||
<t-button
|
||||
class="item"
|
||||
:class="{ quick: item.path === '/customer/quick-sign-in' || item.path === '/management/order-fulfillments/quick' }"
|
||||
variant="text"
|
||||
@click="router.push(item.path)"
|
||||
>
|
||||
<div class="body">
|
||||
<t-icon :name="item.icon" size="1.75rem"/>
|
||||
<h2 v-text="item.title"/>
|
||||
</div>
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="help-wrap" v-entrance-transition>
|
||||
<t-button
|
||||
class="help"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
content="使用帮助"
|
||||
@click="router.push('/management/help')"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="help-circle"/>
|
||||
</template>
|
||||
</t-button>
|
||||
<t-button
|
||||
v-if="canUseAi"
|
||||
class="ai"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
content="AI 小糕"
|
||||
@click="openAiChat"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="robot-2" />
|
||||
</template>
|
||||
</t-button>
|
||||
</div>
|
||||
</section>
|
||||
<div class="help-wrap" v-entrance-transition>
|
||||
<t-button
|
||||
class="help"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
content="使用帮助"
|
||||
@click="router.push('/management/help')"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="help-circle"/>
|
||||
</template>
|
||||
</t-button>
|
||||
<t-button
|
||||
v-if="canUseAi"
|
||||
class="ai"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
content="AI 小糕"
|
||||
@click="openAiChat"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="robot-2" />
|
||||
</template>
|
||||
</t-button>
|
||||
</div>
|
||||
</main>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { NotifyAPI, useUserStore } from "timi-web-api";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import PendingNoticeBar from "./component/PendingNoticeBar.vue";
|
||||
import { corePermissionCodes, gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
|
||||
defineOptions({
|
||||
@@ -208,11 +206,9 @@ onMounted(async () => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.home-tab {
|
||||
gap: 1rem;
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
|
||||
.entry-group {
|
||||
margin: 0 1rem;
|
||||
|
||||
& + & {
|
||||
margin-top: 1.5rem;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<template>
|
||||
<t-notice-bar
|
||||
v-if="noticeContent"
|
||||
:key="noticeContent"
|
||||
class="pending-notice"
|
||||
theme="warning"
|
||||
:visible="true"
|
||||
direction="horizontal"
|
||||
marquee
|
||||
:content="noticeContent"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { usePendingNoticeStore } from "@/store/pendingNoticeStore";
|
||||
|
||||
const pendingNoticeStore = usePendingNoticeStore();
|
||||
const noticeContent = computed(() => pendingNoticeStore.pendingNoticeList.join(","));
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.pending-notice {
|
||||
margin-top: -1rem;
|
||||
}
|
||||
</style>
|
||||
@@ -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<string[]>(() => {
|
||||
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<void> {
|
||||
const requestId = ++pendingRequestId;
|
||||
const tasks: Promise<void>[] = [];
|
||||
const load = async (key: keyof typeof pendingCounts, request: () => Promise<{ total?: number }>): Promise<void> => {
|
||||
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 };
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Events } from "timi-ts";
|
||||
|
||||
interface PendingNoticeEventMap {
|
||||
changed: [storeId: string];
|
||||
}
|
||||
|
||||
/** 待处理通知发生变化。 */
|
||||
export const pendingNoticeEvents = new Events<PendingNoticeEventMap>();
|
||||
Reference in New Issue
Block a user