Files
bid-setup.tootaio.com/app/composables/biddingItems.ts
xiaomai 802c4460a7 feat(export): implement export page for bidding items
Introduces a new export page for creating and managing bidding lists. Key features include: selecting items from a
master list, adding them to a bidding list, editing start price/remarks, batch price updates, and drag-and-drop
reordering. The final list can be previewed and exported as a CSV. This change adds the `useBiddingItems` composable and
the `sortablejs` dependency. Also refactors `imageUrl` to be a non-nullable string for type consistency.
2025-10-20 17:33:48 +08:00

51 lines
1.4 KiB
TypeScript

import { createSharedComposable } from "@vueuse/core";
export type BiddingItem = {
id: number;
name: string;
startPrice: number;
remarks: string;
imageUrl?: string;
};
const _useBiddingItems = () => {
const biddingItems = ref<BiddingItem[]>([]);
const biddingItemsLatestId = computed(() => {
const arr = biddingItems.value ?? [];
if (arr.length === 0) return 1;
return Math.max(...arr.map((i) => i.id)) + 1;
});
const addBiddingItem = (item: Item, startPrice: number) => {
biddingItems.value.push({
id: biddingItemsLatestId.value,
name: `${item.brand} ${item.name}`,
startPrice: startPrice,
remarks: "",
imageUrl: item.imageUrl,
});
};
const removeBiddingItem = (id: number) => {
biddingItems.value = (biddingItems.value ?? []).filter((i) => i.id !== id);
};
const editBiddingItem = (biddingItem: BiddingItem) => {
const idx = (biddingItems.value ?? []).findIndex(
(i) => i.id === biddingItem.id
);
if (idx === -1) return;
const updatedBiddingItems = [...(biddingItems.value ?? [])];
updatedBiddingItems[idx] = {
...updatedBiddingItems[idx],
...biddingItem,
};
biddingItems.value = updatedBiddingItems;
};
return { biddingItems, addBiddingItem, removeBiddingItem, editBiddingItem };
};
export const useBiddingItems = createSharedComposable(_useBiddingItems);