Files
JayuCloud/JC-Salon-Frontend/src/views/CartView.vue
T
xiaowang c957994006
发布 Nacos 配置 / publish (push) Successful in 44s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 1s
统一ArtList与Salon历史命名
2026-10-14 13:04:10 +08:00

3268 lines
94 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="page">
<header class="cart-appbar" aria-label="购物车导航">
<div class="cart-appbar-inner">
<span class="cart-topbar-spacer" aria-hidden="true"></span>
<strong class="cart-brand">{{ checkoutShopName }}</strong>
<span class="cart-topbar-spacer" aria-hidden="true"></span>
</div>
</header>
<main class="content cart-content">
<div v-if="cartLoading && !cartLoaded" class="cart-loading-state" role="status" aria-label="加载购物车">
<a-spin />
</div>
<a-empty v-else-if="cartLoaded && !cartItems.length" class="empty-cart" description="购物车还是空的">
<a-button type="primary" class="empty-action" @click="router.push('/products')">去逛作品</a-button>
</a-empty>
<template v-else>
<section class="cart-section cart-section-items" aria-label="购物车商品">
<div class="cart-section-head">
<h2>我的选择</h2>
<span>{{ selectedCount }} / {{ cartItems.length }} 项已选</span>
</div>
<div class="cart-item-list">
<article
v-for="item in cartItems"
:key="item.id"
:ref="(element: unknown) => setItemRef(item.id, element)"
class="cart-product-card"
:class="{ selected: item.selected, warning: item.selected && hasItemIssue(item) }"
>
<a-checkbox class="product-check" v-model:checked="item.selected" @change="handleToggleSelect" />
<button type="button" class="product-thumb" @click="openProduct(item)">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" @error="handleCartImageError(item)" />
<span v-else>{{ item.productTitle?.[0] || 'Y' }}</span>
</button>
<div class="product-info">
<div class="product-title-row">
<button type="button" class="product-title" @click="openProduct(item)">{{ item.productTitle }}</button>
<a-popconfirm title="确认删除这件作品吗?" ok-text="确认" cancel-text="取消" @confirm="removeItem(item)">
<button type="button" class="product-delete" aria-label="删除作品">
<DeleteOutlined />
</button>
</a-popconfirm>
</div>
<p class="product-meta">
<span>{{ item.tagNames || item.tags || checkoutShopName }}</span>
<span>预计 {{ displayCartDuration(item) }}</span>
</p>
<div class="product-bottom">
<strong class="product-price">参考价 ¥{{ Number(item.price || 0).toFixed(2) }}</strong>
<div class="product-qty" aria-label="调整数量">
<button type="button" :disabled="item.quantity <= 1" @click="changeQuantity(item, -1)">−</button>
<span>{{ item.quantity }}</span>
<button type="button" :disabled="item.quantity >= 99" @click="changeQuantity(item, 1)">+</button>
</div>
</div>
</div>
</article>
</div>
</section>
<section class="cart-section service-section" aria-label="服务详情">
<div class="cart-section-head">
<h2>服务详情</h2>
<span>{{ checkoutIssueCount ? `${checkoutIssueCount} 项待完善` : '预约已就绪' }}</span>
</div>
<div v-if="selectedCount && firstCheckoutIssue" class="issue-callout stitch-issue">
<div>
<strong>{{ firstCheckoutIssue.message }}</strong>
<span>完善服务信息后即可发起询价预约</span>
</div>
<a-button size="small" @click="focusFirstIssue">去完善</a-button>
</div>
<div v-if="selectedItems.length" class="service-card-list">
<article
v-for="item in selectedItems"
:key="`booking-${item.id}`"
class="service-detail-card"
:class="{ ready: !hasItemIssue(item), warning: hasItemIssue(item) }"
>
<button type="button" class="service-detail-main" @click="openBookingModal(item)">
<div class="service-icon">
<img
v-if="item.productImage"
:src="item.productImage"
:alt="item.productTitle"
loading="lazy"
decoding="async"
@error="handleCartImageError(item)"
/>
<span v-else>{{ item.productTitle?.[0] || 'Y' }}</span>
</div>
<div class="service-copy">
<span>{{ item.productTitle }}</span>
<strong>{{ item.artist?.name || '选择美甲师' }}</strong>
<em>{{ item.appointmentTime ? formatAppointmentDisplay(item.appointmentTime) : '选择预约时间' }}</em>
</div>
<span class="service-state">{{ appointmentStatusText(item) }}</span>
<RightOutlined />
</button>
<div v-if="getDisplayArtists(item).length" class="service-artist-strip">
<span class="service-label">选择美甲师</span>
<div class="service-artist-list">
<button
v-for="artist in getDisplayArtists(item)"
:key="artist.id"
type="button"
class="service-artist-option"
:class="{ active: sameId(item.artistId, artist.id) }"
@click="selectInlineArtist(item, artist)"
>
<img v-if="artist.avatar" :src="artist.avatar" :alt="artist.name" loading="lazy" decoding="async" />
<span v-else>{{ artist.name?.[0] || 'Y' }}</span>
<em>{{ artist.name }}</em>
</button>
</div>
</div>
<div class="service-time-panel">
<div class="service-time-head">
<span class="service-label">预约时间</span>
<button type="button" @click="openBookingModal(item)">自定义</button>
</div>
<div class="service-time-grid">
<button
v-for="slot in getDisplayQuickAppointmentSlots(item)"
:key="`${item.id}-${slot.value}`"
type="button"
class="service-time-option"
:class="{ active: item.appointmentTime === slot.value }"
@click="selectInlineTime(item, slot.value)"
>
<span>{{ slot.label }}</span>
<strong>{{ slot.time }}</strong>
</button>
</div>
</div>
</article>
</div>
<a-empty v-else class="service-empty" description="请先选择要结算的作品" />
</section>
<section class="cart-section offer-section" aria-label="优惠券">
<button
type="button"
class="offer-card"
:disabled="!selectedCount"
@click="openCouponModal"
>
<span class="offer-icon">
<TagsOutlined />
</span>
<span class="offer-copy">
<strong>选择优惠券</strong>
<em>{{ selectedCoupon ? formatCouponDisplay(selectedCoupon) : `${availableCoupons.length} 张可用` }}</em>
</span>
<span v-if="discountAmount > 0" class="offer-save">-¥{{ discountAmount.toFixed(2) }}</span>
<RightOutlined />
</button>
<div v-if="checkoutPreview" class="preview-panel stitch-preview">
<div class="preview-line">{{ checkoutPreview.summaryText }}</div>
<div v-if="checkoutPreview.vipTip" class="preview-line vip">{{ checkoutPreview.vipTip }}</div>
</div>
</section>
<section class="cart-section summary-panel stitch-summary" aria-label="询价预约摘要">
<h3>询价预约摘要</h3>
<label class="quote-remark-field">
<span>备注</span>
<a-textarea v-model:value="quoteRemark" :rows="3" :maxlength="300" placeholder="可填写款式偏好、到店需求或其他说明" />
</label>
<div class="summary-row"><span>参考小计</span><strong>¥{{ subtotal.toFixed(2) }}</strong></div>
<div v-if="discountAmount > 0" class="summary-row discount"><span>预估优惠</span><strong>- ¥{{ discountAmount.toFixed(2) }}</strong></div>
<div class="summary-row total"><span>预估应付</span><strong>¥{{ totalAmount.toFixed(2) }}</strong></div>
</section>
</template>
</main>
<footer v-if="cartItems.length" class="footer cart-footer">
<a-button
type="primary"
size="large"
class="checkout-button"
:loading="submittingOrder"
:disabled="submittingOrder || !selectedCount || Boolean(firstCheckoutIssue)"
@click="checkout"
>
<CheckCircleOutlined />
发起询价预约
</a-button>
</footer>
<a-modal
v-model:open="showCouponModal"
title="选择优惠方式"
wrap-class-name="cart-coupon-modal-wrap"
class="cart-coupon-modal"
ok-text="确认"
cancel-text="取消"
:ok-button-props="couponModalOkButtonProps"
:cancel-button-props="couponModalCancelButtonProps"
@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 v-for="coupon in availableCoupons" :key="getCouponKey(coupon)" :value="getCouponKey(coupon)">
<span class="coupon-option-copy">
<strong>{{ formatCouponDisplay(coupon) }}</strong>
<em>{{ coupon.savingText || `本单可省 ¥${Number(coupon.discountAmount || 0).toFixed(2)}` }}</em>
</span>
</a-radio>
</a-radio-group>
<div v-if="unavailableCoupons.length" class="coupon-unavailable">
<div v-for="coupon in unavailableCoupons" :key="getCouponKey(coupon)" class="coupon-unavailable-item">
<span>{{ formatCouponDisplay(coupon) }}</span>
<em>{{ coupon.unavailableReason || '本单暂不可用' }}</em>
</div>
</div>
<div class="coupon-tip">
{{ checkoutPreview?.vipTip || '系统会按本次询价预约的参考金额预估减免最高的一张券,也可以手动选择不使用优惠。' }}
</div>
</a-modal>
<a-modal v-model:open="showBookingModal" :title="bookingTitle" @ok="confirmBooking" @cancel="closeBookingModal">
<div class="modal-section">
<div class="section-title">美甲师</div>
<div v-if="getDraftDisplayArtists().length" class="artist-list">
<button
v-for="artist in getDraftDisplayArtists()"
:key="artist.id"
type="button"
class="artist-option"
:class="{ active: sameId(draftArtistId, artist.id) }"
@click="selectDraftArtist(artist)"
>
<img v-if="artist.avatar" :src="artist.avatar" :alt="artist.name" loading="lazy" decoding="async" />
<span>{{ artist.name }}</span>
<em v-if="artist.roleLabel">{{ artist.roleLabel }}</em>
</button>
</div>
<a-empty v-else description="暂无可预约美甲师" />
</div>
<div class="modal-section">
<div class="section-title">预约时间</div>
<a-date-picker
v-model:value="draftAppointmentTime"
class="time-picker"
popup-class-name="jayucloud-salon-date-picker-panel jayucloud-salon-date-time-panel"
style="width: 100%"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
input-read-only
:disabled-date="disablePastAppointmentDate"
:disabled-time="disablePastAppointmentTime"
:show-time="{ minuteStep: 30, secondStep: 60, hideDisabledOptions: true }"
placeholder="请选择预约时间"
/>
<div class="quick-time-grid">
<button
v-for="slot in quickAppointmentSlots"
:key="slot.value"
type="button"
class="quick-time"
:class="{ active: draftAppointmentTime === slot.value }"
@click="selectDraftAppointmentTime(slot.value)"
>
<span>{{ slot.label }}</span>
<strong>{{ slot.time }}</strong>
</button>
</div>
<div class="helper">{{ bookingHelperText }}</div>
</div>
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* CartView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, inject, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {
CheckCircleOutlined,
DeleteOutlined,
RightOutlined,
TagsOutlined
} from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'
import { cartApi } from '../api/cart'
/**
* Purpose: UserCoupon supports CartView.vue by holding or executing the user coupon page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { orderApi } from '../api/order'
import type { CheckoutCouponPreview, CheckoutIssue as ApiCheckoutIssue, CheckoutPreview } from '../api/order'
import { shopApi } from '../api/shop'
import type { IdType } from '@/utils/id'
import { sameId, toOptionalIdString } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { getBuyNowProductIdFromQuery, isBuyNowCartItem } from '@/utils/buy-now'
import { buildRecoveryActions, getRecoveryMessage } from '@/utils/recovery'
import { extractLegacyFileId } from '@/utils/signed-image-cache'
import { normalizeApiErrorMessage } from '@/api/error'
import { refreshPublicImageUrl, resolvePublicImageUrl, resolvePublicImageUrlsSync } from '@/utils/public-image-assets'
/**
* Purpose: router supports CartView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const router = useRouter()
/** route exposes cart query parameters, including the one-shot buyNow checkout target. */
const route = useRoute()
/**
* Purpose: updateCartCount supports CartView.vue by holding or executing the update cart count page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
/**
* Purpose: NO_COUPON_KEY supports CartView.vue by holding or executing the no coupon key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const NO_COUPON_KEY = 'NONE'
/**
* Purpose: ButtonPropsWithClass supports CartView.vue by holding or executing the button props with class page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
type ButtonPropsWithClass = ButtonProps & { class?: string }
const couponModalOkButtonProps: ButtonPropsWithClass = { class: 'cart-coupon-modal__ok' }
const couponModalCancelButtonProps: ButtonPropsWithClass = { class: 'cart-coupon-modal__cancel' }
/**
* Purpose: ArtistOption supports CartView.vue by holding or executing the artist option page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface ArtistOption {
id: IdType
name: string
avatar?: string
userType?: number
roleLabel?: string
participateProduction?: boolean
}
/**
* Purpose: CartItem supports CartView.vue by holding or executing the cart item page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface CartItem {
id: IdType
productId: IdType
shopId?: IdType
shopName?: string
productTitle: string
productImage: string
originalProductImage?: string
price: number
quantity: number
totalPrice: number
tags: string
tagNames?: string
approximateDuration?: string
serviceDurationMinutes?: number
estimatedTime?: number
businessHours?: string
bookableArtists?: string
availableBookableArtistCount?: number
bookableArtistRestricted?: boolean
availableArtists?: ArtistOption[]
appointmentTime?: string
selected: boolean
artistId?: IdType
artist?: ArtistOption
}
/**
* Purpose: CheckoutIssue supports CartView.vue by holding or executing the checkout issue page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface CheckoutIssue {
key: string
message: string
itemId?: IdType
productId?: IdType
productTitle?: string
}
interface AppointmentSlotOption {
value: string
label: string
time: string
}
interface BookableOptionState {
loading: boolean
artists: ArtistOption[]
slots: AppointmentSlotOption[]
validKeys: Set<string>
}
/**
* Purpose: cartItems supports CartView.vue by holding or executing the cart items page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartItems = ref<CartItem[]>([])
const cartLoading = ref(false)
const cartLoaded = ref(false)
/**
* Purpose: itemRefs supports CartView.vue by holding or executing the item refs page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const itemRefs = ref<Record<string, HTMLElement>>({})
/**
* Purpose: availableCoupons supports CartView.vue by holding or executing the available coupons page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const availableCoupons = ref<CheckoutCouponPreview[]>([])
const unavailableCoupons = ref<CheckoutCouponPreview[]>([])
const checkoutPreview = ref<CheckoutPreview | null>(null)
/**
* Purpose: selectedCoupon supports CartView.vue by holding or executing the selected coupon page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const selectedCoupon = ref<CheckoutCouponPreview | null>(null)
const quoteRemark = ref('')
/** couponSelectionKey is a reactive state variable used by the template and event handlers. */
const couponSelectionKey = ref(NO_COUPON_KEY)
/** couponSelectionTouched is a reactive state variable used by the template and event handlers. */
const couponSelectionTouched = ref(false)
/** showCouponModal is a reactive state variable used by the template and event handlers. */
const showCouponModal = ref(false)
/** showBookingModal is a reactive state variable used by the template and event handlers. */
const showBookingModal = ref(false)
/**
* Purpose: currentItem supports CartView.vue by holding or executing the current item page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentItem = ref<CartItem | null>(null)
/**
* Purpose: availableArtists supports CartView.vue by holding or executing the available artists page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const availableArtists = ref<ArtistOption[]>([])
/**
* Purpose: draftArtistId supports CartView.vue by holding or executing the draft artist id page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const draftArtistId = ref<IdType>()
/** draftAppointmentTime is a reactive state variable used by the template and event handlers. */
const draftAppointmentTime = ref('')
/** currentShopHours is a reactive state variable used by the template and event handlers. */
const currentShopHours = ref('')
const shopHoursById = ref<Record<string, string>>({})
/** submittingOrder is a reactive state variable used by the template and event handlers. */
const submittingOrder = ref(false)
const bookableOptionsByItemId = ref<Record<string, BookableOptionState>>({})
/** buyNowProductId limits checkout selection to the product that opened cart from "立即预约". */
const buyNowProductId = computed(() => getBuyNowProductIdFromQuery(route.query))
/** isBuyNowMode switches cart copy into a focused order-confirmation experience. */
const isBuyNowMode = computed(() => Boolean(buyNowProductId.value))
/** selectedItems is a reactive state variable used by the template and event handlers. */
const selectedItems = computed(() => cartItems.value.filter(item => item.selected))
const checkoutShopName = computed(() => {
const itemWithShopName = selectedItems.value.find(item => item.shopName) || cartItems.value.find(item => item.shopName)
if (itemWithShopName?.shopName) {
return itemWithShopName.shopName
}
if (typeof window !== 'undefined') {
try {
const raw = localStorage.getItem('userInfo')
const storedUser = raw ? JSON.parse(raw) as { shopName?: string; shopNames?: string[] } : null
const cachedShopName = storedUser?.shopName || storedUser?.shopNames?.find(Boolean)
if (cachedShopName) {
return cachedShopName
}
} catch {
// Ignore malformed cached user data and fall back to the neutral shop label.
}
}
return '当前门店'
})
/** selectedCount is a reactive state variable used by the template and event handlers. */
const selectedCount = computed(() => selectedItems.value.length)
/** subtotal is a reactive state variable used by the template and event handlers. */
const localSubtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + Number(item.price || 0) * item.quantity, 0))
const subtotal = computed(() => Number(checkoutPreview.value?.subtotalAmount ?? localSubtotal.value))
/** discountAmount is a reactive state variable used by the template and event handlers. */
const discountAmount = computed(() => Number(checkoutPreview.value?.savedAmount ?? calculateCouponDiscount(selectedCoupon.value, subtotal.value)))
/** totalAmount is a reactive state variable used by the template and event handlers. */
const totalAmount = computed(() => Number(checkoutPreview.value?.payableAmount ?? Math.max(0, subtotal.value - discountAmount.value)))
/** bookingTitle is a reactive state variable used by the template and event handlers. */
const bookingTitle = computed(() => currentItem.value ? `为 ${currentItem.value.productTitle} 选择预约信息` : '选择预约信息')
/** bookingHelperText is a reactive state variable used by the template and event handlers. */
const bookingHelperText = computed(() => {
const texts: string[] = []
if (currentShopHours.value) texts.push(`门店营业时间:${currentShopHours.value}`)
if (currentItem.value) texts.push(`预计时长:${displayCartDuration(currentItem.value)}`)
return texts.join(' · ') || '请选择至少晚于当前 5 分钟的预约时间'
})
/** quickAppointmentSlots is a reactive state variable used by the template and event handlers. */
const quickAppointmentSlots = computed(() => {
if (currentItem.value) {
return getDisplayQuickAppointmentSlotsForArtist(currentItem.value, draftArtistId.value)
}
return buildQuickAppointmentSlots()
})
const getItemKey = (item: CartItem) => toOptionalIdString(item.id) || toOptionalIdString(item.productId) || ''
const getBookableKey = (artistId: IdType, appointmentTime: string) => {
return `${toOptionalIdString(artistId) || ''}|${appointmentTime}`
}
const normalizeArtists = (item: CartItem): ArtistOption[] => {
return Array.isArray(item.availableArtists)
? (item.availableArtists || [])
.filter(artist => artist && artist.id !== undefined && artist.id !== null)
.map(artist => ({
id: artist.id,
name: artist.name,
avatar: artist.avatar,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
}))
: []
}
const getBookableOptionState = (item: CartItem): BookableOptionState | null => {
const itemKey = getItemKey(item)
return itemKey ? bookableOptionsByItemId.value[itemKey] || null : null
}
const getDisplayArtists = (item: CartItem) => {
const state = getBookableOptionState(item)
return state ? state.artists : normalizeArtists(item)
}
const getDisplayQuickAppointmentSlots = (item: CartItem) => {
const state = getBookableOptionState(item)
return state ? state.slots : getQuickAppointmentSlots(item)
}
const getDisplayQuickAppointmentSlotsForArtist = (item: CartItem, artistId?: IdType) => {
const state = getBookableOptionState(item)
if (!state || !artistId) {
return getDisplayQuickAppointmentSlots(item)
}
return state.slots.filter(slot => state.validKeys.has(getBookableKey(artistId, slot.value)))
}
const getDraftDisplayArtists = () => {
if (!currentItem.value || !draftAppointmentTime.value) {
return availableArtists.value
}
const state = getBookableOptionState(currentItem.value)
if (!state) {
return availableArtists.value
}
return availableArtists.value.filter(artist =>
state.validKeys.has(getBookableKey(artist.id, draftAppointmentTime.value))
)
}
const hasBookableCombination = (item: CartItem, artistId?: IdType, appointmentTime?: string) => {
if (!artistId || !appointmentTime) {
return false
}
const state = getBookableOptionState(item)
if (!state) {
return true
}
return state.validKeys.has(getBookableKey(artistId, appointmentTime))
}
const buildQuickAppointmentSlots = (item?: CartItem) => {
const now = getMinAppointmentDate()
const today = new Date(now)
const nextHour = new Date(now)
nextHour.setMinutes(now.getMinutes() > 30 ? 0 : 30, 0, 0)
if (nextHour.getTime() < now.getTime()) {
nextHour.setHours(nextHour.getHours() + 1)
}
const tomorrowMorning = buildAppointmentDate(1, 10, 0)
const tomorrowAfternoon = buildAppointmentDate(1, 14, 0)
const afterTomorrowAfternoon = buildAppointmentDate(2, 15, 0)
const weekendMorning = nextWeekendMorning(today)
return [nextHour, tomorrowMorning, tomorrowAfternoon, afterTomorrowAfternoon, weekendMorning]
.filter((date, index, list) =>
date.getTime() >= now.getTime()
&& list.findIndex(current => current.getTime() === date.getTime()) === index
&& isAppointmentWithinBusinessHours(date, item)
)
.slice(0, 5)
.map(date => ({
value: formatAppointmentValue(date),
label: quickDateLabel(date),
time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}))
}
const getQuickAppointmentSlots = (item: CartItem) => buildQuickAppointmentSlots(item)
const isCheckoutPreviewBookable = (preview: CheckoutPreview) => {
return preview.bookingAvailable !== false && !(preview.bookingIssues || []).length
}
const checkBookableCombination = async (item: CartItem, artist: ArtistOption, slot: AppointmentSlotOption) => {
try {
const preview = await orderApi.checkoutPreview({
items: [{
productId: item.productId,
quantity: item.quantity,
artistId: artist.id,
appointmentTime: slot.value
}]
})
return isCheckoutPreviewBookable(preview)
} catch {
return false
}
}
const refreshBookableOptions = async (item: CartItem) => {
const itemKey = getItemKey(item)
if (!itemKey) {
return
}
const artists = normalizeArtists(item)
const slots = getQuickAppointmentSlots(item)
bookableOptionsByItemId.value = {
...bookableOptionsByItemId.value,
[itemKey]: { loading: true, artists: [], slots: [], validKeys: new Set<string>() }
}
const checks = await Promise.all(artists.flatMap(artist =>
slots.map(async slot => ({
artist,
slot,
valid: await checkBookableCombination(item, artist, slot)
}))
))
const validKeys = new Set(
checks
.filter(check => check.valid)
.map(check => getBookableKey(check.artist.id, check.slot.value))
)
const validArtists = artists.filter(artist =>
slots.some(slot => validKeys.has(getBookableKey(artist.id, slot.value)))
)
const validSlots = slots.filter(slot =>
artists.some(artist => validKeys.has(getBookableKey(artist.id, slot.value)))
)
bookableOptionsByItemId.value = {
...bookableOptionsByItemId.value,
[itemKey]: { loading: false, artists: validArtists, slots: validSlots, validKeys }
}
if (item.artistId && !validArtists.some(artist => sameId(artist.id, item.artistId))) {
item.artistId = undefined
item.artist = undefined
}
if (item.appointmentTime && !validSlots.some(slot => slot.value === item.appointmentTime)) {
item.appointmentTime = ''
}
}
const refreshSelectedBookableOptions = async () => {
await Promise.all(selectedItems.value.map(item => refreshBookableOptions(item)))
}
const findFirstSlotForArtist = (item: CartItem, artistId: IdType) => {
const state = getBookableOptionState(item)
return state?.slots.find(slot => state.validKeys.has(getBookableKey(artistId, slot.value)))
}
const findFirstArtistForSlot = (item: CartItem, appointmentTime: string) => {
const state = getBookableOptionState(item)
return state?.artists.find(artist => state.validKeys.has(getBookableKey(artist.id, appointmentTime)))
}
const findInvalidBookableCombination = () => {
return selectedItems.value.find(item =>
item.artistId
&& item.appointmentTime
&& !hasBookableCombination(item, item.artistId, item.appointmentTime)
)
}
/** getMinAppointmentDate is a local helper used by this page script. */
const getMinAppointmentDate = () => {
const date = new Date()
date.setSeconds(0, 0)
date.setMinutes(date.getMinutes() + 5)
return date
}
/** getDayBoundary is a local helper used by this page script. */
const getDayBoundary = (date: Date) => {
const boundary = new Date(date)
boundary.setHours(0, 0, 0, 0)
return boundary.getTime()
}
/** buildAppointmentDate is a local helper used by this page script. */
const buildAppointmentDate = (daysFromToday: number, hour: number, minute: number) => {
const date = new Date()
date.setDate(date.getDate() + daysFromToday)
date.setHours(hour, minute, 0, 0)
return date
}
/** nextWeekendMorning is a local helper used by this page script. */
const nextWeekendMorning = (fromDate: Date) => {
const date = new Date(fromDate)
const day = date.getDay()
const offset = day === 0 ? 6 : 6 - day
date.setDate(date.getDate() + Math.max(1, offset))
date.setHours(10, 0, 0, 0)
return date
}
/** formatAppointmentValue is a local helper used by this page script. */
const formatAppointmentValue = (date: Date) => {
/** pad is a local helper used by this page script. */
const pad = (value: number) => String(value).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:00`
}
const parseDurationMinutes = (value?: string | number | null): number | null => {
if (value == null || value === '') return null
if (typeof value === 'number') return Number.isFinite(value) && value > 0 ? value : null
const text = String(value).trim()
const hourMatch = text.match(/(\d+(?:\.\d+)?)\s*(?:小时|h|hour)/i)
const minuteMatch = text.match(/(\d+(?:\.\d+)?)\s*(?:分钟|min|minute)/i)
if (hourMatch || minuteMatch) {
const hours = hourMatch ? Number(hourMatch[1]) : 0
const minutes = minuteMatch ? Number(minuteMatch[1]) : 0
const total = Math.round(hours * 60 + minutes)
return total > 0 ? total : null
}
const numberMatch = text.match(/\d+(?:\.\d+)?/)
if (!numberMatch) return null
const total = Math.round(Number(numberMatch[0]))
return total > 0 ? total : null
}
const getCartDurationMinutes = (item: CartItem): number | null => {
return parseDurationMinutes(item.approximateDuration)
?? parseDurationMinutes(item.serviceDurationMinutes)
?? parseDurationMinutes(item.estimatedTime)
}
const displayCartDuration = (item: CartItem) => {
const duration = item.approximateDuration?.trim()
if (duration) return duration
const minutes = getCartDurationMinutes(item)
return minutes ? `${minutes}分钟` : '时长待定'
}
const parseBusinessHoursRange = (value?: string | null): { open: number; close: number } | null => {
const text = String(value || '').replace(/[:]/g, ':').replace(/[-—–]/g, '-')
const match = text.match(/(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})/)
if (!match) return null
const open = Number(match[1]) * 60 + Number(match[2])
const close = Number(match[3]) * 60 + Number(match[4])
if (!Number.isFinite(open) || !Number.isFinite(close) || close <= open) return null
return { open, close }
}
const getItemBusinessHours = (item?: CartItem) => {
if (!item) return ''
const shopKey = toOptionalIdString(item.shopId)
return item.businessHours || (shopKey ? shopHoursById.value[shopKey] : '') || ''
}
const isAppointmentWithinBusinessHours = (date: Date, item?: CartItem) => {
const range = parseBusinessHoursRange(getItemBusinessHours(item))
if (!range) return true
const start = date.getHours() * 60 + date.getMinutes()
const duration = item ? getCartDurationMinutes(item) || 0 : 0
return start >= range.open && start + duration <= range.close
}
/** quickDateLabel is a local helper used by this page script. */
const quickDateLabel = (date: Date) => {
const today = new Date()
const tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)
if (date.toDateString() === today.toDateString()) return '今天'
if (date.toDateString() === tomorrow.toDateString()) return '明天'
return `${date.getMonth() + 1}月${date.getDate()}日`
}
/** getCouponKey is a local helper used by this page script. */
const getCouponKey = (coupon: CheckoutCouponPreview) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
/** setItemRef is a local helper used by this page script. */
const setItemRef = (itemId: IdType, element: unknown) => {
const refKey = toOptionalIdString(itemId)
if (!refKey) {
return
}
if (element && (element as any).$el) {
itemRefs.value[refKey] = (element as any).$el as HTMLElement
return
}
if (element instanceof HTMLElement) {
itemRefs.value[refKey] = element
return
}
delete itemRefs.value[refKey]
}
/** formatCouponDisplay is a local helper used by this page script. */
const formatCouponDisplay = (coupon: CheckoutCouponPreview) => {
if (coupon.displayText) {
return coupon.displayText
}
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
const benefit = coupon.couponType === 1
? `${coupon.discountValue} 折`
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
return `${badge} ${coupon.couponName} ${benefit}`
}
/** calculateCouponDiscount is a local helper used by this page script. */
const calculateCouponDiscount = (coupon: CheckoutCouponPreview | null, amount: number) => {
if (!coupon || amount <= 0) {
return 0
}
if (coupon.discountAmount !== undefined && coupon.discountAmount !== null) {
return Number(coupon.discountAmount || 0)
}
if (coupon.couponType === 1) {
const discountValue = Number(coupon.discountValue || 0)
return discountValue ? amount - amount * discountValue / 10 : 0
}
if (coupon.couponType === 2) {
return Number(coupon.reduceAmount || 0)
}
return 0
}
/** findBestCoupon is a local helper used by this page script. */
const findBestCoupon = (coupons: CheckoutCouponPreview[]) => {
return coupons
.sort((left, right) => calculateCouponDiscount(right, subtotal.value) - calculateCouponDiscount(left, subtotal.value))[0] || null
}
/** formatAppointmentDisplay is a local helper used by this page script. */
const formatAppointmentDisplay = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '未选择预约时间'
/** isPastAppointment is a local helper used by this page script. */
const isPastAppointment = (value?: string) => !!value && new Date(value.replace(' ', 'T')).getTime() < getMinAppointmentDate().getTime()
/** hasItemIssue is a local helper used by this page script. */
const hasItemIssue = (item: CartItem) => !item.artistId || !item.appointmentTime || isPastAppointment(item.appointmentTime)
/** appointmentStatusText is a local helper used by this page script. */
const appointmentStatusText = (item: CartItem) => {
if (!item.selected) {
return '未选中'
}
if (!item.artistId) {
return '待选美甲师'
}
if (!item.appointmentTime) {
return '待选时间'
}
if (isPastAppointment(item.appointmentTime)) {
return '时间已过期'
}
return '已完成'
}
const mapApiCheckoutIssue = (issue: ApiCheckoutIssue): CheckoutIssue | null => {
if (!issue?.message) return null
const matchedItem = selectedItems.value.find(item => issue.itemId != null && sameId(item.id, issue.itemId))
|| selectedItems.value.find(item => issue.productId != null && sameId(item.productId, issue.productId))
return {
key: `server-${issue.code || issue.message}`,
message: normalizeApiErrorMessage(issue.message),
itemId: matchedItem?.id || issue.itemId,
productId: issue.productId,
productTitle: issue.productTitle || matchedItem?.productTitle
}
}
// 购物车结算口径要求单店铺、单美甲师、完整预约信息,避免后端拆单和排班出现歧义。
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 })
}
const selectedShopIds = new Set(
items
.map(item => toOptionalIdString(item.shopId))
.filter((shopId): shopId is string => Boolean(shopId))
)
if (selectedShopIds.size > 1) {
issues.push({ key: 'shop', message: '跨店铺项目请分开结算', itemId: items[0]?.id })
}
const selectedArtistIds = new Set(
items
.map(item => toOptionalIdString(item.artistId))
.filter((artistId): artistId is string => Boolean(artistId))
)
if (selectedArtistIds.size > 1) {
issues.push({ key: 'artist-mix', message: '不同美甲师的项目请分开结算', itemId: items[0]?.id })
}
const apiIssues = checkoutPreview.value?.bookingIssues || []
apiIssues
.map(mapApiCheckoutIssue)
.filter((issue): issue is CheckoutIssue => Boolean(issue))
.forEach(issue => issues.push(issue))
return issues
})
/** checkoutIssueCount is a reactive state variable used by the template and event handlers. */
const checkoutIssueCount = computed(() => checkoutIssues.value.length)
/** firstCheckoutIssue is a reactive state variable used by the template and event handlers. */
const firstCheckoutIssue = computed(() => checkoutIssues.value[0])
/** scrollToIssue is a local helper used by this page script. */
const scrollToIssue = (issue?: CheckoutIssue) => {
const itemId = toOptionalIdString(issue?.itemId)
if (!itemId) {
return
}
const target = itemRefs.value[itemId]
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
}
/** focusFirstIssue is a local helper used by this page script. */
const focusFirstIssue = () => {
scrollToIssue(checkoutIssues.value[0])
}
const isDisplayableImageSource = (value?: string | null) => {
const source = String(value || '').trim()
return source.startsWith('http://')
|| source.startsWith('https://')
|| source.startsWith('/')
|| source.startsWith('data:image/')
|| source.startsWith('blob:')
}
const getInitialCartImage = (rawImage?: string, previousImage?: string) => {
const imageId = extractLegacyFileId(rawImage)
const cachedUrl = imageId ? resolvePublicImageUrlsSync({ imageFileIds: imageId }, '')[0] : ''
if (cachedUrl) return cachedUrl
if (previousImage) return previousImage
if (imageId) return ''
return isDisplayableImageSource(rawImage) ? String(rawImage) : ''
}
/** loadCartItems is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadCartItems = async () => {
cartLoading.value = true
try {
const response = await cartApi.getCartList() as unknown as any[]
const previousItems = cartItems.value
cartItems.value = (response || []).map(item => {
const previous = previousItems.find(current => sameId(current.id, item.id))
|| previousItems.find(current => sameId(current.productId, item.productId))
const originalProductImage = item.productImage || previous?.originalProductImage || ''
const shopKey = toOptionalIdString(item.shopId)
return {
...item,
selected: isBuyNowMode.value ? isBuyNowCartItem(item.productId, buyNowProductId.value) : previous?.selected ?? true,
originalProductImage,
productImage: getInitialCartImage(originalProductImage, previous?.productImage),
appointmentTime: item.appointmentTime,
businessHours: item.businessHours || previous?.businessHours || (shopKey ? shopHoursById.value[shopKey] : '')
}
})
couponSelectionTouched.value = false
couponSelectionKey.value = NO_COUPON_KEY
selectedCoupon.value = null
await Promise.all([loadProductImages(), loadCartItemShopHours()])
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
} finally {
cartLoading.value = false
cartLoaded.value = true
}
}
/** loadProductImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadProductImages = async () => {
for (const item of cartItems.value) {
if (!item.originalProductImage) {
continue
}
const imageId = extractLegacyFileId(item.originalProductImage)
if (!imageId) {
if (!item.productImage && isDisplayableImageSource(item.originalProductImage)) {
item.productImage = item.originalProductImage
}
continue
}
const cachedUrl = resolvePublicImageUrlsSync({ imageFileIds: imageId }, '')[0]
if (cachedUrl) item.productImage = cachedUrl
const signedUrl = await resolvePublicImageUrl({ imageFileIds: imageId }, item.productImage || '')
if (signedUrl) item.productImage = signedUrl
}
}
const handleCartImageError = async (item: CartItem) => {
const imageId = extractLegacyFileId(item.originalProductImage)
item.productImage = imageId ? await refreshPublicImageUrl(imageId, '') : ''
}
const loadCartItemShopHours = async () => {
const shopIds = Array.from(new Set(
cartItems.value
.map(item => toOptionalIdString(item.shopId))
.filter((shopId): shopId is string => Boolean(shopId))
.filter(shopId => !shopHoursById.value[shopId])
))
await Promise.all(shopIds.map(async shopId => {
try {
const shop = await shopApi.getShopById(shopId) as any
const businessHours = String(shop?.businessHours || '')
if (businessHours) {
shopHoursById.value = { ...shopHoursById.value, [shopId]: businessHours }
}
} catch {
shopHoursById.value = { ...shopHoursById.value, [shopId]: '' }
}
}))
cartItems.value.forEach(item => {
const shopKey = toOptionalIdString(item.shopId)
if (shopKey && !item.businessHours && shopHoursById.value[shopKey]) {
item.businessHours = shopHoursById.value[shopKey]
}
})
}
/** loadAvailableCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadAvailableCoupons = async () => {
const currentSelectedKey = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : couponSelectionKey.value
if (!selectedItems.value.length || localSubtotal.value <= 0) {
checkoutPreview.value = null
availableCoupons.value = []
unavailableCoupons.value = []
selectedCoupon.value = null
couponSelectionKey.value = NO_COUPON_KEY
return
}
try {
const preview = await orderApi.checkoutPreview({
couponId: selectedCoupon.value?.id,
couponSourceType: selectedCoupon.value?.sourceType || (couponSelectionTouched.value && currentSelectedKey === NO_COUPON_KEY ? NO_COUPON_KEY : undefined),
remark: quoteRemark.value.trim() || undefined,
items: selectedItems.value.map(item => ({
productId: item.productId,
quantity: item.quantity,
artistId: item.artistId,
appointmentTime: item.appointmentTime
}))
})
checkoutPreview.value = preview
availableCoupons.value = Array.isArray(preview.availableCoupons) ? preview.availableCoupons : []
unavailableCoupons.value = Array.isArray(preview.unavailableCoupons) ? preview.unavailableCoupons : []
const matchedCoupon = availableCoupons.value.find(coupon => getCouponKey(coupon) === currentSelectedKey) || null
if (matchedCoupon) {
selectedCoupon.value = matchedCoupon
couponSelectionKey.value = getCouponKey(matchedCoupon)
return
}
if (couponSelectionTouched.value && currentSelectedKey === NO_COUPON_KEY) {
selectedCoupon.value = null
couponSelectionKey.value = NO_COUPON_KEY
return
}
couponSelectionTouched.value = false
const defaultCoupon = findBestCoupon(availableCoupons.value)
if (defaultCoupon) {
selectedCoupon.value = defaultCoupon
couponSelectionKey.value = getCouponKey(defaultCoupon)
} else {
selectedCoupon.value = null
couponSelectionKey.value = NO_COUPON_KEY
}
} catch (error) {
console.error('获取可用优惠失败:', error)
checkoutPreview.value = null
availableCoupons.value = []
unavailableCoupons.value = []
selectedCoupon.value = null
couponSelectionKey.value = NO_COUPON_KEY
}
}
/** handleToggleSelect is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleToggleSelect = async () => {
await runWithGlobalLoading(async () => {
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
})
}
/** changeQuantity is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const changeQuantity = async (item: CartItem, delta: number) => {
const next = item.quantity + delta
if (next < 1 || next > 99) return
item.quantity = next
try {
await runWithGlobalLoading(async () => {
await cartApi.updateCartQuantity({ productId: item.productId, quantity: next })
await refreshBookableOptions(item)
await loadAvailableCoupons()
})
await updateCartCount()
} catch (error: any) {
item.quantity -= delta
message.error(error?.message || '更新数量失败')
}
}
/** removeItem is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const removeItem = async (item: CartItem) => {
try {
await runWithGlobalLoading(async () => {
await cartApi.removeFromCart(item.productId)
cartItems.value = cartItems.value.filter(current => !sameId(current.id, item.id))
await loadAvailableCoupons()
})
await updateCartCount()
message.success('作品已删除')
} catch (error: any) {
message.error(error?.message || '删除作品失败')
}
}
/** openProduct is a local helper used by this page script. */
const openProduct = (item: CartItem) => {
router.push('/product/' + item.productId)
}
/** selectInlineArtist updates a cart item's artist from the page-level service detail controls. */
const selectInlineArtist = async (item: CartItem, artist: ArtistOption) => {
item.artistId = artist.id
item.artist = artist
if (!hasBookableCombination(item, artist.id, item.appointmentTime)) {
item.appointmentTime = findFirstSlotForArtist(item, artist.id)?.value || ''
}
await runWithGlobalLoading(() => loadAvailableCoupons())
}
/** selectInlineTime updates a cart item's appointment slot from the page-level service detail controls. */
const selectInlineTime = async (item: CartItem, appointmentTime: string) => {
item.appointmentTime = appointmentTime
if (!hasBookableCombination(item, item.artistId, appointmentTime)) {
const artist = findFirstArtistForSlot(item, appointmentTime)
item.artistId = artist?.id
item.artist = artist
}
await runWithGlobalLoading(() => loadAvailableCoupons())
}
/** openBookingModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const openBookingModal = async (item: CartItem) => {
currentItem.value = item
draftArtistId.value = item.artistId
draftAppointmentTime.value = item.appointmentTime || ''
showBookingModal.value = true
await runWithGlobalLoading(async () => {
await Promise.all([refreshBookableOptions(item), loadShopHours(item.shopId)])
await loadArtists(item)
})
}
/** loadArtists is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadArtists = async (item: CartItem) => {
availableArtists.value = getDisplayArtists(item)
if (draftArtistId.value && !availableArtists.value.some(artist => sameId(artist.id, draftArtistId.value))) {
draftArtistId.value = undefined
}
if (draftAppointmentTime.value && !hasBookableCombination(item, draftArtistId.value, draftAppointmentTime.value)) {
draftAppointmentTime.value = ''
}
}
/** loadShopHours is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadShopHours = async (shopId?: IdType) => {
currentShopHours.value = ''
if (!shopId) return
const shopKey = toOptionalIdString(shopId)
if (shopKey && shopHoursById.value[shopKey]) {
currentShopHours.value = shopHoursById.value[shopKey]
return
}
try {
const shop = await shopApi.getShopById(shopId) as any
currentShopHours.value = shop?.businessHours || ''
if (shopKey) {
shopHoursById.value = { ...shopHoursById.value, [shopKey]: currentShopHours.value }
}
} catch {
currentShopHours.value = ''
}
}
/** disablePastAppointmentDate is a local helper used by this page script. */
const disablePastAppointmentDate = (current: any) => {
if (!current) return false
return current.valueOf() < getDayBoundary(new Date())
}
/** disablePastAppointmentTime is a local helper used by this page script. */
const disablePastAppointmentTime = (current: any) => {
if (!current || typeof current.format !== 'function') {
return {}
}
const minDate = getMinAppointmentDate()
const minDateText = [
minDate.getFullYear(),
String(minDate.getMonth() + 1).padStart(2, '0'),
String(minDate.getDate()).padStart(2, '0')
].join('-')
if (current.format('YYYY-MM-DD') !== minDateText) {
return {}
}
const minHour = minDate.getHours()
const minMinute = minDate.getMinutes()
return {
disabledHours: () => Array.from({ length: minHour }, (_, index) => index),
disabledMinutes: (selectedHour: number) => selectedHour === minHour
? Array.from({ length: minMinute }, (_, index) => index)
: [],
disabledSeconds: () => []
}
}
const selectDraftArtist = (artist: ArtistOption) => {
if (!currentItem.value) {
return
}
draftArtistId.value = artist.id
if (!hasBookableCombination(currentItem.value, artist.id, draftAppointmentTime.value)) {
draftAppointmentTime.value = findFirstSlotForArtist(currentItem.value, artist.id)?.value || ''
}
}
const selectDraftAppointmentTime = (appointmentTime: string) => {
if (!currentItem.value) {
return
}
draftAppointmentTime.value = appointmentTime
if (!hasBookableCombination(currentItem.value, draftArtistId.value, appointmentTime)) {
draftArtistId.value = findFirstArtistForSlot(currentItem.value, appointmentTime)?.id
}
}
/** closeBookingModal is a local helper used by this page script. */
const closeBookingModal = () => {
showBookingModal.value = false
currentItem.value = null
draftArtistId.value = undefined
draftAppointmentTime.value = ''
availableArtists.value = []
currentShopHours.value = ''
}
/** confirmBooking is a local helper used by this page script. */
const confirmBooking = async () => {
if (!currentItem.value) return closeBookingModal()
if (!draftArtistId.value) return message.warning('请先选择美甲师')
if (!draftAppointmentTime.value) return message.warning('请选择预约时间')
if (isPastAppointment(draftAppointmentTime.value)) return message.warning('预约时间至少需要晚于当前 5 分钟')
if (!hasBookableCombination(currentItem.value, draftArtistId.value, draftAppointmentTime.value)) {
return message.warning('请选择可预约的美甲师和时间')
}
currentItem.value.artistId = draftArtistId.value
currentItem.value.artist = availableArtists.value.find(artist => sameId(artist.id, draftArtistId.value))
currentItem.value.appointmentTime = draftAppointmentTime.value
closeBookingModal()
await loadAvailableCoupons()
}
/** openCouponModal is a local helper used by this page script. */
const openCouponModal = () => {
couponSelectionKey.value = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : NO_COUPON_KEY
showCouponModal.value = true
}
/** applyCouponSelection is a local helper used by this page script. */
const applyCouponSelection = async () => {
couponSelectionTouched.value = true
if (couponSelectionKey.value === NO_COUPON_KEY) {
selectedCoupon.value = null
} else {
selectedCoupon.value = availableCoupons.value.find(coupon => getCouponKey(coupon) === couponSelectionKey.value) || null
}
showCouponModal.value = false
await runWithGlobalLoading(() => loadAvailableCoupons())
}
let checkoutRecoveryModal: { destroy: () => void } | null = null
const openCheckoutRecovery = (error: unknown) => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
const recoveryMessage = error instanceof Error
? normalizeApiErrorMessage(error.message)
: normalizeApiErrorMessage(getRecoveryMessage(error, '询价预约发起失败'))
const actions = buildRecoveryActions([
{ key: 'retry', text: '重试发起询价' },
{ key: 'orders', text: '查看订单' }
])
const retryAction = actions[0]
const ordersAction = actions[1]
checkoutRecoveryModal = Modal.confirm({
title: '发起询价预约失败',
content: `${recoveryMessage}。如担心重复提交,请先查看订单;仍失败时请联系管理员。`,
closable: true,
okText: retryAction?.text || '重试发起询价',
cancelText: ordersAction?.text || '查看订单',
onOk: () => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
void checkout()
},
onCancel: () => {
checkoutRecoveryModal?.destroy()
checkoutRecoveryModal = null
void router.push(ordersAction?.route || '/orders')
}
})
}
const buildClientRequestId = () => {
if (typeof globalThis.crypto?.randomUUID === 'function') {
return `web-order-${Date.now()}-${globalThis.crypto.randomUUID()}`
}
return `web-order-${Date.now()}-${Math.random().toString(36).slice(2, 12)}`
}
/** checkout is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const checkout = async () => {
if (submittingOrder.value) {
return
}
const items = selectedItems.value
if (!items.length) {
return message.warning('请先选择要结算的作品')
}
await runWithGlobalLoading(async () => {
await refreshSelectedBookableOptions()
await loadAvailableCoupons()
})
const invalidCombination = findInvalidBookableCombination()
if (invalidCombination) {
message.warning(`"${invalidCombination.productTitle}" 当前美甲师和预约时间不可预约,请重新选择`)
scrollToIssue({ key: 'bookable-combination', message: '请选择可预约的美甲师和时间', itemId: invalidCombination.id })
return
}
const firstIssue = checkoutIssues.value[0]
if (firstIssue) {
message.warning(firstIssue.message)
scrollToIssue(firstIssue)
return
}
submittingOrder.value = true
try {
await runWithGlobalLoading(() => orderApi.createInquiryAppointment({
couponId: selectedCoupon.value?.id,
couponSourceType: selectedCoupon.value?.sourceType || (couponSelectionTouched.value && !selectedCoupon.value ? NO_COUPON_KEY : undefined),
remark: quoteRemark.value.trim() || undefined,
clientRequestId: buildClientRequestId(),
items: items.map(item => ({
productId: item.productId,
quantity: item.quantity,
artistId: item.artistId,
appointmentTime: item.appointmentTime
}))
}))
message.success('询价预约已发起,等待门店确认价格')
let followupWarningShown = false
try {
await runWithGlobalLoading(() => loadCartItems())
await updateCartCount()
} catch (followupError) {
followupWarningShown = true
console.error('询价预约发起后刷新购物车失败:', followupError)
message.warning('询价预约已发起,但购物车刷新失败,请前往订单页查看')
}
try {
await router.push('/orders')
} catch (navigationError) {
console.error('询价预约发起后跳转订单页失败:', navigationError)
if (!followupWarningShown) {
message.warning('询价预约已发起,但跳转订单页失败,请手动前往订单页查看')
}
}
} catch (error: any) {
const checkoutErrorMessage = normalizeApiErrorMessage(error instanceof Error ? error.message : getRecoveryMessage(error, '询价预约发起失败'))
if (checkoutErrorMessage.includes('不可预约')) {
console.warn('询价预约被业务规则拦截:', checkoutErrorMessage)
} else {
console.error('创建订单失败:', error)
}
openCheckoutRecovery(error)
} finally {
submittingOrder.value = false
}
}
onMounted(async () => {
try {
await loadCartItems()
} catch (error: any) {
message.error(error?.message || '获取购物车数据失败')
}
})
</script>
<style scoped>
.page {
--cart-radius-lg: 24px;
--cart-radius-md: 18px;
--cart-bottom-offset: 60px;
--cart-shell-width: var(--frontend-page-max-width);
min-height: 100vh;
color: var(--text-primary);
font-family: "Plus Jakarta Sans", "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
background:
radial-gradient(circle at 14% -8%, color-mix(in srgb, var(--theme-primary) 28%, transparent), transparent 34%),
linear-gradient(180deg, color-mix(in srgb, var(--theme-page-bg) 88%, var(--theme-card-bg)), var(--theme-page-bg));
}
.content {
width: min(100%, var(--cart-shell-width));
margin: 0 auto;
padding: 0 16px calc(168px + env(safe-area-inset-bottom));
}
.cart-header {
position: sticky;
top: 0;
z-index: 12;
display: grid;
grid-template-columns: 40px minmax(0, 1fr) 40px;
align-items: center;
gap: 10px;
height: 56px;
margin: 0 -16px 14px;
padding: 8px 16px;
border-bottom: 1px solid color-mix(in srgb, var(--theme-border) 80%, transparent);
background: color-mix(in srgb, var(--theme-page-bg) 88%, transparent);
backdrop-filter: blur(18px);
}
.header-spacer {
width: 36px;
height: 36px;
justify-self: center;
}
.header-title {
min-width: 0;
text-align: center;
}
.header-title strong {
display: block;
}
.header-title strong {
overflow: hidden;
color: var(--text-primary);
font-size: 16px;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.empty-cart {
margin-top: 64px;
padding: 44px 18px;
border: 1px solid var(--theme-border);
border-radius: var(--cart-radius-lg);
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
box-shadow: 0 18px 44px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
}
.cart-loading-state {
display: grid;
min-height: 56vh;
place-items: center;
}
.empty-cart :deep(.ant-empty-description) {
color: var(--text-secondary);
}
.empty-action {
min-width: 128px;
height: 42px;
border: 0;
border-radius: 999px;
color: var(--theme-accent);
font-weight: 800;
background: var(--theme-primary);
box-shadow: var(--theme-button-shadow);
}
.status-card {
display: grid;
gap: 16px;
margin-bottom: 14px;
padding: 20px;
border: 1px solid var(--theme-border);
border-radius: var(--cart-radius-lg);
background:
linear-gradient(145deg, color-mix(in srgb, var(--theme-card-bg) 92%, transparent), color-mix(in srgb, var(--theme-primary-soft) 72%, var(--theme-page-bg))),
var(--theme-gradient-soft);
box-shadow: 0 18px 44px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
}
.status-card.has-issues {
border-color: var(--theme-secondary);
}
.status-copy {
min-width: 0;
}
.status-eyebrow {
margin: 0 0 6px;
color: var(--theme-secondary);
font-size: 11px;
font-weight: 800;
}
.status-copy h1 {
margin: 0;
color: var(--text-primary);
font-size: 20px;
line-height: 1.2;
letter-spacing: 0;
}
.status-copy p {
margin: 8px 0 0;
color: var(--text-secondary);
font-size: 13px;
line-height: 1.55;
}
.status-total {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 14px;
border: 1px solid color-mix(in srgb, var(--theme-primary) 36%, var(--theme-border));
border-radius: 18px;
background: color-mix(in srgb, var(--theme-card-bg) 76%, transparent);
}
.status-total span,
.status-metric span,
.appointment-head span,
.appointment-grid span,
.summary-row span,
.coupon-panel span,
.footer-summary span,
.item-subtitle,
.item-total span {
color: var(--text-secondary);
}
.status-total strong {
color: var(--theme-accent);
font-size: 26px;
line-height: 1;
}
.status-metrics {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.status-metric {
min-width: 0;
padding: 10px;
border: 1px solid color-mix(in srgb, var(--theme-border) 82%, transparent);
border-radius: 16px;
background: color-mix(in srgb, var(--theme-card-bg) 70%, transparent);
}
.status-metric span,
.status-metric strong {
display: block;
}
.status-metric span {
margin-bottom: 4px;
font-size: 11px;
}
.status-metric strong {
overflow: hidden;
color: var(--theme-accent);
font-size: 13px;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-warning {
cursor: pointer;
border-color: var(--theme-secondary);
}
.metric-warning strong {
color: var(--theme-secondary);
}
.issue-callout {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
padding: 14px;
border: 1px solid var(--theme-border);
border-left: 4px solid var(--theme-secondary);
border-radius: 18px;
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
}
.issue-callout strong,
.issue-callout span {
display: block;
}
.issue-callout strong {
margin-bottom: 4px;
color: var(--theme-accent);
}
.issue-callout span {
color: var(--text-secondary);
font-size: 12px;
}
.issue-callout :deep(.ant-btn) {
border-radius: 999px;
color: var(--theme-accent);
border-color: var(--theme-secondary);
background: color-mix(in srgb, var(--theme-secondary) 16%, var(--theme-card-bg));
}
.checkout-layout {
display: grid;
gap: 14px;
}
.cart-group-card,
.coupon-panel,
.preview-panel,
.summary-panel {
border: 1px solid var(--theme-border);
border-radius: var(--cart-radius-lg);
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
box-shadow: 0 18px 44px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
}
.cart-group-card {
padding: 14px;
}
.group-head {
display: grid;
grid-template-columns: 42px minmax(0, 1fr) auto;
gap: 10px;
align-items: center;
padding-bottom: 12px;
border-bottom: 1px solid color-mix(in srgb, var(--theme-border) 78%, transparent);
}
.shop-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border-radius: 16px;
color: var(--theme-accent);
font-weight: 900;
background: var(--theme-primary);
box-shadow: 0 10px 24px color-mix(in srgb, var(--theme-primary) 26%, transparent);
}
.group-copy {
min-width: 0;
}
.group-copy span,
.group-copy strong {
display: block;
}
.group-copy span {
overflow: hidden;
color: var(--text-primary);
font-size: 15px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.group-copy strong {
margin-top: 2px;
color: var(--text-secondary);
font-size: 12px;
font-weight: 600;
}
.group-head em {
display: inline-flex;
align-items: center;
min-height: 26px;
padding: 0 10px;
border-radius: 999px;
color: var(--theme-secondary);
font-size: 12px;
font-style: normal;
font-weight: 800;
background: color-mix(in srgb, var(--theme-secondary) 16%, var(--theme-card-bg));
white-space: nowrap;
}
.cart-list {
display: grid;
margin-top: 12px;
gap: 12px;
}
.checkout-side {
display: grid;
gap: 12px;
align-content: start;
}
.item-card {
display: grid;
grid-template-columns: auto 76px minmax(0, 1fr);
gap: 10px;
align-items: start;
min-width: 0;
padding: 12px;
border: 1px solid color-mix(in srgb, var(--theme-border) 88%, transparent);
border-radius: var(--cart-radius-md);
background: color-mix(in srgb, var(--theme-card-bg) 94%, transparent);
transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.item-card.is-selected {
border-color: color-mix(in srgb, var(--theme-primary) 58%, var(--theme-border));
box-shadow: 0 12px 28px color-mix(in srgb, var(--theme-primary) 12%, transparent);
}
.issue-card {
border-color: var(--theme-secondary);
box-shadow: var(--theme-focus-shadow);
}
.item-check {
padding-top: 28px;
}
.item-check :deep(.ant-checkbox-inner) {
width: 18px;
height: 18px;
border-radius: 6px;
border-color: var(--theme-border);
background: var(--theme-card-bg);
}
.item-check :deep(.ant-checkbox-checked .ant-checkbox-inner) {
border-color: var(--theme-primary);
background: var(--theme-primary);
}
.thumb {
display: flex;
align-items: center;
justify-content: center;
width: 76px;
height: 76px;
overflow: hidden;
border: 0;
border-radius: 18px;
color: var(--theme-accent);
background: var(--theme-primary-soft);
cursor: pointer;
}
.thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.thumb span {
font-size: 22px;
font-weight: 900;
}
.item-main {
min-width: 0;
}
.item-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
min-width: 0;
}
.title {
flex: 1;
min-width: 0;
display: -webkit-box;
overflow: hidden;
padding: 0;
border: 0;
color: var(--text-primary);
background: transparent;
font-size: 15px;
font-weight: 800;
line-height: 1.38;
text-align: left;
overflow-wrap: break-word;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
cursor: pointer;
}
.status-pill {
flex: 0 0 auto;
max-width: 88px;
overflow: hidden;
padding: 4px 8px;
border-radius: 999px;
color: var(--text-secondary);
background: var(--theme-primary-soft);
font-size: 11px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.status-pill.ready {
color: var(--theme-secondary);
background: color-mix(in srgb, var(--theme-secondary) 14%, var(--theme-card-bg));
}
.status-pill.issue {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary) 30%, var(--theme-card-bg));
}
.item-subtitle {
display: flex;
flex-wrap: wrap;
gap: 5px 8px;
margin-top: 6px;
font-size: 12px;
}
.appointment-panel {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
padding: 10px 12px;
border: 1px solid color-mix(in srgb, var(--theme-border) 88%, transparent);
border-radius: 16px;
background: var(--theme-primary-soft);
color: inherit;
text-align: left;
cursor: pointer;
}
.appointment-panel.issue {
border-color: var(--theme-secondary);
background: color-mix(in srgb, var(--theme-secondary) 10%, var(--theme-primary-soft));
}
.appointment-panel.ready {
border-color: color-mix(in srgb, var(--theme-secondary) 40%, var(--theme-border));
background: color-mix(in srgb, var(--theme-card-bg) 78%, var(--theme-primary-soft));
}
.appointment-content {
flex: 1;
min-width: 0;
}
.appointment-head {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.appointment-head strong {
color: var(--theme-accent);
white-space: nowrap;
}
.appointment-panel.issue .appointment-head strong {
color: var(--theme-secondary);
}
.appointment-grid {
display: grid;
gap: 5px;
}
.appointment-grid div {
min-width: 0;
}
.appointment-grid span,
.appointment-grid strong {
display: block;
font-size: 12px;
}
.actions,
.qty,
.summary-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.actions {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
gap: 8px;
margin-top: 10px;
}
.qty {
gap: 0;
min-width: 88px;
overflow: hidden;
border: 1px solid var(--theme-border);
border-radius: 999px;
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
}
.qty span {
min-width: 30px;
color: var(--text-primary);
font-size: 13px;
font-weight: 800;
text-align: center;
}
.qty-btn {
width: 28px;
height: 28px;
display: inline-grid;
place-items: center;
border: 0;
color: var(--theme-accent);
background: transparent;
font-size: 15px;
font-weight: 900;
cursor: pointer;
}
.qty-btn:disabled {
color: color-mix(in srgb, var(--text-secondary) 48%, transparent);
cursor: not-allowed;
}
.item-total {
min-width: 0;
text-align: right;
}
.item-total span,
.item-total strong {
display: block;
}
.item-total span {
font-size: 11px;
}
.item-total strong {
overflow: hidden;
color: var(--theme-accent);
font-size: 14px;
text-overflow: ellipsis;
white-space: nowrap;
}
.remove-button {
width: 30px;
height: 30px;
display: inline-grid;
place-items: center;
border: 1px solid var(--theme-border);
border-radius: 999px;
color: var(--text-secondary);
background: color-mix(in srgb, var(--theme-card-bg) 86%, transparent);
cursor: pointer;
}
.coupon-panel {
width: 100%;
display: grid;
grid-template-columns: minmax(0, 1fr) auto auto;
gap: 10px;
align-items: center;
padding: 14px;
border-radius: 18px;
color: inherit;
text-align: left;
cursor: pointer;
}
.coupon-panel span,
.coupon-panel strong {
display: block;
}
.coupon-panel span {
margin-bottom: 4px;
font-size: 12px;
}
.coupon-panel strong {
overflow: hidden;
color: var(--text-primary);
font-size: 14px;
text-overflow: ellipsis;
white-space: nowrap;
}
.coupon-panel em {
color: var(--theme-secondary);
font-style: normal;
font-weight: 700;
white-space: nowrap;
}
.preview-panel {
display: grid;
gap: 6px;
padding: 14px;
border-radius: 18px;
}
.preview-line {
color: var(--text-secondary);
font-size: 12px;
line-height: 1.5;
}
.preview-line.vip {
color: var(--theme-secondary);
font-weight: 700;
}
.summary-panel {
padding: 16px;
}
.summary-title {
margin-bottom: 6px;
color: var(--text-primary);
font-size: 15px;
font-weight: 900;
}
.summary-row {
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid color-mix(in srgb, var(--theme-border) 82%, transparent);
font-size: 13px;
}
.summary-row strong {
color: var(--text-primary);
white-space: nowrap;
}
.quote-remark-field {
display: grid;
gap: 8px;
margin-bottom: 14px;
color: var(--text-secondary);
font-size: 13px;
}
.summary-row.discount strong,
.summary-row.total strong {
color: var(--theme-accent);
}
.summary-row.total {
border-bottom: 0;
font-weight: 700;
}
.summary-row.total strong {
font-size: 20px;
}
.footer {
position: fixed;
left: 50%;
bottom: var(--cart-bottom-offset);
z-index: 20;
width: min(100%, var(--cart-shell-width));
display: flex;
align-items: center;
gap: 12px;
padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
border: 1px solid color-mix(in srgb, var(--theme-border) 86%, transparent);
border-bottom: 0;
border-radius: 24px 24px 0 0;
background: color-mix(in srgb, var(--theme-card-bg) 94%, transparent);
border-top: 1px solid var(--theme-border);
box-shadow: 0 -18px 44px color-mix(in srgb, var(--theme-neutral) 10%, transparent);
backdrop-filter: blur(16px);
transform: translateX(-50%);
}
.footer-summary {
flex: 1;
min-width: 0;
}
.footer-summary span,
.footer-summary strong {
display: block;
}
.footer-summary span {
margin-bottom: 2px;
font-size: 12px;
}
.footer-summary strong {
color: var(--theme-accent);
font-size: 20px;
}
.checkout-button {
min-width: 136px;
height: 46px;
border: 0;
border-radius: 999px;
color: var(--theme-accent);
font-weight: 900;
background: var(--theme-primary);
box-shadow: var(--theme-button-shadow);
}
.checkout-button:not(:disabled):hover,
.checkout-button:not(:disabled):focus {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary) 86%, var(--theme-card-bg));
}
.checkout-button:disabled {
color: var(--text-secondary);
background: var(--theme-primary-soft);
box-shadow: none;
}
.coupon-options {
display: flex;
flex-direction: column;
gap: 8px;
}
.coupon-option-copy {
display: grid;
gap: 2px;
min-width: 0;
}
.coupon-option-copy strong,
.coupon-option-copy em {
overflow-wrap: break-word;
}
.coupon-option-copy strong {
color: var(--text-primary);
}
.coupon-option-copy em {
color: var(--theme-secondary);
font-size: 12px;
font-style: normal;
}
.coupon-unavailable {
display: grid;
gap: 8px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--theme-border);
}
.coupon-unavailable-item {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
color: var(--text-secondary);
font-size: 12px;
line-height: 1.5;
}
.coupon-unavailable-item span {
min-width: 0;
color: var(--text-primary);
overflow-wrap: break-word;
}
.coupon-unavailable-item em {
max-width: 180px;
color: var(--text-secondary);
font-style: normal;
text-align: right;
}
:global(.cart-coupon-modal-wrap .ant-modal) {
max-width: calc(100vw - 24px);
}
:global(.cart-coupon-modal-wrap .ant-modal-content) {
overflow: hidden;
padding: 0;
border: 1px solid var(--theme-border);
border-radius: 24px;
background: var(--theme-card-bg);
box-shadow: 0 24px 64px color-mix(in srgb, var(--theme-neutral) 22%, transparent);
}
:global(.cart-coupon-modal-wrap .ant-modal-header) {
margin: 0;
padding: 18px 22px 12px;
border-bottom: 1px solid var(--theme-border);
background: var(--theme-card-bg);
}
:global(.cart-coupon-modal-wrap .ant-modal-title) {
color: var(--text-primary);
font-size: 16px;
font-weight: 800;
}
:global(.cart-coupon-modal-wrap .ant-modal-close) {
color: var(--text-secondary);
}
:global(.cart-coupon-modal-wrap .ant-modal-body) {
padding: 18px 22px 14px;
}
:global(.cart-coupon-modal-wrap .ant-modal-footer) {
display: flex;
gap: 10px;
justify-content: flex-end;
margin: 0;
padding: 14px 22px 20px;
border-top: 1px solid var(--theme-border);
background: var(--theme-card-bg);
}
:global(.cart-coupon-modal-wrap .cart-coupon-modal__cancel),
:global(.cart-coupon-modal-wrap .cart-coupon-modal__ok) {
min-width: 82px;
height: 38px;
border-radius: 999px;
font-weight: 700;
}
:global(.cart-coupon-modal-wrap .cart-coupon-modal__cancel) {
color: var(--text-primary);
border-color: var(--theme-border);
background: var(--theme-card-bg);
}
:global(.cart-coupon-modal-wrap .cart-coupon-modal__cancel:hover),
:global(.cart-coupon-modal-wrap .cart-coupon-modal__cancel:focus) {
color: var(--theme-primary);
border-color: var(--theme-primary);
}
:global(.cart-coupon-modal-wrap .cart-coupon-modal__ok) {
color: var(--theme-accent);
border: 0;
background: var(--theme-primary);
box-shadow: var(--theme-button-shadow);
}
:global(.cart-coupon-modal-wrap .cart-coupon-modal__ok:hover),
:global(.cart-coupon-modal-wrap .cart-coupon-modal__ok:focus) {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary) 86%, var(--theme-card-bg));
}
:global(.cart-coupon-modal-wrap .ant-radio-wrapper) {
align-items: flex-start;
margin: 0;
color: var(--text-primary);
line-height: 1.6;
}
:global(.cart-coupon-modal-wrap .ant-radio-wrapper + .ant-radio-wrapper) {
margin-top: 8px;
}
:global(.cart-coupon-modal-wrap .ant-radio-checked .ant-radio-inner) {
border-color: var(--theme-primary);
background: var(--theme-primary);
}
:global(.cart-coupon-modal-wrap .ant-radio-wrapper:hover .ant-radio-inner) {
border-color: var(--theme-primary);
}
.cart-appbar {
position: sticky;
top: 0;
z-index: 30;
width: min(100%, var(--cart-shell-width));
margin: 0 auto;
padding: 12px 18px 9px;
border-bottom: 1px solid color-mix(in srgb, var(--theme-border) 78%, transparent);
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
backdrop-filter: blur(18px);
}
.cart-appbar-inner {
display: grid;
grid-template-columns: 42px minmax(0, 1fr) 42px;
align-items: center;
gap: 0;
min-height: 32px;
}
.cart-topbar-spacer {
width: 42px;
height: 32px;
}
.cart-brand {
min-width: 0;
overflow: hidden;
color: var(--text-primary);
font-size: 16px;
font-weight: 800;
letter-spacing: 0;
line-height: 1.25;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
}
.cart-content {
display: grid;
gap: 28px;
padding-top: 18px;
padding-bottom: calc(144px + var(--cart-bottom-offset) + env(safe-area-inset-bottom));
}
.cart-section {
display: grid;
gap: 14px;
}
.cart-section-head {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
padding: 0 2px;
}
.cart-section-head h2 {
margin: 0;
color: var(--text-primary);
font-family: "Playfair Display", "Noto Serif SC", serif;
font-size: 23px;
font-weight: 800;
line-height: 1.15;
letter-spacing: 0;
}
.cart-section-head span {
flex: 0 0 auto;
color: var(--text-secondary);
font-size: 12px;
font-weight: 700;
line-height: 1.4;
}
.cart-item-list,
.service-card-list {
display: grid;
gap: 14px;
}
.cart-product-card {
display: grid;
grid-template-columns: auto 96px minmax(0, 1fr);
gap: 12px;
align-items: center;
min-width: 0;
padding: 14px;
border: 1px solid color-mix(in srgb, var(--theme-border) 76%, transparent);
border-radius: 22px;
background:
linear-gradient(145deg, color-mix(in srgb, var(--theme-card-bg) 90%, transparent), color-mix(in srgb, var(--theme-primary-soft) 42%, var(--theme-card-bg))),
color-mix(in srgb, var(--theme-card-bg) 86%, transparent);
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-neutral) 9%, transparent);
backdrop-filter: blur(18px);
transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.cart-product-card.selected {
border-color: color-mix(in srgb, var(--theme-primary) 52%, var(--theme-border));
box-shadow: 0 18px 46px color-mix(in srgb, var(--theme-primary) 13%, transparent);
}
.cart-product-card.warning {
border-color: color-mix(in srgb, var(--theme-secondary) 74%, var(--theme-border));
}
.product-check {
align-self: start;
margin-top: 38px;
}
.product-check :deep(.ant-checkbox-inner) {
width: 18px;
height: 18px;
border-radius: 6px;
border-color: color-mix(in srgb, var(--theme-primary) 40%, var(--theme-border));
background: color-mix(in srgb, var(--theme-card-bg) 72%, transparent);
}
.product-check :deep(.ant-checkbox-checked .ant-checkbox-inner) {
border-color: var(--theme-primary);
background: var(--theme-primary);
}
.product-thumb {
width: 96px;
height: 96px;
display: grid;
place-items: center;
overflow: hidden;
padding: 0;
border: 0;
border-radius: 20px;
color: var(--theme-accent);
background: linear-gradient(135deg, var(--theme-primary-soft), color-mix(in srgb, var(--theme-card-bg) 78%, var(--theme-primary)));
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--theme-border) 72%, transparent);
cursor: pointer;
}
.product-thumb img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
object-position: center;
}
.product-thumb span {
font-size: 26px;
font-weight: 900;
}
.product-info {
min-width: 0;
display: grid;
align-self: stretch;
align-content: space-between;
gap: 8px;
}
.product-title-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 32px;
gap: 8px;
align-items: start;
}
.product-title {
min-width: 0;
display: -webkit-box;
overflow: hidden;
padding: 0;
border: 0;
color: var(--text-primary);
background: transparent;
font-size: 15px;
font-weight: 800;
line-height: 1.35;
letter-spacing: 0;
text-align: left;
overflow-wrap: break-word;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
cursor: pointer;
}
.product-delete {
width: 32px;
height: 32px;
display: inline-grid;
place-items: center;
border: 1px solid color-mix(in srgb, var(--theme-border) 82%, transparent);
border-radius: 50%;
color: var(--text-secondary);
background: color-mix(in srgb, var(--theme-card-bg) 70%, transparent);
cursor: pointer;
}
.product-delete:hover,
.product-delete:focus {
color: var(--theme-secondary);
border-color: color-mix(in srgb, var(--theme-secondary) 48%, var(--theme-border));
}
.product-meta {
display: flex;
flex-wrap: wrap;
gap: 5px 8px;
min-width: 0;
margin: 0;
color: var(--text-secondary);
font-size: 12px;
line-height: 1.45;
}
.product-meta span {
min-width: 0;
max-width: 100%;
overflow: hidden;
padding: 3px 8px;
border-radius: 999px;
background: color-mix(in srgb, var(--theme-primary-soft) 70%, transparent);
text-overflow: ellipsis;
white-space: nowrap;
}
.product-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
min-width: 0;
}
.product-price {
min-width: 0;
overflow: hidden;
color: var(--theme-accent);
font-size: 17px;
line-height: 1.1;
text-overflow: ellipsis;
white-space: nowrap;
}
.product-qty {
flex: 0 0 auto;
display: inline-grid;
grid-template-columns: 30px minmax(28px, auto) 30px;
align-items: center;
min-height: 32px;
overflow: hidden;
border: 1px solid color-mix(in srgb, var(--theme-border) 78%, transparent);
border-radius: 999px;
background: color-mix(in srgb, var(--theme-card-bg) 72%, transparent);
}
.product-qty button {
width: 30px;
height: 30px;
border: 0;
color: var(--theme-accent);
background: transparent;
font-size: 15px;
font-weight: 900;
line-height: 1;
cursor: pointer;
}
.product-qty button:disabled {
color: color-mix(in srgb, var(--text-secondary) 46%, transparent);
cursor: not-allowed;
}
.product-qty span {
min-width: 28px;
color: var(--text-primary);
font-size: 13px;
font-weight: 800;
text-align: center;
}
.stitch-issue {
margin: 0;
}
.service-detail-card,
.offer-card {
width: 100%;
display: grid;
gap: 12px;
min-width: 0;
border: 1px solid color-mix(in srgb, var(--theme-border) 76%, transparent);
border-radius: 22px;
color: inherit;
background: color-mix(in srgb, var(--theme-card-bg) 86%, transparent);
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
backdrop-filter: blur(18px);
}
.service-detail-card {
padding: 14px;
text-align: left;
}
.service-detail-main {
width: 100%;
display: grid;
grid-template-columns: 46px minmax(0, 1fr) auto 14px;
align-items: center;
gap: 12px;
min-width: 0;
padding: 0;
border: 0;
color: inherit;
background: transparent;
text-align: left;
cursor: pointer;
}
.service-detail-card.ready {
border-color: color-mix(in srgb, var(--theme-primary) 42%, var(--theme-border));
}
.service-detail-card.warning {
border-color: color-mix(in srgb, var(--theme-secondary) 62%, var(--theme-border));
}
.service-icon,
.offer-icon {
display: grid;
place-items: center;
overflow: hidden;
border-radius: 16px;
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary) 40%, var(--theme-card-bg));
}
.service-icon {
width: 46px;
height: 46px;
}
.service-icon img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
object-position: center;
}
.service-icon span {
font-size: 16px;
font-weight: 900;
line-height: 1;
}
.service-copy,
.offer-copy {
min-width: 0;
display: grid;
gap: 3px;
}
.service-copy span,
.service-copy strong,
.service-copy em,
.offer-copy strong,
.offer-copy em {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.service-copy span {
color: var(--text-secondary);
font-size: 12px;
font-weight: 700;
}
.service-copy strong,
.offer-copy strong {
color: var(--text-primary);
font-size: 15px;
font-weight: 850;
}
.service-copy em,
.offer-copy em {
color: var(--text-secondary);
font-size: 12px;
font-style: normal;
line-height: 1.35;
}
.service-state {
max-width: 88px;
overflow: hidden;
padding: 5px 9px;
border-radius: 999px;
color: var(--theme-secondary);
background: color-mix(in srgb, var(--theme-secondary) 14%, var(--theme-card-bg));
font-size: 11px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.service-detail-card.warning .service-state {
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary) 28%, var(--theme-card-bg));
}
.service-label {
color: var(--text-secondary);
font-size: 11px;
font-weight: 900;
line-height: 1.2;
}
.service-artist-strip,
.service-time-panel {
display: grid;
gap: 10px;
padding-top: 10px;
border-top: 1px solid color-mix(in srgb, var(--theme-border) 70%, transparent);
}
.service-artist-list {
display: flex;
gap: 12px;
overflow-x: auto;
padding: 2px 1px 4px;
scrollbar-width: none;
}
.service-artist-list::-webkit-scrollbar {
display: none;
}
.service-artist-option {
flex: 0 0 auto;
width: 64px;
display: grid;
justify-items: center;
gap: 6px;
padding: 0;
border: 0;
color: var(--text-secondary);
background: transparent;
cursor: pointer;
opacity: .62;
transition: opacity .18s ease, transform .18s ease;
}
.service-artist-option:hover,
.service-artist-option.active {
color: var(--theme-accent);
opacity: 1;
transform: translateY(-1px);
}
.service-artist-option img,
.service-artist-option > span {
width: 56px;
height: 56px;
display: grid;
place-items: center;
overflow: hidden;
border: 2px solid color-mix(in srgb, var(--theme-border) 86%, transparent);
border-radius: 50%;
color: var(--theme-accent);
background: color-mix(in srgb, var(--theme-primary-soft) 70%, var(--theme-card-bg));
object-fit: cover;
}
.service-artist-option.active img,
.service-artist-option.active > span {
border-color: var(--theme-primary);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-primary) 14%, transparent);
}
.service-artist-option em {
width: 100%;
overflow: hidden;
font-size: 11px;
font-style: normal;
font-weight: 800;
line-height: 1.2;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
}
.service-time-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.service-time-head button {
border: 0;
color: var(--theme-accent);
background: transparent;
font-size: 12px;
font-weight: 800;
cursor: pointer;
}
.service-time-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.service-time-option {
min-width: 0;
display: grid;
gap: 2px;
padding: 9px 8px;
border: 1px solid color-mix(in srgb, var(--theme-border) 76%, transparent);
border-radius: 999px;
color: var(--text-primary);
background: color-mix(in srgb, var(--theme-card-bg) 68%, transparent);
text-align: center;
cursor: pointer;
transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.service-time-option:hover,
.service-time-option.active {
border-color: var(--theme-primary);
background: color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg));
transform: translateY(-1px);
}
.service-time-option span,
.service-time-option strong {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.service-time-option span {
color: var(--text-secondary);
font-size: 10px;
font-weight: 700;
}
.service-time-option strong {
color: var(--theme-accent);
font-size: 13px;
}
.service-empty {
padding: 28px 12px;
border: 1px solid color-mix(in srgb, var(--theme-border) 76%, transparent);
border-radius: 22px;
background: color-mix(in srgb, var(--theme-card-bg) 78%, transparent);
}
.offer-card {
grid-template-columns: 48px minmax(0, 1fr) auto 14px;
padding: 16px;
text-align: left;
}
.offer-card:disabled {
cursor: not-allowed;
opacity: .62;
}
.offer-icon {
width: 48px;
height: 48px;
}
.offer-save {
color: var(--theme-accent);
font-size: 13px;
font-weight: 900;
white-space: nowrap;
}
.stitch-preview {
margin-top: -2px;
border-color: color-mix(in srgb, var(--theme-primary) 28%, var(--theme-border));
background: color-mix(in srgb, var(--theme-primary-soft) 66%, var(--theme-card-bg));
}
.stitch-summary {
padding: 18px;
border-radius: 24px;
background:
linear-gradient(145deg, color-mix(in srgb, var(--theme-card-bg) 92%, transparent), color-mix(in srgb, var(--theme-primary-soft) 42%, var(--theme-card-bg))),
color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
backdrop-filter: blur(18px);
}
.stitch-summary h3 {
margin: 0 0 10px;
color: var(--text-primary);
font-size: 13px;
font-weight: 900;
line-height: 1.2;
letter-spacing: 0;
text-align: center;
}
.stitch-summary .summary-row {
padding: 10px 0;
font-size: 13px;
}
.stitch-summary .summary-row.total {
padding-top: 13px;
}
.stitch-summary .summary-row.total strong {
color: var(--theme-accent);
font-size: 23px;
}
.cart-footer {
justify-content: center;
gap: 0;
padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
backdrop-filter: blur(22px);
}
.cart-footer .checkout-button {
width: 100%;
max-width: 100%;
height: 50px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
font-size: 15px;
}
.cart-footer .checkout-button :deep(.anticon) {
font-size: 17px;
}
.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 var(--theme-border);
border-radius: 999px;
background: var(--theme-card-bg);
cursor: pointer;
}
.artist-option.active {
border-color: var(--theme-primary);
color: var(--theme-primary);
background: var(--theme-primary-soft);
}
.artist-option img {
width: 24px;
height: 24px;
border-radius: 50%;
object-fit: cover;
}
.artist-option em {
color: var(--theme-secondary);
font-size: 12px;
font-style: normal;
}
.coupon-tip,
.helper {
color: var(--text-secondary);
font-size: 12px;
}
.quick-time-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
gap: 8px;
margin: 10px 0;
}
.quick-time {
display: grid;
gap: 2px;
padding: 10px 12px;
border: 1px solid var(--theme-border);
border-radius: 14px;
background: var(--theme-card-bg);
color: var(--text-primary);
text-align: left;
cursor: pointer;
transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.quick-time:hover,
.quick-time.active {
border-color: var(--theme-primary);
background: var(--theme-primary-soft);
transform: translateY(-1px);
}
.quick-time span {
color: var(--text-secondary);
font-size: 12px;
}
.quick-time strong {
font-size: 16px;
}
@media (max-width: 420px) {
.content {
padding-inline: 12px;
}
.cart-header {
margin-inline: -12px;
padding-inline: 12px;
}
.status-metrics {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
}
.status-metric {
padding: 9px 7px;
}
.cart-group-card {
padding: 12px;
}
.item-card {
grid-template-columns: auto 70px minmax(0, 1fr);
padding: 10px;
}
.thumb {
width: 70px;
height: 70px;
}
.footer {
padding-inline: 14px;
}
.checkout-button {
min-width: 124px;
}
.cart-appbar {
padding-inline: 12px;
}
.cart-content {
gap: 24px;
padding-top: 16px;
}
.cart-section-head h2 {
font-size: 21px;
}
.cart-product-card {
grid-template-columns: auto 82px minmax(0, 1fr);
gap: 10px;
padding: 12px;
border-radius: 20px;
}
.product-check {
margin-top: 32px;
}
.product-thumb {
width: 82px;
height: 82px;
border-radius: 18px;
}
.product-title {
font-size: 14px;
}
.product-meta {
font-size: 11px;
}
.service-detail-card {
padding: 12px;
border-radius: 20px;
}
.service-detail-main {
grid-template-columns: 42px minmax(0, 1fr) auto 12px;
gap: 10px;
}
.service-icon {
width: 42px;
height: 42px;
border-radius: 14px;
}
.service-state {
max-width: 76px;
padding-inline: 8px;
}
.service-artist-list {
gap: 10px;
}
.service-artist-option {
width: 58px;
}
.service-artist-option img,
.service-artist-option > span {
width: 50px;
height: 50px;
}
.service-time-grid {
gap: 6px;
}
.service-time-option {
padding-inline: 6px;
}
.offer-card {
grid-template-columns: 44px minmax(0, 1fr) auto 12px;
padding: 14px;
border-radius: 20px;
}
.offer-icon {
width: 44px;
height: 44px;
border-radius: 14px;
}
}
</style>