add ProductStockBatchSelect.vue

This commit is contained in:
Timi
2026-10-15 15:29:56 +08:00
parent d8ac19baa7
commit a5ac6c5e69
14 changed files with 1605 additions and 352 deletions
+75
View File
@@ -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<ProductStockBatchSelection[]>([]);
const remark = ref("");
const attachmentItems = ref<PhotoItem[]>([]);
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<ProductStockBatchSelection, "quantity" | "skuUnitId" | "attachmentItems">): 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
};
});