修复:修复标签店铺绑定与作品优惠券选择
This commit is contained in:
@@ -270,6 +270,7 @@ export interface Tag {
|
||||
bgColor?: string
|
||||
borderColor?: string
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ getShopName(record.shopId) }}</span>
|
||||
<span>{{ record.shopName || getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'price'">
|
||||
<span style="color: #cf1322; font-weight: 600;">
|
||||
@@ -234,7 +234,7 @@
|
||||
placeholder="请选择优惠券"
|
||||
style="width: 100%"
|
||||
:loading="loadingCoupons"
|
||||
:disabled="!isShopOwner()"
|
||||
:disabled="isCouponSelectionDisabled"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="coupons.length === 0"
|
||||
@@ -251,6 +251,24 @@
|
||||
{{ coupon?.couponName || '' }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
<a-space class="coupon-actions">
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="isCouponSelectionDisabled || coupons.length === 0"
|
||||
@click="handleSelectAllCoupons"
|
||||
>
|
||||
一键全选
|
||||
</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="isCouponSelectionDisabled || formState.availableCoupons.length === 0"
|
||||
@click="handleClearAvailableCoupons"
|
||||
>
|
||||
清空
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</template>
|
||||
</a-form>
|
||||
@@ -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<string, any>) => {
|
||||
// 获取该店铺的美甲师列表
|
||||
if (recordShopId) {
|
||||
await fetchArtists(recordShopId)
|
||||
await fetchCoupons(recordShopId)
|
||||
}
|
||||
await restoreDraft()
|
||||
|
||||
@@ -785,6 +832,7 @@ const showViewModal = async (record: Product | Record<string, any>) => {
|
||||
// 获取该店铺的美甲师列表
|
||||
if (recordShopId) {
|
||||
await fetchArtists(recordShopId)
|
||||
await fetchCoupons(recordShopId)
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
@@ -1097,11 +1145,24 @@ const handleDelete = async (record: Product | Record<string, any>) => {
|
||||
}
|
||||
}
|
||||
|
||||
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 = []
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -1146,4 +1210,8 @@ watch(() => formState.shopId, (newShopId) => {
|
||||
line-height: 1.6;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.coupon-actions {
|
||||
margin-top: 6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ getShopName(record.shopId) }}</span>
|
||||
<span>{{ record.shopName || getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
@@ -333,8 +333,16 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getShopName = (shopId: number) => {
|
||||
const shop = shops.value.find(s => s.id === shopId)
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
const getShopName = (shopId: number | string | undefined) => {
|
||||
const normalizedShopId = normalizeShopIdValue(shopId)
|
||||
const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
@@ -419,8 +427,9 @@ const handleModalOk = async () => {
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
fetchTags()
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('Error:', error)
|
||||
message.error(error?.message || (isEdit.value ? '更新失败' : '创建失败'))
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user