diff --git a/Frontend/src/api/admin.ts b/Frontend/src/api/admin.ts index 2e64326f..7603fd59 100644 --- a/Frontend/src/api/admin.ts +++ b/Frontend/src/api/admin.ts @@ -270,6 +270,7 @@ export interface Tag { bgColor?: string borderColor?: string shopId?: number + shopName?: string createTime: string updateTime: string } diff --git a/Frontend/src/views/admin/ProductsView.vue b/Frontend/src/views/admin/ProductsView.vue index 6620f1fe..6ecca402 100644 --- a/Frontend/src/views/admin/ProductsView.vue +++ b/Frontend/src/views/admin/ProductsView.vue @@ -51,7 +51,7 @@ @@ -469,10 +487,18 @@ const columns = [ ] const getShopName = (shopId: number): string => { - const shop = shops.value.find(s => s.id === shopId) + const normalizedShopId = normalizeShopIdValue(shopId) + const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId) return shop ? shop.shopName : '未知店铺' } +const normalizeShopIdValue = (value: string | number | undefined | null) => { + if (value === undefined || value === null || value === '') { + return '' + } + return String(value) +} + const getCurrentUserInfo = () => { try { const userInfoStr = localStorage.getItem('adminUserInfo') @@ -488,11 +514,13 @@ const getCurrentUserInfo = () => { return null } -const isShopOwner = () => { +const canManageAvailableCoupons = () => { const userInfo = getCurrentUserInfo() - return userInfo && userInfo.type === 2 + return Boolean(userInfo && (userInfo.type === 2 || userInfo.type === 4)) } +const isCouponSelectionDisabled = computed(() => !canManageAvailableCoupons()) + const fetchShops = async () => { loadingShops.value = true try { @@ -556,12 +584,29 @@ const fetchArtists = async (shopId?: number) => { } } -const fetchCoupons = async () => { +const syncAvailableCouponSelection = () => { + const availableCouponIdSet = new Set( + coupons.value + .map(coupon => coupon?.id) + .filter((id): id is number => id !== undefined && id !== null) + .map(id => String(id)) + ) + formState.availableCoupons = formState.availableCoupons.filter(couponId => availableCouponIdSet.has(String(couponId))) +} + +const fetchCoupons = async (shopId?: number) => { + if (!shopId) { + coupons.value = [] + formState.availableCoupons = [] + return + } + loadingCoupons.value = true try { - const response = await adminCouponApi.listAllCoupons() + const response = await adminCouponApi.listAllCoupons(shopId) const res = typeof response === 'object' && 'data' in response ? response.data : response coupons.value = (res as any[]) || [] + syncAvailableCouponSelection() } catch (error) { console.error('获取优惠券列表失败', error) message.error('获取优惠券列表失败') @@ -669,6 +714,7 @@ const showAddModal = async () => { // 如果有店铺ID,获取该店铺的美甲师列表 if (shopId) { fetchArtists(shopId) + fetchCoupons(shopId) } await restoreDraft() modalVisible.value = true @@ -721,6 +767,7 @@ const showEditModal = async (record: Product | Record) => { // 获取该店铺的美甲师列表 if (recordShopId) { await fetchArtists(recordShopId) + await fetchCoupons(recordShopId) } await restoreDraft() @@ -785,6 +832,7 @@ const showViewModal = async (record: Product | Record) => { // 获取该店铺的美甲师列表 if (recordShopId) { await fetchArtists(recordShopId) + await fetchCoupons(recordShopId) } viewModalVisible.value = true @@ -1097,11 +1145,24 @@ const handleDelete = async (record: Product | Record) => { } } +const handleSelectAllCoupons = () => { + if (isCouponSelectionDisabled.value) { + return + } + formState.availableCoupons = coupons.value + .map(coupon => coupon?.id) + .filter((id): id is number => id !== undefined && id !== null) + .map(id => String(id)) +} + +const handleClearAvailableCoupons = () => { + formState.availableCoupons = [] +} + onMounted(async () => { await loadUserPermissions() fetchShops() fetchTags() - fetchCoupons() fetchProductList() }) @@ -1110,9 +1171,12 @@ watch(() => formState.shopId, (newShopId) => { if (newShopId) { fetchTags(newShopId) fetchArtists(newShopId) + fetchCoupons(newShopId) } else { tags.value = [] artists.value = [] + coupons.value = [] + formState.availableCoupons = [] } }) @@ -1146,4 +1210,8 @@ watch(() => formState.shopId, (newShopId) => { line-height: 1.6; margin-top: 6px; } + +.coupon-actions { + margin-top: 6px; +} diff --git a/Frontend/src/views/admin/TagsView.vue b/Frontend/src/views/admin/TagsView.vue index 27dedddf..bb8c22df 100644 --- a/Frontend/src/views/admin/TagsView.vue +++ b/Frontend/src/views/admin/TagsView.vue @@ -42,7 +42,7 @@