功能:完善多店铺登录与首次部署SQL

This commit is contained in:
xiaowang
2026-03-26 10:28:28 +08:00
parent 5601428087
commit 764bfadb51
79 changed files with 6524 additions and 2603 deletions
+400 -85
View File
@@ -5,15 +5,36 @@
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>购物车</h1>
<a-button type="text">编辑</a-button>
<a-button type="text" @click="editing = !editing">
{{ editing ? '完成' : '批量删除' }}
</a-button>
</header>
<main class="content">
<a-empty v-if="!cartItems.length" description="购物车是空的">
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
<a-empty v-if="!cartItems.length" description="购物车还是空的">
<a-button type="primary" @click="router.push('/products')">去逛作品</a-button>
</a-empty>
<a-card v-for="item in cartItems" :key="item.id" class="item-card">
<a-alert
v-if="selectedCount && checkoutIssues.length && !editing"
class="issue-alert"
type="warning"
show-icon
:message="`还有 ${checkoutIssues.length} 项待完善`"
:description="checkoutIssues.map(issue => issue.message).join(';')"
>
<template #action>
<a-button size="small" @click="focusFirstIssue">定位问题</a-button>
</template>
</a-alert>
<a-card
v-for="item in cartItems"
:key="item.id"
:ref="element => setItemRef(item.id, element)"
class="item-card"
:class="{ 'issue-card': item.selected && hasItemIssue(item) }"
>
<div class="item-row">
<a-checkbox v-model:checked="item.selected" @change="loadAvailableCoupons" />
<div class="thumb" @click="openProduct(item)">
@@ -22,15 +43,19 @@
</div>
<div class="item-main">
<div class="title" @click="openProduct(item)">{{ item.productTitle }}</div>
<div class="price">¥{{ item.price.toFixed(2) }}</div>
<div class="price">¥{{ Number(item.price || 0).toFixed(2) }}</div>
<div class="selector" @click="openBookingModal(item)">
<div class="selector" :class="{ issue: item.selected && !item.artistId }" @click="openBookingModal(item)">
<span class="label">美甲师</span>
<span class="value">{{ item.artist?.name || '请选择美甲师' }}</span>
<RightOutlined />
</div>
<div class="selector" @click="openBookingModal(item)">
<div
class="selector"
:class="{ issue: item.selected && (!item.appointmentTime || isPastAppointment(item.appointmentTime)) }"
@click="openBookingModal(item)"
>
<span class="label">预约时间</span>
<span class="value">
{{ item.appointmentTime ? formatAppointmentDisplay(item.appointmentTime) : (item.artistId ? '请选择预约时间' : '先选择美甲师') }}
@@ -46,7 +71,7 @@
<span>{{ item.quantity }}</span>
<a-button size="small" :disabled="item.quantity >= 99" @click="changeQuantity(item, 1)">+</a-button>
</div>
<a-popconfirm title="确定删除吗?" ok-text="确认" cancel-text="取消" @confirm="removeItem(item)">
<a-popconfirm title="确认删除这件作品吗?" ok-text="确认" cancel-text="取消" @confirm="removeItem(item)">
<a-button type="text" danger size="small">
<DeleteOutlined />
</a-button>
@@ -56,37 +81,56 @@
</div>
</a-card>
<a-card v-if="selectedCount" class="coupon-card" @click="openCouponModal">
<a-card v-if="selectedCount && !editing" class="coupon-card" @click="openCouponModal">
<div class="coupon-row">
<span>优惠券</span>
<span>{{ selectedCoupon ? formatCouponDisplay(selectedCoupon) : '使用优惠券' }}</span>
<span>优惠方式</span>
<span>{{ selectedCoupon ? formatCouponDisplay(selectedCoupon) : '不使用优惠' }}</span>
</div>
<div v-if="selectedCoupon" class="coupon-extra">
<span>{{ selectedCoupon.sourceType === 'SYSTEM_VIP' ? '当前为 VIP 自动折扣,不会消耗用户券。' : '当前为用户券,只有下单成功才会消耗。' }}</span>
<strong>-¥{{ discountAmount.toFixed(2) }}</strong>
</div>
<div v-if="selectedCoupon" class="coupon-discount">优惠金额 -¥{{ discountAmount.toFixed(2) }}</div>
</a-card>
<a-card v-if="cartItems.length" class="summary-card">
<a-card v-if="cartItems.length && !editing" class="summary-card">
<div class="summary-row"><span>选中项目</span><span>{{ selectedCount }} 项</span></div>
<div class="summary-row"><span>作品数量</span><span>{{ totalQuantity }} 件</span></div>
<div class="summary-row"><span>小计</span><span>¥{{ subtotal.toFixed(2) }}</span></div>
<div v-if="selectedCoupon" class="summary-row"><span>优惠</span><span>-¥{{ discountAmount.toFixed(2) }}</span></div>
<div class="summary-row total"><span>总计</span><span>¥{{ totalAmount.toFixed(2) }}</span></div>
<div class="summary-row total"><span>合计</span><span>¥{{ totalAmount.toFixed(2) }}</span></div>
</a-card>
</main>
<footer v-if="cartItems.length" class="footer">
<a-button type="primary" size="large" block @click="checkout">
结算 {{ selectedCount }} 个项目,预计金额 ¥{{ totalAmount.toFixed(2) }}
<a-button
v-if="editing"
danger
size="large"
block
@click="removeSelectedItems"
>
删除已选中的 {{ selectedCount }} 项
</a-button>
<a-button
v-else
type="primary"
size="large"
block
@click="checkout"
>
结算 {{ selectedCount }} 项,预计金额 ¥{{ totalAmount.toFixed(2) }}
</a-button>
</footer>
<a-modal v-model:open="showCouponModal" title="使用优惠券" @ok="applyCouponSelection" @cancel="showCouponModal = false">
<a-modal v-model:open="showCouponModal" title="选择优惠方式" @ok="applyCouponSelection" @cancel="showCouponModal = false">
<a-radio-group v-model:value="couponSelectionKey" class="coupon-options">
<a-radio :value="NO_COUPON_KEY">不使用优惠券</a-radio>
<a-radio :value="NO_COUPON_KEY">不使用优惠</a-radio>
<a-radio v-for="coupon in availableCoupons" :key="getCouponKey(coupon)" :value="getCouponKey(coupon)">
{{ formatCouponDisplay(coupon) }}
</a-radio>
</a-radio-group>
<div class="coupon-tip">
系统只会默认预选 VIP 自动券,普通用户券需要你手动选择后才会在下单时使用。
系统只会默认预选最佳 VIP 自动券,普通用户券需要你手动选择后才会在下单时使用。
</div>
</a-modal>
@@ -106,7 +150,7 @@
<span>{{ artist.name }}</span>
</button>
</div>
<a-empty v-else description="暂无可用美甲师" />
<a-empty v-else description="暂无可预约美甲师" />
</div>
<div class="modal-section">
@@ -173,8 +217,15 @@ interface CartItem {
artist?: ArtistOption
}
interface CheckoutIssue {
key: string
message: string
itemId?: number
}
const cartItems = ref<CartItem[]>([])
const imageIdCache = ref<Record<string, string>>({})
const itemRefs = ref<Record<number, HTMLElement>>({})
const availableCoupons = ref<UserCoupon[]>([])
const selectedCoupon = ref<UserCoupon | null>(null)
const couponSelectionKey = ref(NO_COUPON_KEY)
@@ -186,18 +237,19 @@ const availableArtists = ref<ArtistOption[]>([])
const draftArtistId = ref<number>()
const draftAppointmentTime = ref('')
const currentShopHours = ref('')
const editing = ref(false)
const selectedItems = computed(() => cartItems.value.filter(item => item.selected))
const selectedCount = computed(() => selectedItems.value.length)
const totalQuantity = computed(() => selectedItems.value.reduce((sum, item) => sum + item.quantity, 0))
const subtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + item.price * item.quantity, 0))
const subtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + Number(item.price || 0) * item.quantity, 0))
const discountAmount = computed(() => calculateCouponDiscount(selectedCoupon.value, subtotal.value))
const totalAmount = computed(() => Math.max(0, subtotal.value - discountAmount.value))
const bookingTitle = computed(() => currentItem.value ? '为 ' + currentItem.value.productTitle + ' 选择预约信息' : '选择预约信息')
const bookingTitle = computed(() => currentItem.value ? `为 ${currentItem.value.productTitle} 选择预约信息` : '选择预约信息')
const bookingHelperText = computed(() => {
const texts: string[] = []
if (currentShopHours.value) texts.push('门店营业时间:' + currentShopHours.value)
if (currentItem.value?.approximateDuration) texts.push('预计时长:' + currentItem.value.approximateDuration)
if (currentShopHours.value) texts.push(`门店营业时间:${currentShopHours.value}`)
if (currentItem.value?.approximateDuration) texts.push(`预计时长:${currentItem.value.approximateDuration}`)
return texts.join(' · ') || '请选择至少晚于当前 5 分钟的预约时间'
})
@@ -216,16 +268,33 @@ const getDayBoundary = (date: Date) => {
const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
const setItemRef = (itemId: number, element: unknown) => {
if (element && (element as any).$el) {
itemRefs.value[itemId] = (element as any).$el as HTMLElement
return
}
if (element instanceof HTMLElement) {
itemRefs.value[itemId] = element
return
}
delete itemRefs.value[itemId]
}
const formatCouponDisplay = (coupon: UserCoupon) => {
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
const benefit = coupon.couponType === 1
? `${coupon.discountValue} 折`
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
return `${badge} ${coupon.couponName} ${benefit}`
}
const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
if (!coupon || amount <= 0) {
return 0
}
if (coupon.couponType === 1) {
const discountValue = Number(coupon.discountValue || 0)
if (!discountValue) {
return 0
}
return amount - amount * discountValue / 10
return discountValue ? amount - amount * discountValue / 10 : 0
}
if (coupon.couponType === 2) {
return Number(coupon.reduceAmount || 0)
@@ -233,27 +302,63 @@ const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
return 0
}
const formatCouponDisplay = (coupon: UserCoupon) => {
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
const benefit = coupon.couponType === 1
? `${coupon.discountValue}折`
: `满${coupon.minAmount}减${coupon.reduceAmount}`
return `${badge} ${coupon.couponName} ${benefit}`
}
const findBestSystemVipCoupon = (coupons: UserCoupon[]) => {
return coupons
.filter(coupon => coupon.sourceType === 'SYSTEM_VIP')
.sort((left, right) => calculateCouponDiscount(right, subtotal.value) - calculateCouponDiscount(left, subtotal.value))[0] || null
}
const openProduct = (item: CartItem) => {
router.push('/product/' + item.productId)
const formatAppointmentDisplay = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '未选择预约时间'
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() < getMinAppointmentDate().getTime()
const hasItemIssue = (item: CartItem) => !item.artistId || !item.appointmentTime || isPastAppointment(item.appointmentTime)
const checkoutIssues = computed<CheckoutIssue[]>(() => {
const items = selectedItems.value
const issues: CheckoutIssue[] = []
const firstMissingArtist = items.find(item => !item.artistId)
if (firstMissingArtist) {
issues.push({ key: 'artist', message: `请先为“${firstMissingArtist.productTitle}”选择美甲师`, itemId: firstMissingArtist.id })
}
const firstMissingTime = items.find(item => !item.appointmentTime)
if (firstMissingTime) {
issues.push({ key: 'time', message: `请先为“${firstMissingTime.productTitle}”选择预约时间`, itemId: firstMissingTime.id })
}
const firstExpiredTime = items.find(item => isPastAppointment(item.appointmentTime))
if (firstExpiredTime) {
issues.push({ key: 'expired', message: `“${firstExpiredTime.productTitle}”的预约时间已过期,请重新选择`, itemId: firstExpiredTime.id })
}
if (new Set(items.map(item => item.shopId).filter(Boolean)).size > 1) {
issues.push({ key: 'shop', message: '跨店铺项目请分开结算', itemId: items[0]?.id })
}
if (new Set(items.map(item => item.artistId).filter(Boolean)).size > 1) {
issues.push({ key: 'artist-mix', message: '不同美甲师的项目请分开结算', itemId: items[0]?.id })
}
return issues
})
const scrollToIssue = (issue?: CheckoutIssue) => {
if (!issue?.itemId) {
return
}
const target = itemRefs.value[issue.itemId]
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
}
const focusFirstIssue = () => {
scrollToIssue(checkoutIssues.value[0])
}
const loadCartItems = async () => {
const response = await cartApi.getCartList() as unknown as any[]
cartItems.value = response.map(item => ({
cartItems.value = (response || []).map(item => ({
...item,
selected: true,
originalProductImage: item.productImage,
@@ -263,6 +368,7 @@ const loadCartItems = async () => {
couponSelectionTouched.value = false
couponSelectionKey.value = NO_COUPON_KEY
selectedCoupon.value = null
editing.value = false
await Promise.all([loadProductImages(), loadAvailableCoupons()])
}
@@ -284,6 +390,10 @@ const loadProductImages = async () => {
}
const loadAvailableCoupons = async () => {
if (editing.value) {
return
}
const currentSelectedKey = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : couponSelectionKey.value
const selectedShopId = selectedItems.value[0]?.shopId
@@ -330,7 +440,7 @@ const loadAvailableCoupons = async () => {
couponSelectionKey.value = NO_COUPON_KEY
}
} catch (error) {
console.error('获取可用优惠券失败:', error)
console.error('获取可用优惠失败:', error)
availableCoupons.value = []
selectedCoupon.value = null
couponSelectionKey.value = NO_COUPON_KEY
@@ -361,6 +471,26 @@ const removeItem = async (item: CartItem) => {
}
}
const removeSelectedItems = async () => {
if (!selectedItems.value.length) {
message.warning('请先勾选要删除的作品')
return
}
try {
await Promise.all(selectedItems.value.map(item => cartApi.removeFromCart(item.productId)))
await Promise.all([loadCartItems(), updateCartCount()])
message.success('已删除选中的作品')
} catch (error) {
console.error('批量删除失败:', error)
message.error('批量删除失败,请稍后重试')
}
}
const openProduct = (item: CartItem) => {
router.push('/product/' + item.productId)
}
const openBookingModal = async (item: CartItem) => {
currentItem.value = item
draftArtistId.value = item.artistId
@@ -374,7 +504,13 @@ const loadArtists = async (item: CartItem) => {
const allowedIds = new Set((item.bookableArtists || '').split(',').map(id => Number(id.trim())).filter(id => Number.isFinite(id) && id > 0))
availableArtists.value = await Promise.all(
users
.filter(user => (!item.shopId || user.shopId === item.shopId) && (!allowedIds.size || allowedIds.has(user.id)))
.filter(user => user.status === 1)
.filter(user => {
const matchedShop = !item.shopId
|| user.shopId === item.shopId
|| (Array.isArray((user as any).shopIds) && (user as any).shopIds.some((shopId: string | number) => String(shopId) === String(item.shopId)))
return matchedShop && (!allowedIds.size || allowedIds.has(user.id))
})
.map(async user => {
try {
const detail = await api.get('/nail-artist/get/' + user.id) as any
@@ -397,14 +533,11 @@ const loadShopHours = async (shopId?: number) => {
}
}
const formatAppointmentDisplay = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '未选择预约时间'
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() < getMinAppointmentDate().getTime()
const disablePastAppointmentDate = (current: any) => {
if (!current) {
return false
}
if (!current) return false
return current.valueOf() < getDayBoundary(new Date())
}
const disablePastAppointmentTime = (current: any) => {
if (!current || typeof current.format !== 'function') {
return {}
@@ -466,12 +599,16 @@ const applyCouponSelection = () => {
const checkout = async () => {
const items = selectedItems.value
if (!items.length) return message.warning('请先选择要结算的作品')
if (items.some(item => !item.artistId)) return message.warning('请先为所有项目选择美甲师')
if (items.some(item => !item.appointmentTime)) return message.warning('请先为所有项目选择预约时间')
if (items.some(item => isPastAppointment(item.appointmentTime))) return message.warning('存在已过期的预约时间,请重新选择')
if (new Set(items.map(item => item.shopId).filter(Boolean)).size > 1) return message.warning('跨店铺商品请分开结算')
if (new Set(items.map(item => item.artistId).filter(Boolean)).size > 1) return message.warning('不同美甲师的项目请分开结算')
if (!items.length) {
return message.warning('请先选择要结算的作品')
}
const firstIssue = checkoutIssues.value[0]
if (firstIssue) {
message.warning(firstIssue.message)
scrollToIssue(firstIssue)
return
}
try {
await orderApi.createOrder({
@@ -510,41 +647,219 @@ onMounted(async () => {
</script>
<style scoped>
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
.header, .footer { position: fixed; left: 0; right: 0; background: #fff; z-index: 10; }
.header { top: 0; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; border-bottom: 1px solid #f0f0f0; }
.header h1 { margin: 0; font-size: 18px; }
.content { padding: 15px; padding-bottom: 140px; }
.item-card, .coupon-card, .summary-card { margin-bottom: 12px; border-radius: 12px; }
.item-row { display: flex; gap: 12px; align-items: flex-start; }
.thumb { width: 80px; height: 80px; border-radius: 8px; overflow: hidden; background: #eef3ff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-main { flex: 1; }
.title { font-weight: 600; cursor: pointer; }
.price { margin: 4px 0 10px; color: #ff4d4f; font-weight: 700; }
.selector { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 10px; border-radius: 8px; background: #f8f9ff; cursor: pointer; }
.selector .label { min-width: 56px; color: #666; font-size: 13px; }
.selector .value { flex: 1; color: #1890ff; font-size: 13px; }
.actions, .qty, .coupon-row, .summary-row { display: flex; align-items: center; justify-content: space-between; }
.qty { gap: 8px; }
.duration, .coupon-discount, .helper, .coupon-tip { color: #666; font-size: 12px; }
.coupon-tip { margin-top: 12px; line-height: 1.6; }
.summary-row.total { font-weight: 700; }
.footer { bottom: 60px; padding: 15px; border-top: 1px solid #f0f0f0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
.coupon-options { display: flex; flex-direction: column; gap: 8px; }
.modal-section + .modal-section { margin-top: 16px; }
.section-title { margin-bottom: 8px; font-weight: 600; }
.artist-list { display: flex; flex-wrap: wrap; gap: 8px; }
.artist-option { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 999px; background: #fff; cursor: pointer; }
.artist-option.active { border-color: #1890ff; color: #1890ff; background: #f0f9ff; }
.artist-option img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.time-picker { border-radius: 8px; }
.page {
min-height: 100vh;
padding-top: 60px;
background: #f5f5f5;
}
@media (min-width: 992px) {
.header,
.footer {
position: fixed;
left: 0;
right: 0;
background: #fff;
z-index: 10;
}
.header {
top: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 15px;
border-bottom: 1px solid #f0f0f0;
}
.header h1 {
margin: 0;
font-size: 18px;
font-weight: 700;
}
.content {
max-width: 980px;
margin: 0 auto;
padding: 16px 16px 140px;
}
.issue-alert {
margin-bottom: 16px;
border-radius: 16px;
}
.item-card,
.coupon-card,
.summary-card {
margin-bottom: 12px;
border-radius: 16px;
}
.issue-card {
border-color: #faad14;
box-shadow: 0 8px 24px rgba(250, 173, 20, 0.12);
}
.item-row {
display: flex;
gap: 12px;
align-items: flex-start;
}
.thumb {
width: 84px;
height: 84px;
border-radius: 12px;
overflow: hidden;
background: #eef3ff;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.item-main {
flex: 1;
}
.title {
font-size: 15px;
font-weight: 700;
cursor: pointer;
}
.price {
margin: 6px 0 10px;
color: #ff4d4f;
font-weight: 700;
}
.selector {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
margin-bottom: 10px;
border: 1px solid transparent;
border-radius: 10px;
background: #f8f9ff;
cursor: pointer;
}
.selector.issue {
border-color: #faad14;
background: #fff7e6;
}
.selector .label {
min-width: 56px;
color: #666;
font-size: 13px;
}
.selector .value {
flex: 1;
color: #1677ff;
font-size: 13px;
}
.duration,
.coupon-tip,
.helper {
color: #666;
font-size: 12px;
}
.actions,
.qty,
.coupon-row,
.summary-row,
.coupon-extra {
display: flex;
align-items: center;
justify-content: space-between;
}
.qty {
gap: 8px;
}
.coupon-extra {
margin-top: 10px;
color: #666;
gap: 12px;
}
.summary-row {
margin-bottom: 10px;
}
.summary-row.total {
margin-bottom: 0;
font-weight: 700;
}
.footer {
bottom: 60px;
padding: 15px;
border-top: 1px solid #f0f0f0;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}
.coupon-options {
display: flex;
flex-direction: column;
gap: 8px;
}
.modal-section + .modal-section {
margin-top: 16px;
}
.section-title {
margin-bottom: 8px;
font-weight: 700;
}
.artist-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.artist-option {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border: 1px solid #d9d9d9;
border-radius: 999px;
background: #fff;
cursor: pointer;
}
.artist-option.active {
border-color: #1677ff;
color: #1677ff;
background: #f0f9ff;
}
.artist-option img {
width: 24px;
height: 24px;
border-radius: 50%;
object-fit: cover;
}
@media (max-width: 767px) {
.content {
max-width: 980px;
margin: 0 auto;
padding: 24px 24px 140px;
padding: 15px 15px 140px;
}
}
</style>