diff --git a/src/api/ProductAPI.ts b/src/api/ProductAPI.ts index 36402d3..32bb29b 100644 --- a/src/api/ProductAPI.ts +++ b/src/api/ProductAPI.ts @@ -12,6 +12,7 @@ import type { ProductStockBatchRequest, ProductStockProduct, ProductStockChangeRequest, + ProductStockManualInBatchRequest, ProductStockManualRevokeRequest, ProductStockPage, StockRecord, @@ -132,6 +133,10 @@ async function manualIn(request: ProductStockChangeRequest): Promise { + return await axios.post(`${STOCK_URI}/manual-in/batch`, withCurrentStoreId(request)); +} + async function manualOut(request: ProductStockChangeRequest): Promise { return await axios.post(`${STOCK_URI}/manual-out`, withCurrentStoreId(request)); } @@ -184,6 +189,7 @@ export default { stockBatchDetail, initialIn, manualIn, + manualInBatch, manualOut, manualRevoke, stocktakeGain, diff --git a/src/components/ProductSelector.vue b/src/components/ProductSelector.vue deleted file mode 100644 index f94a58c..0000000 --- a/src/components/ProductSelector.vue +++ /dev/null @@ -1,349 +0,0 @@ - - - - - diff --git a/src/components/productSelector/ProductSelector.vue b/src/components/productSelector/ProductSelector.vue new file mode 100644 index 0000000..fbccfbb --- /dev/null +++ b/src/components/productSelector/ProductSelector.vue @@ -0,0 +1,174 @@ + + + + + diff --git a/src/components/productSelector/ProductSkuOptions.vue b/src/components/productSelector/ProductSkuOptions.vue new file mode 100644 index 0000000..3eb700f --- /dev/null +++ b/src/components/productSelector/ProductSkuOptions.vue @@ -0,0 +1,284 @@ + + + + + diff --git a/src/components/productSelector/ProductSkuSelector.vue b/src/components/productSelector/ProductSkuSelector.vue new file mode 100644 index 0000000..72ef74d --- /dev/null +++ b/src/components/productSelector/ProductSkuSelector.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/src/layout/MainLayout.vue b/src/layout/MainLayout.vue index 98cb89c..6834a75 100644 --- a/src/layout/MainLayout.vue +++ b/src/layout/MainLayout.vue @@ -51,7 +51,7 @@ const globalUIStore = useGlobalUIStore(); const tabBarStore = useTabBarStore(); const userStore = useUserStore(); -const cachedRouteNames = new Set(["SalesOrderList", "ProductList", "ProductStockList"]); +const cachedRouteNames = new Set(["SalesOrderList", "ProductList", "ProductStockList", "ProductStockBatchSelect", "ProductStockBatchConfigure"]); function shouldKeepAlive(sourceRoute: RouteLocationNormalizedLoaded): boolean { return cachedRouteNames.has(String(sourceRoute.name)); diff --git a/src/pages/point/PointRedeemSkuEdit.vue b/src/pages/point/PointRedeemSkuEdit.vue index 775675e..486e53e 100644 --- a/src/pages/point/PointRedeemSkuEdit.vue +++ b/src/pages/point/PointRedeemSkuEdit.vue @@ -57,7 +57,7 @@ + + diff --git a/src/pages/product/ProductStockBatchSelect.vue b/src/pages/product/ProductStockBatchSelect.vue new file mode 100644 index 0000000..420d2ca --- /dev/null +++ b/src/pages/product/ProductStockBatchSelect.vue @@ -0,0 +1,398 @@ + + + + + diff --git a/src/pages/product/ProductStockList.vue b/src/pages/product/ProductStockList.vue index d770286..24ade4e 100644 --- a/src/pages/product/ProductStockList.vue +++ b/src/pages/product/ProductStockList.vue @@ -65,13 +65,16 @@ import { useUserStore } from "timi-web-api"; import { onBeforeRouteLeave } from "vue-router"; import ProductAPI from "@/api/ProductAPI"; +import { useCurrentStoreStore } from "@/store/currentStoreStore"; import { useNavBarStore } from "@/store/navBarStore"; +import { useProductStockBatchStore } from "@/store/productStockBatchStore"; import type { ProductStockProduct } from "@/types/Product"; import { getErrorMessage } from "@/utils/error"; import { getProductPhotoURL, getProductQuantityText } from "@/utils/product"; import { events, isCurrentStoreEvent, listDataEventKeys, type ListDataChangedPayload } from "@/utils/listDataEvents"; import { Message } from "@/utils/message"; import { permissionCodes } from "@/utils/permission"; +import { getCurrentStoreId } from "@/utils/store"; defineOptions({ name: "ProductStockList" }); @@ -80,6 +83,8 @@ const route = useRoute(); const productStockListRef = ref(null); const navBarStore = useNavBarStore(); const userStore = useUserStore(); +const currentStoreStore = useCurrentStoreStore(); +const productStockBatchStore = useProductStockBatchStore(); const keyword = ref(""); const productList = ref([]); const pageIndex = ref(0); @@ -126,11 +131,35 @@ function restorePageScrollPosition(): void { } const emptyText = computed(() => isLoading.value ? "正在加载产品" : keyword.value ? "未找到匹配产品" : "暂无启用库存管理的产品"); +const canBatchIn = computed(() => + userStore.hasPermissions(permissionCodes.productStock.read) + && userStore.hasPermissions(permissionCodes.productStock.create) +); function getCurrentRouteDepth(): number { return Number(route.meta.depth ?? 0); } +function updateNavBar(): void { + navBarStore.clearRight(); + if (canBatchIn.value) { + navBarStore.setRightText("批量入库", "var(--td-brand-color)", openBatchIn); + } +} + +async function openBatchIn(): Promise { + const storeId = currentStoreStore.currentStoreId || getCurrentStoreId(); + if (!storeId) { + Message.warning("请先选择门店"); + return; + } + productStockBatchStore.start(storeId); + await router.push({ + name: "ProductStockBatchSelect", + query: { transitionDepth: String(getCurrentRouteDepth() + 1) } + }); +} + async function fetch(reset = false, preserveScroll = false): Promise { if (!reset && (isLoading.value || isNoMore.value)) { return; @@ -272,7 +301,7 @@ async function toSkuList(item: ProductStockProduct): Promise { onMounted(async () => { unregisterProductStockListEvent = events.register(listDataEventKeys.productStockChanged, (payload: ListDataChangedPayload) => requestEventRefresh(payload)); - navBarStore.clearRight(); + updateNavBar(); if (!userStore.hasPermissions(permissionCodes.productStock.read)) { return; } @@ -285,6 +314,7 @@ onMounted(async () => { onActivated(() => { restorePageScrollPosition(); + updateNavBar(); }); onDeactivated(() => { diff --git a/src/router/routes/productRoutes.ts b/src/router/routes/productRoutes.ts index a547ba1..6f8fbcf 100644 --- a/src/router/routes/productRoutes.ts +++ b/src/router/routes/productRoutes.ts @@ -61,6 +61,18 @@ const productRoutes: RouteRecordRaw[] = [ component: () => import("@/pages/product/ProductStockSkuList.vue"), meta: pageMeta("选择 SKU", 4) }, + { + path: "/management/product-stocks/batch/select", + name: "ProductStockBatchSelect", + component: () => import("@/pages/product/ProductStockBatchSelect.vue"), + meta: pageMeta("选择入库 SKU", 4) + }, + { + path: "/management/product-stocks/batch/configure", + name: "ProductStockBatchConfigure", + component: () => import("@/pages/product/ProductStockBatchConfigure.vue"), + meta: pageMeta("批量入库", 5) + }, { path: "/management/product-stock-records", name: "ProductStockRecordList", diff --git a/src/store/productStockBatchStore.ts b/src/store/productStockBatchStore.ts new file mode 100644 index 0000000..4554959 --- /dev/null +++ b/src/store/productStockBatchStore.ts @@ -0,0 +1,75 @@ +import type { ProductSku } from "@/types/Product"; +import type { PhotoItem } from "@/types/Photo"; + +export type ProductStockBatchSelection = { + productId: string; + productName: string; + sku: ProductSku; + quantity: string; + skuUnitId: string; + attachmentItems: PhotoItem[]; +}; + +export const useProductStockBatchStore = defineStore("product-stock-batch", () => { + const storeId = ref(""); + const selectedItemList = ref([]); + const remark = ref(""); + const attachmentItems = ref([]); + const requestNo = ref(""); + + function reset(): void { + storeId.value = ""; + selectedItemList.value = []; + remark.value = ""; + attachmentItems.value = []; + requestNo.value = ""; + } + + function start(storeIdValue: string): void { + reset(); + storeId.value = storeIdValue; + } + + function ensureStore(storeIdValue: string): void { + if (storeId.value === storeIdValue) { + return; + } + start(storeIdValue); + } + + function hasSku(skuId: string): boolean { + return selectedItemList.value.some(item => item.sku.id === skuId); + } + + function toggleSelection(item: Omit): void { + const skuId = item.sku.id; + if (!skuId) { + return; + } + const itemIndex = selectedItemList.value.findIndex(selectedItem => selectedItem.sku.id === skuId); + if (0 <= itemIndex) { + selectedItemList.value.splice(itemIndex, 1); + return; + } + const defaultUnit = item.sku.unitList?.find(unit => unit.allowPurchase && unit.id); + selectedItemList.value.push({ + ...item, + quantity: "", + skuUnitId: defaultUnit?.id || "", + attachmentItems: [] + }); + } + + return { + storeId, + selectedItemList, + remark, + attachmentItems, + requestNo, + reset, + start, + ensureStore, + hasSku, + toggleSelection + }; +}); diff --git a/src/types/Product.ts b/src/types/Product.ts index aa0ccbf..4996271 100644 --- a/src/types/Product.ts +++ b/src/types/Product.ts @@ -226,6 +226,21 @@ export type ProductStockChangeRequest = { attachmentList: Partial[]; }; +export type ProductStockManualInBatchItem = { + skuId: string; + skuUnitId: string; + quantity: number | string; + attachmentList?: Partial[]; +}; + +export type ProductStockManualInBatchRequest = { + requestNo: string; + storeId?: string; + remark: string; + attachmentList?: Partial[]; + itemList: ProductStockManualInBatchItem[]; +}; + export type ProductStockManualRevokeRequest = { requestNo: string; sourceRecordId: string; diff --git a/src/types/ProductSkuSelection.ts b/src/types/ProductSkuSelection.ts new file mode 100644 index 0000000..9bd1e3c --- /dev/null +++ b/src/types/ProductSkuSelection.ts @@ -0,0 +1,25 @@ +import type { Product, ProductSku } from "./Product"; + +/** SKU 与销售单位共同确定一项选择。 */ +export type ProductSkuSelectionValue = { + skuId: string; + skuUnitId: string; +}; + +/** SKU 选择模式。 */ +export type ProductSkuSelectionMode = "single" | "multiple"; + +/** 产品 SKU 选择器中的产品面板。 */ +export interface ProductSkuSelectorItem { + key: string; + name: string; + photoUrl?: string; + product?: Product; + skuList?: ProductSku[]; + /** 多选模式下可直接切换的唯一 SKU。 */ + singleSkuId?: string; + skuCount?: number; + selectedSkuCount?: number; + checkLoading?: boolean; + message?: string; +}