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.
This commit is contained in:
50
app/composables/biddingItems.ts
Normal file
50
app/composables/biddingItems.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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);
|
||||
@@ -4,7 +4,7 @@ export type Item = {
|
||||
id: number;
|
||||
brand?: string;
|
||||
name: string;
|
||||
imageUrl?: string | null;
|
||||
imageUrl?: string;
|
||||
description?: string | null;
|
||||
tags?: string[] | null;
|
||||
createdAt?: Date;
|
||||
|
||||
Reference in New Issue
Block a user