diff --git a/package.json b/package.json index 4e0a82b..c27fb94 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gao-customer-h5", "private": true, - "version": "1.1.0", + "version": "1.2.0", "type": "module", "scripts": { "dev": "vite --host", diff --git a/src/api/RecycleAPI.ts b/src/api/RecycleAPI.ts new file mode 100644 index 0000000..18a1a57 --- /dev/null +++ b/src/api/RecycleAPI.ts @@ -0,0 +1,161 @@ +import { axios } from "timi-web-api"; +import type { + RecycleExchange, + RecycleExchangeActionRequest, + RecycleExchangeCreateRequest, + RecycleExchangeDetail, + RecycleExchangePage, + RecycleExchangeRule, + RecycleExchangeRulePage, + RecycleExchangeStatRow, + RecycleItem, + RecycleItemPage, + RecyclePageResult, + RecycleStatRow +} from "@/types/Recycle"; +import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; +import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store"; + +const CONFIG_URI = "/gao/recycle/config"; +const EXCHANGE_URI = "/gao/recycle/exchange"; +const STAT_URI = "/gao/recycle/stat"; + +/** 配置接口的 storeId 走查询参数,可省略时由后端按登录用户门店范围解析。 */ +function configParams(page: RecycleItemPage | RecycleExchangeRulePage): Record { + return { + storeId: page.storeId || getCurrentStoreId() || undefined, + status: page.status, + keyword: page.keyword || undefined, + recycleItemId: "recycleItemId" in page ? page.recycleItemId : undefined, + skuId: "skuId" in page ? page.skuId : undefined, + offset: page.offset, + limit: page.limit + }; +} + +/** 兑换单状态变化会改变待核销数量,通知顶部的待处理提示重新取数。 */ +function notifyPendingNoticeChanged(result: RecycleExchange): RecycleExchange { + pendingNoticeEvents.emit("changed", getCurrentStoreId()); + return result; +} + +// ---------- 配置 ---------- + +/** 回收物配置列表,包含启用和停用项,支持按名称与状态筛选。 */ +async function itemList(page: RecycleItemPage): Promise> { + return await axios.post(`${CONFIG_URI}/items`, undefined, { params: configParams(page) }); +} + +/** 回收物配置详情,回填服务端拼接好的来源产品与 SKU 名称。 */ +async function itemDetail(id: string): Promise { + return await axios.post(`${CONFIG_URI}/item/detail`, undefined, { + params: { storeId: getCurrentStoreId() || undefined, id } + }); +} + +/** 保存回收物配置:新增不传 id,修改必须提交完整配置。 */ +async function itemSave(item: RecycleItem): Promise { + return await axios.post(`${CONFIG_URI}/item/save`, withCurrentStoreId(item)); +} + +/** 规则列表,返回全部状态,按 sort 升序、创建时间倒序。 */ +async function ruleList(page: RecycleExchangeRulePage): Promise> { + return await axios.post(`${CONFIG_URI}/rules`, undefined, { params: configParams(page) }); +} + +/** 启用规则列表,创建兑换单时使用。回收物或产品后来停用时仍可能出现,以服务端校验为准。 */ +async function activeRuleList(page: RecycleExchangeRulePage): Promise> { + return await axios.post(`${CONFIG_URI}/rules/active`, undefined, { params: configParams(page) }); +} + +/** 兑换规则详情,回填回收物、产品、SKU 与业务单位名称。 */ +async function ruleDetail(id: string): Promise { + return await axios.post(`${CONFIG_URI}/rule/detail`, undefined, { + params: { storeId: getCurrentStoreId() || undefined, id } + }); +} + +/** 保存规则配置:新增不传 id,修改必须提交完整配置。 */ +async function ruleSave(rule: RecycleExchangeRule): Promise { + return await axios.post(`${CONFIG_URI}/rule/save`, withCurrentStoreId(rule)); +} + +// ---------- 兑换单 ---------- + +/** 创建兑换单。requestNo 为幂等号,重试必须原样复用。 */ +async function create(request: RecycleExchangeCreateRequest): Promise { + const result = await axios.post(`${EXCHANGE_URI}/create`, withCurrentStoreId(request)); + return notifyPendingNoticeChanged(result); +} + +/** 兑换单分页,按业务时间、创建时间及 ID 倒序。 */ +async function page(request: RecycleExchangePage): Promise> { + return await axios.post(`${EXCHANGE_URI}/page`, withCurrentStoreId(request)); +} + +async function detail(id: string): Promise { + return await axios.post(`${EXCHANGE_URI}/detail`, undefined, { params: { id } }); +} + +/** + * 核销待核销单。成功返回的兑换单状态可能已被并发操作改变,页面应重新查询详情。 + * 门店由服务端按兑换单自身归属解析,请求不需要带 storeId。 + */ +async function verify(request: RecycleExchangeActionRequest): Promise { + const result = await axios.post(`${EXCHANGE_URI}/verify`, request); + return notifyPendingNoticeChanged(result); +} + +/** 撤销待核销单,recycleReturned 决定回收物是否全部退还客户。门店同理由服务端取。 */ +async function cancel(request: RecycleExchangeActionRequest): Promise { + const result = await axios.post(`${EXCHANGE_URI}/cancel`, request); + return notifyPendingNoticeChanged(result); +} + +/** 冲正已核销单。库存商品必须 stockReturned 且至少一张 PHOTO。门店同理由服务端取。 */ +async function revoke(request: RecycleExchangeActionRequest): Promise { + const result = await axios.post(`${EXCHANGE_URI}/revoke`, request); + return notifyPendingNoticeChanged(result); +} + +// ---------- 统计 ---------- + +/** 回收统计,时间区间为 [startAt, endAt)。 */ +async function statRecycle(startAt: number, endAt: number): Promise { + return await axios.post(`${STAT_URI}/recycle`, undefined, { + params: { + storeId: getCurrentStoreId() || undefined, + startAt, + endAt + } + }); +} + +/** 兑换统计,时间区间为 [startAt, endAt)。 */ +async function statExchange(startAt: number, endAt: number): Promise { + return await axios.post(`${STAT_URI}/exchange`, undefined, { + params: { + storeId: getCurrentStoreId() || undefined, + startAt, + endAt + } + }); +} + +export default { + itemList, + itemDetail, + itemSave, + ruleList, + activeRuleList, + ruleDetail, + ruleSave, + create, + page, + detail, + verify, + cancel, + revoke, + statRecycle, + statExchange +}; diff --git a/src/assets/styles/global.less b/src/assets/styles/global.less index fc8aece..228ad47 100644 --- a/src/assets/styles/global.less +++ b/src/assets/styles/global.less @@ -22,10 +22,22 @@ html.theme-dark { --td-bg-color-page: #10161f; --td-bg-color-container: #1a2230; --td-bg-color-container-hover: #222c3c; + --td-bg-color-container-active: #222c3c; + // 次级容器与组件底色:t-tag[theme=default] 的浅色底直接取 secondarycontainer, + // 不补就会退化到 gray-color-1(#f3f3f3),在深色页面里是一块白底 + --td-bg-color-secondarycontainer: #222c3c; + --td-bg-color-secondarycontainer-active: #2a3646; + --td-bg-color-component: #2a3646; + --td-bg-color-component-active: #33414f; + --td-bg-color-component-disabled: #1f2836; + --td-border-level-1-color: rgba(255, 255, 255, .08); + --td-border-level-2-color: rgba(255, 255, 255, .16); + --td-component-stroke: rgba(255, 255, 255, .08); --td-component-border: rgba(255, 255, 255, .12); --td-text-color-primary: rgba(255, 255, 255, .9); --td-text-color-secondary: rgba(255, 255, 255, .55); --td-text-color-placeholder: rgba(255, 255, 255, .35); + --td-text-color-disabled: rgba(255, 255, 255, .25); // 导航激活项在深色下需要压深,否则浅色胶囊压在深底上太刺眼 --tui-rail-active-background: rgba(15, 118, 110, .22); diff --git a/src/components/attachmentSelector/AttachmentSelector.vue b/src/components/attachmentSelector/AttachmentSelector.vue index 6fae454..822e9d5 100644 --- a/src/components/attachmentSelector/AttachmentSelector.vue +++ b/src/components/attachmentSelector/AttachmentSelector.vue @@ -74,7 +74,7 @@ const props = withDefaults(defineProps(), { busy: false, items: () => [], readonly: false, - required: false, + required: false }); const emit = defineEmits<{ diff --git a/src/components/productSelector/ProductSelectPopup.vue b/src/components/productSelector/ProductSelectPopup.vue index e5b622d..ff13b56 100644 --- a/src/components/productSelector/ProductSelectPopup.vue +++ b/src/components/productSelector/ProductSelectPopup.vue @@ -27,7 +27,7 @@ @toggle="toggleSku" @check="toggleProduct" /> - + @@ -46,12 +46,14 @@ interface Props { modelValue?: ProductSkuSelectionValue; visible?: boolean; selectionMode?: ProductSkuSelectionMode; + /** sellable 只列可售产品;all 连停售产品一起列,用于来源产品这类仅作识别的场景 */ + productScope?: "sellable" | "all"; selectableProductIdList?: string[]; selectableSkuIdList?: string[]; selectedSkuIdList?: string[]; } -const props = withDefaults(defineProps(), { selectionMode: "single" }); +const props = withDefaults(defineProps(), { selectionMode: "single", productScope: "sellable" }); const emit = defineEmits<{ "update:modelValue": [value: Props["modelValue"]]; "update:visible": [value: boolean]; @@ -93,7 +95,9 @@ const visibleProductList = computed(() => { return productList.value.filter(item => (!selectableProductIdSet.value || selectableProductIdSet.value.has(item.id || "")) && (!text || `${item.name}${item.code}`.toLocaleLowerCase().includes(text))); }); -const emptyProductText = computed(() => props.selectableProductIdList?.length === 0 ? "客户暂无已购可履约产品" : "暂无可售产品"); +const emptyProductText = computed(() => props.selectableProductIdList?.length === 0 + ? "客户暂无已购可履约产品" + : (props.productScope === "all" ? "暂无产品" : "暂无可售产品")); const selectorItemList = computed(() => visibleProductList.value.map((summary, index) => { const key = getProductKey(summary, index); const product = productDetailMap.value[key] || (summary.skuList?.length ? summary : undefined); @@ -132,9 +136,11 @@ watch(popupVisible, async visible => { } loading.value = true; try { - productList.value = await ProductAPI.sellableList({ index: 0, size: 1000 }); + productList.value = props.productScope === "all" + ? (await ProductAPI.list({ index: 0, size: 1000 })).list || [] + : await ProductAPI.sellableList({ index: 0, size: 1000 }); } catch (error) { - Message.error(getErrorMessage(error, "可售产品加载失败")); + Message.error(getErrorMessage(error, props.productScope === "all" ? "产品加载失败" : "可售产品加载失败")); } finally { loading.value = false; } diff --git a/src/pages/recycle/RecycleExchangeCreate.vue b/src/pages/recycle/RecycleExchangeCreate.vue new file mode 100644 index 0000000..8490df7 --- /dev/null +++ b/src/pages/recycle/RecycleExchangeCreate.vue @@ -0,0 +1,514 @@ + + + + + diff --git a/src/pages/recycle/RecycleExchangeDetail.vue b/src/pages/recycle/RecycleExchangeDetail.vue new file mode 100644 index 0000000..c6bfa8f --- /dev/null +++ b/src/pages/recycle/RecycleExchangeDetail.vue @@ -0,0 +1,498 @@ + + + + + diff --git a/src/pages/recycle/RecycleExchangeList.vue b/src/pages/recycle/RecycleExchangeList.vue new file mode 100644 index 0000000..908b518 --- /dev/null +++ b/src/pages/recycle/RecycleExchangeList.vue @@ -0,0 +1,517 @@ + + + + + diff --git a/src/pages/recycle/RecycleItemEdit.vue b/src/pages/recycle/RecycleItemEdit.vue new file mode 100644 index 0000000..3e62010 --- /dev/null +++ b/src/pages/recycle/RecycleItemEdit.vue @@ -0,0 +1,289 @@ + + + + + diff --git a/src/pages/recycle/RecycleItemList.vue b/src/pages/recycle/RecycleItemList.vue new file mode 100644 index 0000000..00c0c64 --- /dev/null +++ b/src/pages/recycle/RecycleItemList.vue @@ -0,0 +1,253 @@ + + + + + diff --git a/src/pages/recycle/RecycleRuleEdit.vue b/src/pages/recycle/RecycleRuleEdit.vue new file mode 100644 index 0000000..2389347 --- /dev/null +++ b/src/pages/recycle/RecycleRuleEdit.vue @@ -0,0 +1,400 @@ + + + + + diff --git a/src/pages/recycle/RecycleRuleList.vue b/src/pages/recycle/RecycleRuleList.vue new file mode 100644 index 0000000..a24aa55 --- /dev/null +++ b/src/pages/recycle/RecycleRuleList.vue @@ -0,0 +1,265 @@ + + + + + diff --git a/src/pages/recycle/RecycleStat.vue b/src/pages/recycle/RecycleStat.vue new file mode 100644 index 0000000..06f6928 --- /dev/null +++ b/src/pages/recycle/RecycleStat.vue @@ -0,0 +1,437 @@ + + + + + diff --git a/src/pages/recycle/components/RecycleExchangeActionPopup.vue b/src/pages/recycle/components/RecycleExchangeActionPopup.vue new file mode 100644 index 0000000..833e506 --- /dev/null +++ b/src/pages/recycle/components/RecycleExchangeActionPopup.vue @@ -0,0 +1,242 @@ + + + + + diff --git a/src/pages/recycle/components/RecycleExchangeListCell.vue b/src/pages/recycle/components/RecycleExchangeListCell.vue new file mode 100644 index 0000000..51f2a94 --- /dev/null +++ b/src/pages/recycle/components/RecycleExchangeListCell.vue @@ -0,0 +1,239 @@ + + + + + diff --git a/src/pages/setting/AppUpdate.vue b/src/pages/setting/AppUpdate.vue index 0c643d3..38061ef 100644 --- a/src/pages/setting/AppUpdate.vue +++ b/src/pages/setting/AppUpdate.vue @@ -36,7 +36,7 @@ diff --git a/src/pages/tabs/component/CustomerEntryPanel.vue b/src/pages/tabs/component/CustomerEntryPanel.vue index 0ec77c0..7a04956 100644 --- a/src/pages/tabs/component/CustomerEntryPanel.vue +++ b/src/pages/tabs/component/CustomerEntryPanel.vue @@ -140,6 +140,12 @@ const entryGroupList: HomeEntryGroup[] = [ permission: permissionCodes.pointRedemption.create, icon: "gift", title: "积分兑换" + }, + { + path: "/management/recycle-exchanges", + permission: permissionCodes.recycleExchange.query, + icon: "swap", + title: "回收兑换" } ] } diff --git a/src/pages/tabs/component/ProductEntryPanel.vue b/src/pages/tabs/component/ProductEntryPanel.vue index a969d2e..737417e 100644 --- a/src/pages/tabs/component/ProductEntryPanel.vue +++ b/src/pages/tabs/component/ProductEntryPanel.vue @@ -149,6 +149,28 @@ const menuGroupList = computed(() => [ } ] }, + { + items: [ + { + icon: "swap", + path: "/management/recycle-exchanges", + title: "回收兑换", + visible: userStore.hasPermissions(permissionCodes.recycleExchange.query) + }, + { + icon: "setting", + path: "/management/recycle-items", + title: "回收配置", + visible: userStore.hasPermissions(permissionCodes.recycleExchange.configManage) + }, + { + icon: "chart-combo", + path: "/management/recycle-stats", + title: "回收统计", + visible: userStore.hasPermissions(permissionCodes.recycleExchange.query) + } + ] + }, { key: "analysis", items: [ diff --git a/src/router/index.ts b/src/router/index.ts index 31a9245..8b4c66e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -15,6 +15,7 @@ import followUpReminderRoutes from "@/router/routes/followUpReminderRoutes"; import productRoutes from "@/router/routes/productRoutes"; import salesOrderRoutes from "@/router/routes/salesOrderRoutes"; import fulfillmentRoutes from "@/router/routes/fulfillmentRoutes"; +import recycleRoutes from "@/router/routes/recycleRoutes"; import dataExportRoutes from "@/router/routes/dataExportRoutes"; import { useCurrentStoreStore } from "@/store/currentStoreStore"; import { useGlobalUIStore } from "@/store/globalUI"; @@ -37,6 +38,7 @@ const detailRoutes = [ ...productRoutes, ...salesOrderRoutes, ...fulfillmentRoutes, + ...recycleRoutes, ...dataExportRoutes ]; diff --git a/src/router/routes/recycleRoutes.ts b/src/router/routes/recycleRoutes.ts new file mode 100644 index 0000000..3e2b0c1 --- /dev/null +++ b/src/router/routes/recycleRoutes.ts @@ -0,0 +1,68 @@ +import type { RouteRecordRaw } from "vue-router"; + +function meta(depth = 3): RouteRecordRaw["meta"] { + return { depth, tabBarVisible: false, bodyBackground: "#F5F5F8", darkBodyBackground: "#10161f" }; +} + +export default [ + { + path: "/management/recycle-exchanges", + name: "RecycleExchangeList", + component: () => import("@/pages/recycle/RecycleExchangeList.vue"), + meta: meta() + }, + { + path: "/management/recycle-exchanges/create", + name: "RecycleExchangeCreate", + component: () => import("@/pages/recycle/RecycleExchangeCreate.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-exchanges/:id", + name: "RecycleExchangeDetail", + component: () => import("@/pages/recycle/RecycleExchangeDetail.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-items", + name: "RecycleItemList", + component: () => import("@/pages/recycle/RecycleItemList.vue"), + meta: meta() + }, + { + path: "/management/recycle-items/create", + name: "RecycleItemCreate", + component: () => import("@/pages/recycle/RecycleItemEdit.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-items/:id", + name: "RecycleItemEdit", + component: () => import("@/pages/recycle/RecycleItemEdit.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-rules", + name: "RecycleRuleList", + component: () => import("@/pages/recycle/RecycleRuleList.vue"), + meta: meta() + }, + { + path: "/management/recycle-rules/create", + name: "RecycleRuleCreate", + component: () => import("@/pages/recycle/RecycleRuleEdit.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-rules/:id", + name: "RecycleRuleEdit", + component: () => import("@/pages/recycle/RecycleRuleEdit.vue"), + meta: meta(4) + }, + { + path: "/management/recycle-stats", + name: "RecycleStat", + component: () => import("@/pages/recycle/RecycleStat.vue"), + meta: meta() + } +] as RouteRecordRaw[]; diff --git a/src/store/pendingNoticeStore.ts b/src/store/pendingNoticeStore.ts index 21e490b..dca4b3e 100644 --- a/src/store/pendingNoticeStore.ts +++ b/src/store/pendingNoticeStore.ts @@ -2,6 +2,7 @@ import { useUserStore } from "timi-web-api"; import EventRecordAPI from "@/api/EventRecordAPI"; import FulfillmentAPI from "@/api/FulfillmentAPI"; +import RecycleAPI from "@/api/RecycleAPI"; import SalesOrderAPI from "@/api/SalesOrderAPI"; import { pendingNoticeEvents } from "@/utils/pendingNoticeEvents"; import { permissionCodes } from "@/utils/permission"; @@ -11,13 +12,16 @@ 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 }); + const pendingCounts = reactive({ fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 }); let pendingRequestId = 0; const pendingNoticeList = computed(() => { const notices: { content: string; name: string; query: Record }[] = []; if (pendingCounts.fulfillment) { notices.push({ content: `有 ${pendingCounts.fulfillment} 条履约待核销`, name: "OrderFulfillmentList", query: { status: "PENDING" } }); } + if (pendingCounts.recycle) { + notices.push({ content: `有 ${pendingCounts.recycle} 条回收兑换待核销`, name: "RecycleExchangeList", query: { status: "PENDING" } }); + } if (pendingCounts.fund) { notices.push({ content: `有 ${pendingCounts.fund} 条资金流水待核销`, name: "FundRecordList", query: { status: "PENDING" } }); } @@ -55,6 +59,9 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => { if (userStore.hasPermissions(permissionCodes.eventRecord.read)) { tasks.push(load("event", () => EventRecordAPI.list({ index: 0, size: 1, verificationStatus: "PENDING" }))); } + if (userStore.hasPermissions(permissionCodes.recycleExchange.query)) { + tasks.push(load("recycle", () => RecycleAPI.page({ index: 0, size: 1, status: "PENDING" }))); + } await Promise.all(tasks); } @@ -62,7 +69,7 @@ export const usePendingNoticeStore = defineStore("pendingNotice", () => { () => [currentStoreStore.currentStoreId, userStore.loginUser.user?.id || userStore.loginUser.id || ""], ([, userId]) => { pendingRequestId++; - Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0 }); + Object.assign(pendingCounts, { fulfillment: 0, stock: 0, fund: 0, event: 0, recycle: 0 }); if (userId) { void refreshPendingNotices(); } diff --git a/src/types/Recycle.ts b/src/types/Recycle.ts new file mode 100644 index 0000000..cea824c --- /dev/null +++ b/src/types/Recycle.ts @@ -0,0 +1,232 @@ +import type { Attachment, Model, PageResult, User } from "timi-web-api"; +import type { Customer } from "@/types/Customer"; +import type { ProductSkuSpecSnapshot, StockRecord } from "@/types/Product"; + +/** 回收物与兑换规则的启用状态。配置没有删除,停用使用 INACTIVE。 */ +export type RecycleStatus = "ACTIVE" | "INACTIVE"; + +/** 兑换单状态。 */ +export type RecycleExchangeStatus = "PENDING" | "VERIFIED" | "CANCELLED" | "REVOKED"; + +/** 兑换单操作类型。 */ +export type RecycleExchangeActionType = "VERIFY" | "CANCEL" | "REVOKE"; + +/** 回收物配置。回收物不是退货,不校验客户购买记录,也不累计客户余额。 */ +export type RecycleItem = { + storeId?: string; + name: string; + /** 回收计量单位,例如「个」「公斤」 */ + unitName: string; + /** 来源产品 ID,仅用于识别,不影响库存 */ + productId?: string | null; + /** 来源 SKU ID,填写时必须同时填写其所属 productId */ + skuId?: string | null; + status?: RecycleStatus; + remark?: string | null; + /** 来源产品名称,服务端回填,仅展示用 */ + sourceProductName?: string | null; + /** 来源 SKU 规格摘要,服务端回填,仅展示用 */ + sourceSkuName?: string | null; +} & Model; + +/** 回收物配置分页与筛选条件。 */ +export type RecycleItemPage = { + storeId?: string; + status?: RecycleStatus; + /** 名称关键字 */ + keyword?: string; + offset: number; + limit: number; +}; + +/** 回收兑换规则:单份回收数量兑换单份业务单位数量。 */ +export type RecycleExchangeRule = { + storeId?: string; + recycleItemId: string; + /** 单份规则回收数量 */ + recycleQuantity: number | string; + /** 兑换 SKU ID */ + skuId: string; + /** 兑换 SKU 业务单位 ID */ + skuUnitId: string; + /** 单份规则兑换业务单位数量 */ + exchangeQuantity: number | string; + status?: RecycleStatus; + sort?: number; + remark?: string | null; + /** 以下为服务端回填的展示字段,保存时无需提交 */ + recycleName?: string | null; + recycleUnit?: string | null; + productName?: string | null; + productType?: string | null; + skuCode?: string | null; + skuName?: string | null; + specSummary?: string | null; + unitName?: string | null; + stockEnabled?: boolean | null; + allowDecimalQuantity?: boolean | null; +} & Model; + +/** 兑换规则分页与筛选条件。 */ +export type RecycleExchangeRulePage = { + storeId?: string; + status?: RecycleStatus; + recycleItemId?: string; + skuId?: string; + /** 回收物名称关键字 */ + keyword?: string; + offset: number; + limit: number; +}; + +/** + * 兑换单。 + * + * 规则、产品、客户后续变更都不改写单据,页面展示优先使用快照字段。 + */ +export type RecycleExchange = { + storeId?: string; + customerId?: string; + requestNo?: string; + ruleId?: string; + recycleItemId?: string; + recycleNameSnapshot?: string; + recycleUnitSnapshot?: string; + sourceProductIdSnapshot?: string; + sourceSkuIdSnapshot?: string; + ruleRecycleQuantity?: number | string; + ruleExchangeQuantity?: number | string; + /** 规则倍数,正整数 */ + multiple?: number; + /** 预设回收数量 = 规则回收数量 × 倍数 */ + defaultRecycleQuantity?: number | string; + /** 预设兑换数量 = 规则兑换数量 × 倍数 */ + defaultExchangeQuantity?: number | string; + /** 实际回收数量 */ + recycleQuantity?: number | string; + /** 实际兑换数量 */ + exchangeQuantity?: number | string; + productIdSnapshot?: string; + skuIdSnapshot?: string; + skuUnitIdSnapshot?: string; + productNameSnapshot?: string; + productTypeSnapshot?: string; + skuCodeSnapshot?: string; + skuNameSnapshot?: string; + specSummarySnapshot?: string; + skuSpecSnapshot?: ProductSkuSpecSnapshot[]; + unitSnapshot?: string; + baseQuantityPerUnitSnapshot?: number | string; + baseQuantity?: number | string; + allowDecimalSnapshot?: boolean; + /** true 为兑换 SKU 启用库存管理,创建时预占,撤销时释放 */ + stockEnabledSnapshot?: boolean; + status?: RecycleExchangeStatus; + operatorUserId?: string; + /** 业务发生时间 */ + occurredAt?: number; + remark?: string | null; + customer?: Customer; + operator?: Partial; +} & Model; + +/** 兑换单操作记录。核销记录的退回字段为空。 */ +export type RecycleExchangeAction = { + exchangeId?: string; + actionType?: RecycleExchangeActionType; + operatorUserId?: string; + occurredAt?: number; + reason?: string | null; + remark?: string | null; + /** true 为回收物全部退还客户 */ + recycleReturned?: boolean | null; + /** true 为兑换商品已退回门店 */ + stockReturned?: boolean | null; + stockRecordId?: string; + sourceStockRecordId?: string; + operator?: Partial; +} & Model; + +/** 兑换单详情。冲正照片按操作记录 ID 从 actionAttachments 读取。 */ +export type RecycleExchangeDetail = { + exchange?: RecycleExchange; + actionList?: RecycleExchangeAction[]; + attachmentList?: Attachment[]; + actionAttachments?: Record; + stockRecordList?: StockRecord[]; +}; + +export type RecycleExchangeCreateRequest = { + storeId?: string; + customerId: string; + ruleId: string; + requestNo: string; + multiple: number; + /** 实际回收数量,不传使用预设值 */ + recycleQuantity?: string; + /** 实际兑换数量,不传使用预设值 */ + exchangeQuantity?: string; + occurredAt?: number; + remark?: string | null; + attachmentList?: Partial[]; +}; + +/** 兑换单动作请求。门店由服务端按兑换单归属解析,这里不需要也不应该传。 */ +export type RecycleExchangeActionRequest = { + exchangeId: string; + requestNo: string; + occurredAt?: number; + remark?: string | null; + /** 冲正必填 */ + reason?: string; + /** 撤销、冲正必填 */ + recycleReturned?: boolean; + /** 库存商品冲正必填,必须为 true */ + stockReturned?: boolean; + /** 库存商品冲正至少一张 PHOTO */ + attachmentList?: Partial[]; +}; + +export type RecycleExchangePage = { + storeId?: string; + customerId?: string; + recycleItemId?: string; + skuId?: string; + status?: RecycleExchangeStatus; + /** 业务时间起点,包含 */ + beginAt?: number; + /** 业务时间终点,包含 */ + endAt?: number; + index: number; + size: number; +}; + +/** + * 配置列表分页结果。 + * + * 后端返回的 pages 按本次列表长度计算,末页可能不准,分页一律用 total 推算。 + */ +export type RecyclePageResult = PageResult & { + pages?: number; +}; + +/** 回收统计行。同一回收物名称或单位变化后可能出现多行。 */ +export type RecycleStatRow = { + recycleItemId?: string; + recycleName?: string; + recycleUnit?: string; + receivedQuantity?: number | string; + returnedQuantity?: number | string; + netQuantity?: number | string; +}; + +/** 兑换统计行。三项数量按创建、核销、冲正的业务时间分别归集。 */ +export type RecycleExchangeStatRow = { + skuId?: string; + skuUnitId?: string; + productName?: string; + unit?: string; + createdQuantity?: number | string; + verifiedQuantity?: number | string; + revokedQuantity?: number | string; +}; diff --git a/src/utils/permission.ts b/src/utils/permission.ts index d9a6576..3282df9 100644 --- a/src/utils/permission.ts +++ b/src/utils/permission.ts @@ -99,6 +99,15 @@ export const permissionCodes = { return: "GAO:ORDER_FULFILLMENT:RETURN", revoke: "GAO:ORDER_FULFILLMENT:REVOKE" }, + recycleExchange: { + configManage: "GAO:RECYCLE_EXCHANGE:CONFIG_MANAGE", + query: "GAO:RECYCLE_EXCHANGE:QUERY", + create: "GAO:RECYCLE_EXCHANGE:CREATE", + quantityAdjust: "GAO:RECYCLE_EXCHANGE:QUANTITY_ADJUST", + verify: "GAO:RECYCLE_EXCHANGE:VERIFY", + cancel: "GAO:RECYCLE_EXCHANGE:CANCEL", + revoke: "GAO:RECYCLE_EXCHANGE:REVOKE" + }, fundReceive: { create: "GAO:FUND_RECEIVE:CREATE", verify: "GAO:FUND_RECEIVE:VERIFY" @@ -244,6 +253,13 @@ export const gaoStoreScopePermissionCodes = [ permissionCodes.orderFulfillment.revoke, permissionCodes.fundReceive.create, permissionCodes.fundReceive.verify, + permissionCodes.recycleExchange.configManage, + permissionCodes.recycleExchange.query, + permissionCodes.recycleExchange.create, + permissionCodes.recycleExchange.quantityAdjust, + permissionCodes.recycleExchange.verify, + permissionCodes.recycleExchange.cancel, + permissionCodes.recycleExchange.revoke, permissionCodes.fundRecord.read, permissionCodes.fund.refund, permissionCodes.fund.revoke, diff --git a/src/utils/recycle.ts b/src/utils/recycle.ts new file mode 100644 index 0000000..c548a3f --- /dev/null +++ b/src/utils/recycle.ts @@ -0,0 +1,90 @@ +import type { RecycleExchange, RecycleExchangeActionType, RecycleExchangeStatus, RecycleStatus } from "@/types/Recycle"; +import { comparePackageQuantity, getPackageQuantityText } from "@/utils/package"; + +/** 配置状态(回收物、规则)的展示文案。 */ +export function getRecycleStatusText(status?: RecycleStatus): string { + return ({ ACTIVE: "启用", INACTIVE: "停用" } as Record)[status || ""] || "未知"; +} + +export function getRecycleStatusTheme(status?: RecycleStatus): "success" | "warning" | "default" { + if (status === "ACTIVE") { + return "success"; + } + if (status === "INACTIVE") { + return "warning"; + } + return "default"; +} + +/** 兑换单状态文案。 */ +export function getRecycleExchangeStatusText(status?: RecycleExchangeStatus): string { + return ({ + PENDING: "待核销", + VERIFIED: "已核销", + CANCELLED: "已撤销", + REVOKED: "已冲正" + } as Record)[status || ""] || "未知"; +} + +export function getRecycleExchangeStatusTheme(status?: RecycleExchangeStatus): "success" | "warning" | "danger" | "primary" { + if (status === "VERIFIED") { + return "success"; + } + if (status === "PENDING") { + return "warning"; + } + if (status === "CANCELLED") { + return "danger"; + } + // 已冲正用主色,默认灰标签在深色模式下会变成白底不可读 + return "primary"; +} + +/** 操作记录类型文案。 */ +export function getRecycleActionText(type?: RecycleExchangeActionType): string { + return ({ VERIFY: "核销", CANCEL: "撤销", REVOKE: "冲正" } as Record)[type || ""] || "未知操作"; +} + +/** 兑换单可执行的操作,服务端仍会按状态和权限二次校验。 */ +export function canVerifyExchange(status?: RecycleExchangeStatus): boolean { + return status === "PENDING"; +} + +export function canCancelExchange(status?: RecycleExchangeStatus): boolean { + return status === "PENDING"; +} + +export function canRevokeExchange(status?: RecycleExchangeStatus): boolean { + return status === "VERIFIED"; +} + +/** 拼接「数量 + 单位」,后端 BigDecimal 可能是字符串。 */ +export function getRecycleQuantityText(value: number | string | null | undefined, unit?: string | null): string { + const quantityText = getPackageQuantityText(value); + return unit ? `${quantityText} ${unit}` : quantityText; +} + +/** + * 按整数倍数放大规则数量。 + * + * 用 BigInt 做定点乘法,避免 0.5 × 3 这类组合出现二进制浮点尾数。 + * 倍数可能来自 TDesign Stepper,它的 formatNumber 返回字符串(如 "2"、"2.0"), + * 所以必须先转数字,不能直接对入参用 Number.isFinite。 + */ +export function multiplyRecycleQuantity(value: number | string | null | undefined, multiple: number | string | null | undefined): string { + const quantityText = getPackageQuantityText(value); + const [integerText, fractionText = ""] = quantityText.split("."); + const multipleValue = Number(multiple); + const multiplier = Number.isFinite(multipleValue) && 0 < multipleValue ? Math.trunc(multipleValue) : 0; + const digits = BigInt(`${integerText}${fractionText}`) * BigInt(multiplier); + const padded = digits.toString().padStart(fractionText.length + 1, "0"); + const integer = fractionText.length ? padded.slice(0, -fractionText.length) : padded; + const fraction = fractionText.length ? padded.slice(-fractionText.length).replace(/0+$/, "") : ""; + return fraction ? `${integer}.${fraction}` : integer; +} + +/** 实际数量是否被有权限的操作人调整过(与预设值不同)。 */ +export function isRecycleQuantityAdjusted(exchange: RecycleExchange): boolean { + return comparePackageQuantity(exchange.recycleQuantity ?? "0", exchange.defaultRecycleQuantity ?? "0") !== 0 + || comparePackageQuantity(exchange.exchangeQuantity ?? "0", exchange.defaultExchangeQuantity ?? "0") !== 0; +}