Files
JayuCloud/Frontend/src/views/CartView.vue
T

1370 lines
33 KiB
Vue
Raw Normal View History

<template>
<div class="mobile-container">
<!-- 头部区域 -->
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>购物车</h1>
<a-button class="edit-btn" type="text" @click="handleEditClick">
编辑
</a-button>
</header>
2026-03-05 16:08:27 +08:00
<!-- 购物车作品列表 -->
<div class="cart-items">
<a-empty v-if="cartItems.length === 0" description="购物车是空的">
<a-button type="primary" @click="handleBrowseProducts">去逛逛</a-button>
</a-empty>
<a-card
v-for="item in cartItems"
:key="item.id"
class="cart-item"
:body-style="{ padding: '16px' }"
2026-03-02 10:13:20 +08:00
hoverable
>
<div class="item-content">
<!-- 复选框 -->
<a-checkbox v-model:checked="item.selected" @change="handleSelectChange" />
2026-03-05 16:08:27 +08:00
<!-- 作品图片 -->
<div class="item-image" v-if="item.productImage" @click="handleProductClick(item)" style="cursor: pointer;">
<img :src="item.productImage" :alt="item.productTitle" />
</div>
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor(), cursor: 'pointer' }" @click="handleProductClick(item)">
<span>{{ item.productTitle[0] }}</span>
</div>
2026-03-05 16:08:27 +08:00
<!-- 作品详情 -->
<div class="item-details">
<h3 class="item-name" @click="handleProductClick(item)" style="cursor: pointer;">{{ item.productTitle }}</h3>
2026-02-25 10:37:16 +08:00
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
2026-03-19 14:10:59 +08:00
<!-- 美甲师选择 -->
<div class="artist-selector" @click="showArtistSelection(item)">
<span v-if="item.artist" class="selected-artist">
<img v-if="item.artist.avatar" :src="item.artist.avatar" class="artist-avatar-small" />
<span class="artist-name">{{ item.artist.name }}</span>
</span>
<span v-else class="select-artist">
选择美甲师
</span>
<RightOutlined class="arrow-icon" />
</div>
<!-- 数量控制和删除按钮 -->
<div class="item-actions">
2026-02-25 10:37:16 +08:00
<div class="quantity-control">
<a-button
size="small"
:disabled="item.quantity <= 1"
@click="handleDecreaseQuantity(item)"
>
-
</a-button>
<span class="quantity-value">{{ item.quantity }}</span>
<a-button
size="small"
:disabled="item.quantity >= 99"
@click="handleIncreaseQuantity(item)"
>
+
</a-button>
</div>
<a-popconfirm
2026-03-05 16:08:27 +08:00
title="确定要删除这个作品吗?"
ok-text="确定"
cancel-text="取消"
@confirm="handleDeleteItem(item)"
>
<a-button type="text" danger size="small">
<DeleteOutlined />
</a-button>
</a-popconfirm>
</div>
</div>
</div>
</a-card>
</div>
<!-- 优惠券选择 -->
<div class="coupon-section" v-if="cartItems.length > 0 && selectedCount > 0">
<a-card class="coupon-card">
<div class="coupon-header" @click="showCouponModal = true">
<span class="coupon-title">优惠券</span>
<div class="coupon-value">
2026-03-19 14:10:59 +08:00
{{ selectedCoupon ? selectedCoupon.couponName : '使用优惠券' }}
<RightOutlined :style="{ marginLeft: '4px' }" />
</div>
</div>
<div class="coupon-discount" v-if="selectedCoupon">
<span class="discount-label">优惠金额</span>
<span class="discount-amount">-¥{{ discountAmount.toFixed(2) }}</span>
</div>
</a-card>
</div>
<!-- 订单摘要 -->
<div class="summary" v-if="cartItems.length > 0">
<div class="summary-row">
2026-03-05 16:08:27 +08:00
<span>作品数量</span>
<span>{{ totalQuantity }} 件</span>
</div>
<div class="summary-row">
<span>小计</span>
2026-02-25 10:37:16 +08:00
<span>¥{{ subtotal.toFixed(2) }}</span>
</div>
<div class="summary-row" v-if="selectedCoupon">
<span>优惠</span>
<span class="discount">-¥{{ discountAmount.toFixed(2) }}</span>
</div>
<div class="summary-row total">
<span>总计</span>
<span class="total-price">¥{{ totalAmount.toFixed(2) }}</span>
</div>
</div>
<!-- 结算按钮 -->
<div class="checkout-section" v-if="cartItems.length > 0">
<a-button
type="primary"
size="large"
block
@click="handleCheckout"
>
2026-03-19 14:10:59 +08:00
确认 {{ selectedCount }} 笔订单- 预计金额 ¥{{ totalAmount.toFixed(2) }}
</a-button>
</div>
<!-- 优惠券选择弹窗 -->
<a-modal
v-model:visible="showCouponModal"
2026-03-19 14:10:59 +08:00
title="使用优惠券"
width="90%"
2026-02-28 17:09:45 +08:00
@ok="confirmCouponSelection"
@cancel="cancelCouponSelection"
>
<div class="coupon-modal-content">
<a-empty v-if="availableCoupons.length === 0" description="暂无可用优惠券" />
<div v-else class="coupon-list">
2026-02-28 17:09:45 +08:00
<!-- 取消选择选项 -->
<a-card
class="modal-coupon-card"
:class="{ active: !selectedCoupon }"
@click="selectedCoupon = null"
>
<div class="coupon-content">
<div class="coupon-value">
不使用
</div>
<div class="coupon-info">
<div class="coupon-name">不使用优惠券</div>
<div class="coupon-condition">
直接结算
</div>
<div class="coupon-select" v-if="!selectedCoupon">
<CheckCircleOutlined />
</div>
</div>
</div>
</a-card>
<a-divider />
<!-- 优惠券列表 -->
<a-card
v-for="coupon in availableCoupons"
:key="coupon.id"
class="modal-coupon-card"
:class="{ active: selectedCoupon && selectedCoupon.id === coupon.id }"
2026-02-28 17:09:45 +08:00
@click="selectedCoupon = coupon"
>
<div class="coupon-content">
<div class="coupon-value">
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
</div>
<div class="coupon-info">
<div class="coupon-name">{{ coupon.couponName }}</div>
<div class="coupon-condition" v-if="coupon.couponType === 2">
满{{ coupon.minAmount }}元可用
</div>
<div class="coupon-time">
{{ coupon.startTime }} 至 {{ coupon.endTime }}
</div>
2026-02-28 14:32:28 +08:00
<div class="coupon-select" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
<CheckCircleOutlined />
</div>
</div>
</div>
</a-card>
</div>
</div>
</a-modal>
2026-02-28 14:32:28 +08:00
<!-- 美甲师选择弹窗 -->
<a-modal
v-model:visible="showArtistModal"
2026-03-19 14:10:59 +08:00
:title='currentEditingItem ? `为"${currentEditingItem.productTitle}"选择美甲师` : "选择美甲师"'
2026-02-28 14:32:28 +08:00
width="90%"
2026-03-19 14:10:59 +08:00
@ok="confirmArtistSelection"
2026-02-28 14:32:28 +08:00
@cancel="closeArtistModal"
>
<div class="artist-modal-content">
<a-empty v-if="availableArtists.length === 0" description="暂无可用美甲师" />
<div v-else class="artist-list">
2026-03-04 11:17:38 +08:00
<div class="artist-list-container">
<div
2026-02-28 14:32:28 +08:00
v-for="artist in availableArtists"
:key="artist.id"
class="artist-item"
2026-03-19 14:10:59 +08:00
:class="{ 'selected': currentEditingItem && currentEditingItem.artistId === artist.id }"
@click="selectArtist(artist)"
2026-02-28 14:32:28 +08:00
>
2026-03-04 11:17:38 +08:00
<div class="artist-card">
<div class="artist-avatar">
<img
:src="getArtistAvatar(artist)"
:alt="artist.name"
class="avatar-image"
/>
</div>
<div class="artist-details">
<div class="artist-header">
<h3 class="artist-name">{{ artist.name }}</h3>
<div class="artist-rating">
<span class="rating-star">⭐</span>
2026-03-04 15:42:43 +08:00
<span class="rating-score">{{ artist.rating || 0 }}</span>
2026-03-04 11:17:38 +08:00
</div>
</div>
<div class="artist-info">
2026-03-04 15:42:43 +08:00
<span class="artist-experience">经验: {{ artist.experience || 0 }}年</span>
2026-03-04 11:17:38 +08:00
<span class="artist-status" :class="{ 'available': artist.status === 1 }">
{{ artist.status === 1 ? '可预约' : '不可预约' }}
</span>
</div>
2026-03-04 15:42:43 +08:00
<div v-if="artist.signature" class="artist-signature">
{{ artist.signature }}
</div>
2026-03-04 11:17:38 +08:00
<div class="artist-skills">
2026-03-04 15:42:43 +08:00
<span class="skill-tag" v-for="skill in getArtistSkills(artist)" :key="skill">{{ skill }}</span>
2026-03-04 11:17:38 +08:00
</div>
</div>
2026-03-19 14:10:59 +08:00
<div class="artist-selection-indicator" v-if="currentEditingItem && currentEditingItem.artistId === artist.id">
2026-03-04 11:17:38 +08:00
<CheckCircleOutlined style="color: #1890ff; font-size: 20px;" />
</div>
2026-02-28 14:32:28 +08:00
</div>
2026-03-04 11:17:38 +08:00
</div>
</div>
2026-02-28 14:32:28 +08:00
</div>
</div>
</a-modal>
</div>
</template>
<script setup lang="ts">
2026-02-28 17:09:45 +08:00
import { ref, computed, onMounted, watch, inject } from 'vue'
import { useRouter } from 'vue-router'
import {
LeftOutlined,
DeleteOutlined,
RightOutlined,
CheckCircleOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { cartApi } from '../api/cart'
import { orderApi } from '../api/order'
import { fileApi } from '../api/index'
import { couponApi, type UserCoupon } from '../api/coupon'
2026-02-28 17:09:45 +08:00
import { userApi } from '../api/user'
2026-03-10 23:23:15 +08:00
import { tagApi, type TagVO } from '../api/tag'
2026-03-04 15:42:43 +08:00
import api from '../api'
2026-02-28 17:09:45 +08:00
// 注入更新购物车数量的方法
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
interface CartItem {
id: number
productId: number
productTitle: string
productImage: string
2026-03-04 11:17:38 +08:00
originalProductImage?: string
price: number
quantity: number
totalPrice: number
2026-02-28 15:45:16 +08:00
tags: string
selected: boolean
2026-03-19 14:10:59 +08:00
artistId?: number
artist?: {
id: number
name: string
avatar?: string
signature?: string
shopName?: string
status?: number
experience?: number
skills?: string
rating?: number
}
}
const router = useRouter()
2026-03-05 16:08:27 +08:00
// 购物车作品数据
const cartItems = ref<CartItem[]>([])
// 图片缓存
const imageIdCache = ref<Record<string, string>>({})
// 优惠券相关状态
const availableCoupons = ref<UserCoupon[]>([])
const selectedCoupon = ref<UserCoupon | null>(null)
const showCouponModal = ref(false)
// 加载购物车数据
const loadCartItems = async () => {
try {
2026-03-02 10:13:20 +08:00
const response = await cartApi.getCartList() as any
cartItems.value = response.map((item: any) => ({
...item,
2026-03-04 11:17:38 +08:00
selected: true,
// 临时将productImage设为空,避免浏览器直接加载本地API路径
originalProductImage: item.productImage,
productImage: ''
}))
await loadProductImages(cartItems.value)
await loadAvailableCoupons()
} catch (error) {
message.error('获取购物车数据失败')
2026-02-25 10:37:16 +08:00
}
}
2026-03-05 16:08:27 +08:00
// 加载作品图片
const loadProductImages = async (items: CartItem[]) => {
for (const item of items) {
2026-03-04 11:17:38 +08:00
if (item.originalProductImage) {
const cleanImageUrl = item.originalProductImage.replace(/<[^>]*>/g, '')
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
if (match && match[1]) {
const imageId = match[1]
try {
if (!imageIdCache.value[imageId]) {
2026-03-04 11:17:38 +08:00
// 尝试获取签名URL
try {
const response = await fileApi.getSignedUrl(Number(imageId)) as any
imageIdCache.value[imageId] = response
2026-03-10 23:23:15 +08:00
item.productImage = imageIdCache.value[imageId] || ''
2026-03-04 11:17:38 +08:00
} catch (error) {
// 静默处理404错误,不显示错误信息
console.log('图片不存在或无法获取签名URL:', imageId)
item.productImage = ''
}
} else {
2026-03-10 23:23:15 +08:00
item.productImage = imageIdCache.value[imageId] || ''
}
} catch (error) {
2026-03-04 11:17:38 +08:00
console.error('处理图片时出错:', error)
item.productImage = ''
}
} else {
item.productImage = ''
}
}
}
}
// 加载可用优惠券
const loadAvailableCoupons = async () => {
try {
const totalPrice = subtotal.value
2026-02-28 15:45:16 +08:00
const productTagsSet = new Set<string>()
cartItems.value
.filter(item => item.selected)
2026-02-28 15:45:16 +08:00
.forEach(item => {
if (item.tags) {
const tags = item.tags.split(',').map(tag => tag.trim())
tags.forEach(tag => {
if (tag) productTagsSet.add(tag)
})
}
})
const productTags = Array.from(productTagsSet).join(',')
if (totalPrice > 0) {
2026-03-02 10:13:20 +08:00
const response = await couponApi.getAvailableCoupons(productTags, totalPrice) as any
availableCoupons.value = response
2026-02-28 15:45:16 +08:00
} else {
availableCoupons.value = []
}
} catch (error) {
console.error('获取可用优惠券失败:', error)
2026-02-28 15:45:16 +08:00
availableCoupons.value = []
}
}
2026-03-05 16:08:27 +08:00
// 计算选中的作品数量
const selectedCount = computed(() => {
return cartItems.value.filter(item => item.selected).length
})
2026-03-05 16:08:27 +08:00
// 计算作品总数量
const totalQuantity = computed(() => {
return cartItems.value.reduce((sum, item) => sum + item.quantity, 0)
})
// 计算小计
const subtotal = computed(() => {
return cartItems.value
.filter(item => item.selected)
.reduce((sum, item) => sum + item.totalPrice, 0)
})
// 计算优惠金额
const discountAmount = computed(() => {
if (!selectedCoupon.value) return 0
const total = subtotal.value
const coupon = selectedCoupon.value
if (coupon.couponType === 1) {
// 折扣券
return total - (total * parseFloat(coupon.discountValue) / 10)
} else if (coupon.couponType === 2) {
// 满减券
return parseFloat(coupon.reduceAmount)
}
return 0
})
// 计算总金额
const totalAmount = computed(() => {
return Math.max(0, subtotal.value - discountAmount.value)
})
// 生成随机颜色
const getRandomColor = () => {
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
return colors[Math.floor(Math.random() * colors.length)]
}
// 处理返回按钮点击
const handleBackClick = () => {
router.back()
}
// 处理编辑按钮点击
const handleEditClick = () => {
}
// 处理选择状态变化
const handleSelectChange = async () => {
// 重新加载可用优惠券
await loadAvailableCoupons()
}
2026-02-25 10:37:16 +08:00
// 处理减少数量
const handleDecreaseQuantity = async (item: CartItem) => {
2026-02-25 10:37:16 +08:00
if (item.quantity > 1) {
item.quantity--
try {
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
// 重新加载可用优惠券
await loadAvailableCoupons()
2026-02-28 17:09:45 +08:00
// 更新购物车数量
await updateCartCount()
} catch (error) {
message.error('更新数量失败')
item.quantity++
}
2026-02-25 10:37:16 +08:00
}
}
// 处理增加数量
const handleIncreaseQuantity = async (item: CartItem) => {
2026-02-25 10:37:16 +08:00
if (item.quantity < 99) {
item.quantity++
try {
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
// 重新加载可用优惠券
await loadAvailableCoupons()
2026-02-28 17:09:45 +08:00
// 更新购物车数量
await updateCartCount()
} catch (error) {
message.error('更新数量失败')
item.quantity--
}
2026-02-25 10:37:16 +08:00
}
}
2026-03-05 16:08:27 +08:00
// 处理删除作品
const handleDeleteItem = async (item: CartItem) => {
try {
await cartApi.removeFromCart(item.productId)
const index = cartItems.value.findIndex(i => i.id === item.id)
if (index > -1) {
cartItems.value.splice(index, 1)
2026-03-05 16:08:27 +08:00
message.success('作品已删除')
// 重新加载可用优惠券
await loadAvailableCoupons()
2026-02-28 17:09:45 +08:00
// 更新购物车数量
await updateCartCount()
}
} catch (error) {
2026-03-05 16:08:27 +08:00
message.error('删除作品失败')
}
}
2026-03-02 10:13:20 +08:00
const handleProductClick = (item: CartItem) => {
router.push(`/product/${item.productId}`)
}
2026-03-05 16:08:27 +08:00
// 处理浏览作品
const handleBrowseProducts = () => {
router.push('/products')
}
2026-02-28 17:09:45 +08:00
// 确认优惠券选择
const confirmCouponSelection = () => {
showCouponModal.value = false
}
// 取消优惠券选择
const cancelCouponSelection = () => {
showCouponModal.value = false
}
2026-02-28 14:32:28 +08:00
// 美甲师选择相关状态
const showArtistModal = ref(false)
2026-03-19 14:10:59 +08:00
const currentEditingItem = ref<CartItem | null>(null)
2026-03-04 15:42:43 +08:00
const availableArtists = ref<{id: number, name: string, avatar?: string, signature?: string, shopName?: string, status?: number, experience?: number, skills?: string, rating?: number}[]>([])
// 标签列表
2026-03-10 23:23:15 +08:00
const tagList = ref<TagVO[]>([])
2026-03-04 15:42:43 +08:00
// 加载标签列表
const loadTagList = async () => {
try {
// 使用前台API获取标签列表
2026-03-10 23:23:15 +08:00
const tags = await tagApi.getAllTags() as unknown as TagVO[]
2026-03-04 15:42:43 +08:00
tagList.value = tags || []
} catch (error) {
console.error('获取标签列表失败:', error)
tagList.value = []
}
}
2026-02-28 14:32:28 +08:00
// 加载可用美甲师
const loadAvailableArtists = async () => {
try {
2026-03-04 15:42:43 +08:00
// 先加载标签列表
await loadTagList()
// 首先获取所有美甲师用户
const users = await userApi.listUsersByType(3) as any
// 然后获取每个美甲师的详细信息
const artistsWithDetails = await Promise.all(
users.map(async (user: any) => {
try {
// 调用前台美甲师信息API获取详细信息
2026-03-10 23:23:15 +08:00
const nailArtistInfo = await api.get(`/nail-artist/get/${user.id}`) as any
2026-03-04 15:42:43 +08:00
return {
id: user.id,
name: user.nickname,
avatar: user.avatar,
signature: nailArtistInfo?.signature || user.signature,
shopName: nailArtistInfo?.shopName || user.shopName,
status: nailArtistInfo?.status || user.status,
experience: nailArtistInfo?.experience || 0,
skills: nailArtistInfo?.skills || '',
rating: nailArtistInfo?.rating || 0
}
} catch (error) {
console.error(`获取美甲师 ${user.nickname} 详细信息失败:`, error)
// 如果获取失败,返回基本信息
return {
id: user.id,
name: user.nickname,
avatar: user.avatar,
signature: user.signature,
shopName: user.shopName,
status: user.status,
experience: 0,
skills: '',
rating: 0
}
}
})
)
availableArtists.value = artistsWithDetails
2026-02-28 14:32:28 +08:00
} catch (error) {
console.error('获取美甲师列表失败:', error)
2026-02-28 17:09:45 +08:00
availableArtists.value = []
2026-02-28 14:32:28 +08:00
}
}
// 处理结算
const handleCheckout = async () => {
const selectedItems = cartItems.value.filter(item => item.selected)
if (selectedItems.length === 0) {
2026-03-05 16:08:27 +08:00
message.warning('请先选择要结算的作品')
return
}
2026-03-19 14:10:59 +08:00
// 检查所有选中的作品是否都选择了美甲师
const itemsWithoutArtist = selectedItems.filter(item => !item.artistId)
if (itemsWithoutArtist.length > 0) {
message.warning(`请为"${itemsWithoutArtist.map(item => item.productTitle).join('、')}"选择美甲师`)
2026-02-28 14:32:28 +08:00
return
}
2026-03-19 14:10:59 +08:00
// 创建订单
try {
2026-03-02 10:13:20 +08:00
await orderApi.createOrder({
2026-02-28 14:32:28 +08:00
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined,
2026-03-19 14:10:59 +08:00
items: selectedItems.map(item => ({
productId: item.productId,
quantity: item.quantity,
artistId: item.artistId
}))
})
message.success('订单创建成功')
2026-03-19 14:10:59 +08:00
// 从购物车中移除已购买的商品
const selectedIds = selectedItems.map(item => item.id)
await cartApi.batchRemoveFromCart(selectedIds)
// 更新购物车数据
await loadCartItems()
// 更新购物车数量
2026-02-28 17:09:45 +08:00
await updateCartCount()
router.push('/profile')
} catch (error) {
message.error('创建订单失败')
}
}
2026-03-19 14:10:59 +08:00
// 显示美甲师选择弹窗
const showArtistSelection = (item: CartItem) => {
currentEditingItem.value = item
loadAvailableArtists()
showArtistModal.value = true
}
// 选择美甲师
const selectArtist = (artist: any) => {
if (currentEditingItem.value) {
currentEditingItem.value.artistId = artist.id
currentEditingItem.value.artist = artist
}
}
// 确认选择
const confirmArtistSelection = () => {
showArtistModal.value = false
currentEditingItem.value = null
}
2026-02-28 14:32:28 +08:00
// 关闭美甲师选择弹窗
const closeArtistModal = () => {
showArtistModal.value = false
2026-03-19 14:10:59 +08:00
currentEditingItem.value = null
2026-02-28 14:32:28 +08:00
}
2026-03-04 11:17:38 +08:00
// 获取美甲师头像
const getArtistAvatar = (artist: any) => {
// 优先使用用户表中的真实头像
if (artist.avatar) {
return artist.avatar
}
// 生成基于ID的随机头像
const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD']
2026-03-10 23:23:15 +08:00
const color = colors[artist.id % colors.length] || '#FF6B6B'
2026-03-04 11:17:38 +08:00
return `https://api.dicebear.com/7.x/avataaars/svg?seed=${artist.id}&backgroundColor=${color.replace('#', '')}`
}
// 获取随机评分
2026-03-10 23:23:15 +08:00
// const _getRandomRating = () => {
// return (4 + Math.random()).toFixed(1)
// }
2026-03-04 11:17:38 +08:00
// 获取随机经验
2026-03-10 23:23:15 +08:00
// const _getRandomExperience = () => {
// return Math.floor(1 + Math.random() * 5)
// }
2026-03-04 11:17:38 +08:00
// 获取随机技能标签
2026-03-10 23:23:15 +08:00
// const _getRandomSkills = () => {
// const allSkills = ['手绘', '雕花', '水晶甲', '光疗甲', '渐变', '法式', '钻饰', '创意美甲']
// const skillsCount = 2 + Math.floor(Math.random() * 3)
// const shuffled = allSkills.sort(() => 0.5 - Math.random())
// return shuffled.slice(0, skillsCount)
// }
2026-03-04 11:17:38 +08:00
2026-03-04 15:42:43 +08:00
// 获取美甲师的技能标签
const getArtistSkills = (artist: any) => {
if (!artist.skills) {
return []
}
const skillIds = artist.skills.split(',').filter((id: string) => id)
return skillIds.map((id: string) => {
2026-03-10 23:23:15 +08:00
const tag = tagList.value.find((t: any) => t.id.toString() === id)
2026-03-04 15:42:43 +08:00
return tag ? tag.tagName : id
})
}
2026-03-05 16:08:27 +08:00
// 监听选中作品变化,重新加载可用优惠券
watch(
() => cartItems.value.map(item => ({ id: item.id, selected: item.selected, quantity: item.quantity })),
async () => {
await loadAvailableCoupons()
},
{ deep: true }
)
// 页面加载时获取购物车数据
onMounted(() => {
loadCartItems()
})
</script>
<style scoped>
.mobile-container {
padding-top: 60px;
min-height: 100vh;
background: #f5f5f5;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #f0f0f0;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.back-btn,
.edit-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
}
.cart-items {
padding: 15px;
padding-bottom: 20px;
}
.cart-item {
margin-bottom: 12px;
border-radius: 12px;
overflow: hidden;
2026-03-02 10:13:20 +08:00
cursor: pointer;
transition: transform 0.3s, box-shadow 0.3s;
}
.cart-item:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.cart-item :deep(.ant-card-body) {
padding: 16px;
}
.item-content {
display: flex;
gap: 12px;
align-items: flex-start;
}
.item-image {
width: 80px;
height: 80px;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
font-weight: bold;
color: rgba(0,0,0,0.1);
flex-shrink: 0;
overflow: hidden;
}
.item-image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.item-details {
flex: 1;
display: flex;
flex-direction: column;
min-height: 80px;
}
.item-name {
font-size: 15px;
font-weight: 600;
margin: 0 0 4px 0;
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.item-price {
color: #ff4d4f;
font-weight: bold;
margin: 0;
font-size: 16px;
}
2026-03-19 14:10:59 +08:00
.artist-selector {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #f8f9ff;
border-radius: 8px;
margin-bottom: 10px;
cursor: pointer;
transition: all 0.3s ease;
}
.artist-selector:hover {
background: #e6f7ff;
}
.selected-artist {
display: flex;
align-items: center;
gap: 8px;
color: #1890ff;
font-weight: 500;
}
.artist-avatar-small {
width: 24px;
height: 24px;
border-radius: 50%;
object-fit: cover;
}
.select-artist {
color: #999;
font-size: 13px;
display: flex;
align-items: center;
gap: 4px;
}
.arrow-icon {
color: #999;
font-size: 12px;
transition: transform 0.3s ease;
}
.artist-selector:hover .arrow-icon {
transform: translateX(4px);
}
2026-02-25 10:37:16 +08:00
.item-duration {
color: #666;
font-size: 13px;
margin: 4px 0 0 0;
}
.item-actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 8px;
}
2026-02-25 10:37:16 +08:00
.quantity-control {
display: flex;
align-items: center;
gap: 8px;
}
.quantity-value {
min-width: 30px;
text-align: center;
font-weight: 600;
font-size: 16px;
}
.summary {
margin: 0 15px 15px;
padding: 16px;
background: #fafafa;
border-radius: 12px;
}
.summary-row {
display: flex;
justify-content: space-between;
padding: 8px 0;
font-size: 14px;
color: #666;
}
.summary-row.total {
font-size: 16px;
font-weight: bold;
color: #333;
border-top: 1px solid #e8e8e8;
padding-top: 12px;
margin-top: 4px;
}
.total-price {
color: #ff4d4f;
font-size: 20px;
}
2026-02-25 10:37:16 +08:00
.duration {
color: #667eea;
font-weight: 600;
}
.checkout-section {
position: fixed;
bottom: 60px;
left: 0;
right: 0;
padding: 15px;
background: white;
border-top: 1px solid #f0f0f0;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}
.checkout-section :deep(.ant-btn-lg) {
height: 48px;
border-radius: 24px;
font-weight: 600;
font-size: 16px;
}
/* 优惠券样式 */
.coupon-section {
margin: 0 15px 15px;
}
.coupon-card {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
border: 1px solid #f0f0f0;
transition: all 0.3s ease;
}
.coupon-card:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
transform: translateY(-2px);
}
.coupon-header {
display: flex;
justify-content: space-between;
align-items: center;
2026-03-19 14:10:59 +08:00
padding: 12px 16px;
cursor: pointer;
background: linear-gradient(135deg, #f6f9ff 0%, #ffffff 100%);
border-bottom: 1px solid #e6f7ff;
}
.coupon-header:hover {
background: linear-gradient(135deg, #e6f7ff 0%, #f6f9ff 100%);
}
.coupon-title {
2026-03-19 14:10:59 +08:00
font-size: 14px;
font-weight: 600;
color: #333;
display: flex;
align-items: center;
2026-03-19 14:10:59 +08:00
gap: 6px;
}
.coupon-title::before {
content: "🎁";
2026-03-19 14:10:59 +08:00
font-size: 14px;
}
.coupon-value {
2026-03-19 14:10:59 +08:00
font-size: 12px;
font-weight: 500;
color: #1890ff;
display: flex;
align-items: center;
2026-03-19 14:10:59 +08:00
gap: 4px;
padding: 4px 10px;
background: rgba(24, 144, 255, 0.1);
2026-03-19 14:10:59 +08:00
border-radius: 16px;
transition: all 0.3s ease;
box-shadow: 0 1px 3px rgba(24, 144, 255, 0.2);
}
.coupon-value:hover {
background: rgba(24, 144, 255, 0.2);
transform: scale(1.05);
box-shadow: 0 2px 6px rgba(24, 144, 255, 0.3);
}
.coupon-discount {
2026-03-19 14:10:59 +08:00
padding: 10px 16px;
background-color: #f0f9ff;
border-top: 1px solid #e6f7ff;
display: flex;
justify-content: space-between;
align-items: center;
}
.discount-label {
2026-03-19 14:10:59 +08:00
font-size: 12px;
color: #666;
display: flex;
align-items: center;
2026-03-19 14:10:59 +08:00
gap: 4px;
}
.discount-label::before {
content: "💰";
2026-03-19 14:10:59 +08:00
font-size: 12px;
}
.discount-amount {
2026-03-19 14:10:59 +08:00
font-size: 16px;
font-weight: 700;
color: #1890ff;
text-shadow: 0 1px 2px rgba(24, 144, 255, 0.3);
}
.discount {
color: #1890ff;
font-weight: 600;
}
/* 优惠券弹窗样式 */
.coupon-modal-content {
max-height: 400px;
overflow-y: auto;
}
.coupon-list {
padding: 8px 0;
}
.modal-coupon-card {
margin-bottom: 12px;
border-radius: 12px;
overflow: hidden;
cursor: pointer;
transition: all 0.3s;
}
.modal-coupon-card:hover {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.modal-coupon-card.active {
border: 2px solid #1890ff;
}
.coupon-content {
display: flex;
align-items: center;
2026-03-19 14:10:59 +08:00
padding: 10px;
gap: 10px;
}
.coupon-value {
2026-03-19 14:10:59 +08:00
font-size: 18px;
font-weight: 600;
color: #ff4d4f;
flex-shrink: 0;
2026-03-19 14:10:59 +08:00
min-width: 50px;
text-align: center;
}
.coupon-info {
flex: 1;
min-width: 0;
}
.coupon-name {
2026-03-19 14:10:59 +08:00
font-size: 13px;
font-weight: 600;
color: #333;
2026-03-19 14:10:59 +08:00
margin-bottom: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.coupon-condition {
2026-03-19 14:10:59 +08:00
font-size: 11px;
color: #666;
2026-03-19 14:10:59 +08:00
margin-bottom: 2px;
}
.coupon-time {
2026-03-19 14:10:59 +08:00
font-size: 10px;
color: #999;
}
.coupon-select {
color: #1890ff;
2026-03-19 14:10:59 +08:00
font-size: 16px;
flex-shrink: 0;
}
2026-02-28 14:32:28 +08:00
/* 美甲师选择弹窗样式 */
.artist-modal-content {
2026-03-04 11:17:38 +08:00
max-height: 500px;
2026-02-28 14:32:28 +08:00
overflow-y: auto;
2026-03-04 11:17:38 +08:00
padding: 10px 0;
2026-02-28 14:32:28 +08:00
}
.artist-list {
padding: 8px 0;
}
2026-03-04 11:17:38 +08:00
.artist-list-container {
display: flex;
flex-direction: column;
gap: 12px;
}
2026-02-28 14:32:28 +08:00
.artist-item {
display: block;
width: 100%;
2026-03-04 11:17:38 +08:00
border-radius: 12px;
overflow: hidden;
transition: all 0.3s ease;
cursor: pointer;
2026-02-28 14:32:28 +08:00
}
2026-03-04 11:17:38 +08:00
.artist-item:hover {
background-color: #f5f9ff;
}
.artist-item.selected {
background-color: #e6f7ff;
}
.artist-card {
display: flex;
align-items: flex-start;
gap: 16px;
padding: 16px;
background: white;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
position: relative;
}
.artist-item:hover .artist-card {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
transform: translateY(-2px);
}
.artist-item.selected .artist-card {
border: 2px solid #1890ff;
box-shadow: 0 0 0 4px rgba(24, 144, 255, 0.1);
}
.artist-selection-indicator {
position: absolute;
top: 12px;
right: 12px;
background: white;
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.artist-avatar {
width: 64px;
height: 64px;
flex-shrink: 0;
}
.avatar-image {
width: 100%;
height: 100%;
border-radius: 50%;
object-fit: cover;
border: 3px solid #f0f0f0;
transition: all 0.3s ease;
}
.artist-item:hover .avatar-image {
border-color: #1890ff;
transform: scale(1.05);
}
.artist-details {
flex: 1;
min-width: 0;
}
.artist-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.artist-name {
font-size: 18px;
font-weight: 700;
color: #333;
margin: 0;
}
.artist-rating {
display: flex;
align-items: center;
gap: 4px;
background: linear-gradient(135deg, #ffd700, #ffed4e);
padding: 4px 12px;
border-radius: 16px;
font-weight: 600;
color: #333;
box-shadow: 0 2px 4px rgba(255, 215, 0, 0.3);
}
.rating-star {
font-size: 14px;
}
.rating-score {
font-size: 14px;
2026-02-28 14:32:28 +08:00
}
.artist-info {
display: flex;
align-items: center;
2026-03-04 11:17:38 +08:00
gap: 16px;
margin-bottom: 10px;
font-size: 14px;
color: #666;
2026-02-28 14:32:28 +08:00
}
2026-03-04 11:17:38 +08:00
.artist-experience {
display: flex;
align-items: center;
gap: 4px;
}
.artist-status {
padding: 2px 10px;
border-radius: 12px;
font-size: 12px;
2026-02-28 14:32:28 +08:00
font-weight: 600;
2026-03-04 11:17:38 +08:00
transition: all 0.3s ease;
}
.artist-status.available {
background: #f6ffed;
color: #52c41a;
border: 1px solid #b7eb8f;
}
.artist-skills {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.skill-tag {
padding: 4px 12px;
background: #f0f9ff;
color: #1890ff;
border: 1px solid #e6f7ff;
border-radius: 16px;
font-size: 12px;
font-weight: 500;
transition: all 0.3s ease;
}
.skill-tag:hover {
background: #e6f7ff;
transform: scale(1.05);
box-shadow: 0 2px 4px rgba(24, 144, 255, 0.2);
}
/* 弹窗按钮样式 */
.artist-modal-cancel {
border-radius: 20px !important;
padding: 0 24px !important;
}
:deep(.ant-modal-footer .ant-btn-primary) {
border-radius: 20px !important;
padding: 0 24px !important;
font-weight: 600 !important;
}
:deep(.ant-modal-header) {
border-bottom: none !important;
padding: 24px 24px 0 !important;
}
:deep(.ant-modal-title) {
font-size: 20px !important;
font-weight: 700 !important;
color: #333 !important;
text-align: center !important;
}
:deep(.ant-modal-body) {
padding: 24px !important;
}
:deep(.ant-empty) {
padding: 40px 0 !important;
}
:deep(.ant-empty-image) {
font-size: 60px !important;
}
:deep(.ant-empty-description) {
font-size: 16px !important;
color: #999 !important;
margin-top: 16px !important;
2026-02-28 14:32:28 +08:00
}
</style>