diff --git a/WeChatProgram/api/nail-artist.js b/WeChatProgram/api/nail-artist.js new file mode 100644 index 00000000..30001cb5 --- /dev/null +++ b/WeChatProgram/api/nail-artist.js @@ -0,0 +1,24 @@ +/** + * Mini program API wrapper for public nail artist pages. + */ +const request = require('../utils/request') + +module.exports = { + getPublicProfile(artistId) { + return request({ + url: `/nail-artist/profile/${artistId}` + }) + }, + + getAvailability(artistId) { + return request({ + url: `/nail-artist/${artistId}/availability` + }) + }, + + listReviews(artistId) { + return request({ + url: `/nail-artist/${artistId}/reviews` + }) + } +} diff --git a/WeChatProgram/api/order.js b/WeChatProgram/api/order.js index b35a5bd4..4a54aca6 100644 --- a/WeChatProgram/api/order.js +++ b/WeChatProgram/api/order.js @@ -17,6 +17,14 @@ module.exports = { }) }, + checkoutPreview(data) { + return request({ + url: '/order/checkout-preview', + method: 'POST', + data + }) + }, + /** * Purpose: getOrderList supports order.js by holding or executing the get order list page or API role. * Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow. @@ -47,6 +55,16 @@ module.exports = { }) }, + /** + * Purpose: listOrderArtistChangeRequests loads every change request attached to one order for timeline display. + * Usage: call it from the order page after loading the order list; callers may fall back to an empty list. + */ + listOrderArtistChangeRequests(orderId) { + return request({ + url: `/order/${orderId}/artist-change/requests` + }) + }, + /** * Purpose: submitArtistReview supports order.js by holding or executing the submit artist review page or API role. * Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow. diff --git a/WeChatProgram/api/shop.js b/WeChatProgram/api/shop.js index 904012b0..6b97f1fe 100644 --- a/WeChatProgram/api/shop.js +++ b/WeChatProgram/api/shop.js @@ -33,5 +33,15 @@ module.exports = { return request({ url: `/shop/get/${id}` }) + }, + + /** + * Purpose: getTrustProfile loads public trust signals for the shop detail page. + * Usage: render ratings, recent reviews, environment images, and booking hints. + */ + getTrustProfile(id) { + return request({ + url: `/shop/trust-profile/${id}` + }) } } diff --git a/WeChatProgram/api/tag.js b/WeChatProgram/api/tag.js index 41d68c61..4134d2d2 100644 --- a/WeChatProgram/api/tag.js +++ b/WeChatProgram/api/tag.js @@ -13,5 +13,16 @@ module.exports = { return request({ url: '/tag/list/all' }) + }, + + /** + * Purpose: getFilterOptions loads grouped public tag filters for scene-based browsing. + * Usage: call it from product list pages, then pass selected tag ids to getProductPage. + */ + getFilterOptions(shopId) { + return request({ + url: '/tag/list/filter-options', + params: shopId ? { shopId } : undefined + }) } } diff --git a/WeChatProgram/api/wishlist.js b/WeChatProgram/api/wishlist.js index b480e9f0..b093749b 100644 --- a/WeChatProgram/api/wishlist.js +++ b/WeChatProgram/api/wishlist.js @@ -54,5 +54,33 @@ module.exports = { return request({ url: '/wishlist/list' }) + }, + + getGroups() { + return request({ + url: '/wishlist/groups' + }) + }, + + getInspiration() { + return request({ + url: '/wishlist/inspiration' + }) + }, + + addWithGroup(data) { + return request({ + url: '/wishlist/add-with-group', + method: 'POST', + data + }) + }, + + moveWishlist(data) { + return request({ + url: '/wishlist/move', + method: 'POST', + data + }) } } diff --git a/WeChatProgram/app.json b/WeChatProgram/app.json index 59b51f45..0d9bb90a 100644 --- a/WeChatProgram/app.json +++ b/WeChatProgram/app.json @@ -7,6 +7,7 @@ "pages/profile/index", "pages/auth/index", "pages/product-detail/index", + "pages/artist-profile/index", "pages/shop-detail/index", "pages/orders/index", "pages/wishlist/index", diff --git a/WeChatProgram/pages/artist-profile/index.js b/WeChatProgram/pages/artist-profile/index.js new file mode 100644 index 00000000..848d8c7b --- /dev/null +++ b/WeChatProgram/pages/artist-profile/index.js @@ -0,0 +1,136 @@ +const nailArtistApi = require('../../api/nail-artist') +const navigation = require('../../utils/navigation') +const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config') + +function formatPrice(price) { + const value = Number(price || 0) + return value > 0 ? `¥${value.toFixed(2)}` : '到店确认' +} + +function formatDateTime(value) { + if (!value) { + return '' + } + return String(value).replace('T', ' ').slice(0, 16) +} + +Page({ + data: { + loading: true, + loadError: '', + artistId: '', + profile: null, + works: [], + reviews: [], + availability: [], + heroImage: DEFAULT_PRODUCT_IMAGE, + artistName: '美甲师', + artistDesc: '专注细节与稳定出品', + shopName: '门店待确认', + styleTags: [], + ratingText: '0.0', + serviceCountText: '0', + workTimeText: '到店确认' + }, + + onLoad(options) { + this.setData({ + artistId: options && options.id ? options.id : '' + }) + this.loadArtistProfile() + }, + + async onPullDownRefresh() { + await this.loadArtistProfile() + wx.stopPullDownRefresh() + }, + + async loadArtistProfile() { + if (!this.data.artistId) { + this.setData({ + loading: false, + loadError: '缺少美甲师信息' + }) + return + } + + this.setData({ + loading: true, + loadError: '' + }) + + try { + const [profile, availability, reviews] = await Promise.all([ + nailArtistApi.getPublicProfile(this.data.artistId), + nailArtistApi.getAvailability(this.data.artistId), + nailArtistApi.listReviews(this.data.artistId) + ]) + const works = (profile.works || []).map(work => ({ + ...work, + title: work.title || '美甲作品', + coverImageUrl: work.coverImageUrl || DEFAULT_PRODUCT_IMAGE, + priceText: formatPrice(work.price) + })) + const formattedReviews = (reviews || profile.reviews || []).map(review => ({ + ...review, + customerName: review.customerName || '匿名用户', + content: review.content || '这位用户没有填写文字评价', + submittedAtText: formatDateTime(review.submittedAt), + ratingText: Number(review.rating || 0).toFixed(1) + })) + const start = profile.workStartTime ? String(profile.workStartTime).slice(0, 5) : '' + const end = profile.workEndTime ? String(profile.workEndTime).slice(0, 5) : '' + + this.setData({ + profile, + works, + reviews: formattedReviews, + availability: availability || profile.availability || [], + heroImage: (works.find(work => work.coverImageUrl) || {}).coverImageUrl || DEFAULT_PRODUCT_IMAGE, + artistName: profile.artistName || '美甲师', + artistDesc: profile.identity || profile.signature || '专注细节与稳定出品', + shopName: profile.shopName || '门店待确认', + styleTags: (profile.styleTags || []).filter(Boolean), + ratingText: Number(profile.rating || 0).toFixed(1), + serviceCountText: String(profile.serviceCount || 0), + workTimeText: start && end ? `${start}-${end}` : '到店确认' + }) + } catch (error) { + this.setData({ + loadError: error.message || '美甲师个人页加载失败' + }) + } finally { + this.setData({ + loading: false + }) + } + }, + + handleBack() { + navigation.goBack('/pages/home/index') + }, + + handleRetry() { + this.loadArtistProfile() + }, + + handleOpenShop() { + const profile = this.data.profile + if (!profile || !profile.shopId) { + return + } + wx.navigateTo({ + url: `/pages/shop-detail/index?id=${profile.shopId}` + }) + }, + + handleOpenWork(event) { + const id = event.currentTarget.dataset.id + if (!id) { + return + } + wx.navigateTo({ + url: `/pages/product-detail/index?id=${id}` + }) + } +}) diff --git a/WeChatProgram/pages/artist-profile/index.json b/WeChatProgram/pages/artist-profile/index.json new file mode 100644 index 00000000..b16ef3e3 --- /dev/null +++ b/WeChatProgram/pages/artist-profile/index.json @@ -0,0 +1,4 @@ +{ + "navigationStyle": "custom", + "usingComponents": {} +} diff --git a/WeChatProgram/pages/artist-profile/index.wxml b/WeChatProgram/pages/artist-profile/index.wxml new file mode 100644 index 00000000..8386784f --- /dev/null +++ b/WeChatProgram/pages/artist-profile/index.wxml @@ -0,0 +1,98 @@ + + + ‹ + {{artistName}} + + + + + 加载中... + + + + 暂时无法查看个人页 + {{loadError}} + 重试 + + + + + + + + + 艺 + + {{artistName}} + {{artistDesc}} + {{shopName}} + + + + + + + 评分 + {{ratingText}} + + + 服务 + {{serviceCountText}} + + + 工时 + {{workTimeText}} + + + + + 擅长风格 + + {{item}} + + 暂未设置风格标签 + + + + 近期可预约 + + + {{item.dateText}} + {{item.timeText}} + + + 近期暂未放出可预约时间 + + + + 作品 + + + + {{item.title}} + {{item.priceText}} + + + 作品正在整理中 + + + + 评价 {{reviews.length}} + + + + + 客 + + {{item.customerName}} + {{item.submittedAtText}} + + {{item.ratingText}} + + {{item.content}} + + + 还没有公开评价 + + + diff --git a/WeChatProgram/pages/artist-profile/index.wxss b/WeChatProgram/pages/artist-profile/index.wxss new file mode 100644 index 00000000..2555ed99 --- /dev/null +++ b/WeChatProgram/pages/artist-profile/index.wxss @@ -0,0 +1,336 @@ +.artist-page { + min-height: 100vh; + background: #f6f7fb; + color: #1f2933; +} + +.page-header { + position: sticky; + top: 0; + z-index: 5; + display: flex; + align-items: center; + justify-content: space-between; + height: 96rpx; + padding: 0 24rpx; + background: rgba(255, 255, 255, 0.95); + border-bottom: 1rpx solid #e6e9ef; +} + +.back-btn, +.header-spacer { + width: 64rpx; + height: 64rpx; + line-height: 58rpx; + text-align: center; + font-size: 48rpx; +} + +.page-title { + flex: 1; + overflow: hidden; + text-align: center; + font-size: 32rpx; + font-weight: 700; + text-overflow: ellipsis; + white-space: nowrap; +} + +.content-scroll { + height: calc(100vh - 96rpx); +} + +.state-box { + display: flex; + min-height: 60vh; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 20rpx; + padding: 40rpx; + color: #65717f; +} + +.state-title { + color: #1f2933; + font-size: 34rpx; + font-weight: 700; +} + +.state-desc { + text-align: center; + line-height: 1.6; +} + +.primary-btn { + padding: 18rpx 36rpx; + color: #fff; + background: #c6597d; + border-radius: 12rpx; +} + +.hero { + position: relative; + height: 520rpx; + margin: 20rpx; + overflow: hidden; + background: #222831; + border-radius: 16rpx; +} + +.hero-image, +.hero-mask { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + width: 100%; + height: 100%; +} + +.hero-mask { + background: linear-gradient(180deg, rgba(10, 14, 20, 0.08), rgba(10, 14, 20, 0.72)); +} + +.artist-card { + position: absolute; + right: 28rpx; + bottom: 28rpx; + left: 28rpx; + display: flex; + gap: 22rpx; + align-items: center; + color: #fff; +} + +.avatar { + width: 112rpx; + height: 112rpx; + flex: 0 0 auto; + overflow: hidden; + border: 3rpx solid rgba(255, 255, 255, 0.8); + border-radius: 56rpx; +} + +.placeholder { + display: flex; + align-items: center; + justify-content: center; + background: #d8dde6; + color: #5f6b7a; + font-weight: 700; +} + +.artist-main { + min-width: 0; +} + +.artist-name, +.artist-desc, +.shop-link { + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.artist-name { + font-size: 44rpx; + font-weight: 800; +} + +.artist-desc { + margin-top: 10rpx; + color: rgba(255, 255, 255, 0.88); + font-size: 26rpx; +} + +.shop-link { + max-width: 440rpx; + margin-top: 16rpx; + padding: 12rpx 18rpx; + background: rgba(255, 255, 255, 0.18); + border: 1rpx solid rgba(255, 255, 255, 0.28); + border-radius: 12rpx; +} + +.metrics { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 16rpx; + margin: 0 20rpx 20rpx; +} + +.metric-item { + display: flex; + min-height: 132rpx; + flex-direction: column; + justify-content: center; + gap: 10rpx; + padding: 20rpx; + background: #fff; + border: 1rpx solid #e6e9ef; + border-radius: 16rpx; +} + +.metric-item text:first-child { + color: #65717f; + font-size: 24rpx; +} + +.metric-value { + overflow-wrap: anywhere; + font-size: 34rpx; + font-weight: 800; +} + +.section { + margin: 20rpx; + padding: 28rpx; + background: #fff; + border: 1rpx solid #e6e9ef; + border-radius: 16rpx; +} + +.section-head { + margin-bottom: 20rpx; + font-size: 32rpx; + font-weight: 800; +} + +.tag-list { + display: flex; + flex-wrap: wrap; + gap: 14rpx; +} + +.tag { + padding: 10rpx 18rpx; + color: #394554; + background: #eef1f5; + border-radius: 999rpx; +} + +.empty-text { + color: #7b8794; + line-height: 1.6; +} + +.slot-grid, +.work-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 16rpx; +} + +.slot { + display: flex; + min-height: 104rpx; + flex-direction: column; + justify-content: center; + gap: 8rpx; + padding: 18rpx; + background: #f6f7fb; + border: 1rpx solid #dfe4ea; + border-radius: 14rpx; +} + +.slot text:first-child { + color: #65717f; + font-size: 24rpx; +} + +.slot-time { + font-size: 32rpx; + font-weight: 800; +} + +.work-card { + overflow: hidden; + background: #fff; + border: 1rpx solid #e6e9ef; + border-radius: 14rpx; +} + +.work-card image { + width: 100%; + height: 210rpx; + background: #eef1f5; +} + +.work-title, +.work-price { + display: block; + overflow: hidden; + padding: 0 16rpx; + text-overflow: ellipsis; + white-space: nowrap; +} + +.work-title { + margin-top: 14rpx; + font-weight: 700; +} + +.work-price { + margin: 8rpx 0 16rpx; + color: #c6597d; + font-weight: 800; +} + +.review-list { + display: flex; + flex-direction: column; + gap: 18rpx; +} + +.review-card { + padding: 22rpx; + background: #f8fafc; + border: 1rpx solid #e6e9ef; + border-radius: 14rpx; +} + +.review-top { + display: flex; + align-items: center; + gap: 16rpx; +} + +.review-avatar { + width: 72rpx; + height: 72rpx; + border-radius: 36rpx; +} + +.review-meta { + flex: 1; + min-width: 0; +} + +.review-meta text { + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.review-meta text:last-child { + margin-top: 4rpx; + color: #7b8794; + font-size: 22rpx; +} + +.review-score { + color: #c6597d; + font-weight: 800; +} + +.review-content { + display: block; + margin-top: 18rpx; + color: #3f4a56; + line-height: 1.7; + white-space: pre-wrap; +} diff --git a/WeChatProgram/pages/cart/index.js b/WeChatProgram/pages/cart/index.js index 09ab8072..3b123788 100644 --- a/WeChatProgram/pages/cart/index.js +++ b/WeChatProgram/pages/cart/index.js @@ -3,11 +3,6 @@ * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. */ const cartApi = require('../../api/cart') -/** - * Purpose: couponApi supports index.js by holding or executing the coupon api 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 couponApi = require('../../api/coupon') /** * Purpose: orderApi supports index.js by holding or executing the order api 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. @@ -31,6 +26,8 @@ const theme = require('../../utils/theme') const { resolveLegacyImage } = require('../../utils/file') const { NO_COUPON_KEY } = require('../../utils/config') const { runWithLoading } = require('../../utils/loading') +const { clearBuyNowContext, isBuyNowCartItem, readBuyNowContext } = require('../../utils/buy-now') +const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery') const { buildAppointmentValue, formatDateTime, @@ -53,6 +50,9 @@ function getCouponKey(coupon) { * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getCouponDisplay(coupon) { + if (coupon && coupon.displayText) { + return coupon.displayText + } if (Number(coupon.couponType) === 1) { return `${coupon.couponName} ${coupon.discountValue} 折` } @@ -71,6 +71,9 @@ function calculateCouponDiscount(coupon, amount) { if (!coupon || amount <= 0) { return 0 } + if (coupon.discountAmount !== undefined && coupon.discountAmount !== null) { + return Number(coupon.discountAmount || 0) + } if (Number(coupon.couponType) === 1) { const discountValue = Number(coupon.discountValue || 0) @@ -160,6 +163,9 @@ Page({ minDate: getMinDateText(), cartItems: [], availableCoupons: [], + unavailableCoupons: [], + checkoutPreview: null, + vipTip: '', selectedCouponKey: NO_COUPON_KEY, /** * Purpose: couponSelectionTouched records whether the user explicitly chose a coupon option. @@ -167,13 +173,18 @@ Page({ */ couponSelectionTouched: false, selectedCount: 0, + isBuyNowMode: false, + heroKicker: '结算准备', + heroTitle: '已选 0 个预约项目', + heroDesc: '确认美甲师和时间后再下单。', totalQuantity: 0, subtotalAmount: 0, subtotalText: '¥0.00', discountAmountText: '¥0.00', totalAmountText: '¥0.00', checkoutIssues: [], - submittingOrder: false + submittingOrder: false, + recoveryState: clearRecoveryState() }), /** @@ -214,13 +225,19 @@ Page({ const selectedCoupon = this.getSelectedCoupon() const selectedCount = selectedItems.length const totalQuantity = selectedItems.reduce((sum, item) => sum + Number(item.quantity || 0), 0) - const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0) - const discountAmount = calculateCouponDiscount(selectedCoupon, subtotalAmount) - const totalAmount = Math.max(0, subtotalAmount - discountAmount) + const localSubtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0) + const preview = this.data.checkoutPreview || {} + const subtotalAmount = preview.subtotalAmount !== undefined ? Number(preview.subtotalAmount || 0) : localSubtotalAmount + const discountAmount = preview.savedAmount !== undefined ? Number(preview.savedAmount || 0) : calculateCouponDiscount(selectedCoupon, subtotalAmount) + const totalAmount = preview.payableAmount !== undefined ? Number(preview.payableAmount || 0) : Math.max(0, subtotalAmount - discountAmount) const checkoutIssues = buildCheckoutIssues(this.data.cartItems) + const isBuyNowMode = Boolean(this.data.isBuyNowMode) this.setData({ selectedCount, + heroKicker: isBuyNowMode ? '确认订单' : '结算准备', + heroTitle: isBuyNowMode ? '确认本次预约' : `已选 ${selectedCount} 个预约项目`, + heroDesc: isBuyNowMode ? '本次只会提交刚刚选择的作品,不会混入购物车其他项目。' : '确认美甲师和时间后再下单。', totalQuantity, subtotalAmount, subtotalText: `¥${formatPrice(subtotalAmount)}`, @@ -232,9 +249,13 @@ Page({ async loadCartItems() { const isLoggedIn = auth.isLoggedIn() + const buyNowContext = isLoggedIn ? readBuyNowContext() : null + const buyNowProductId = buyNowContext && buyNowContext.productId ? String(buyNowContext.productId) : '' this.setData({ isLoggedIn, - loading: isLoggedIn + isBuyNowMode: Boolean(buyNowProductId), + loading: isLoggedIn, + recoveryState: clearRecoveryState() }) /** @@ -245,9 +266,13 @@ Page({ this.setData({ cartItems: [], availableCoupons: [], + unavailableCoupons: [], + checkoutPreview: null, + vipTip: '', selectedCouponKey: NO_COUPON_KEY, couponSelectionTouched: false, - loading: false + loading: false, + recoveryState: clearRecoveryState() }) this.refreshSummary() return @@ -273,7 +298,7 @@ Page({ ...item, productImageUrl, priceText: `¥${formatPrice(item.price)}`, - selected: true, + selected: buyNowProductId ? isBuyNowCartItem(item, buyNowProductId) : true, artistId: item.artistId || '', artistName: artist ? artist.name : '', availableArtists, @@ -286,16 +311,26 @@ Page({ this.setData({ cartItems: formattedItems, selectedCouponKey: NO_COUPON_KEY, - couponSelectionTouched: false + couponSelectionTouched: false, + recoveryState: clearRecoveryState() }) + if (buyNowProductId) { + clearBuyNowContext() + } await this.loadAvailableCoupons() } catch (error) { this.setData({ - cartItems: [] - }) - wx.showToast({ - title: error.message || '购物车加载失败', - icon: 'none' + cartItems: [], + recoveryState: buildRecoveryState({ + title: '购物车加载失败', + message: error, + fallbackMessage: '购物车暂时没有加载出来,请重试或先去逛作品。', + actions: [ + { key: 'retryCartLoad', text: '重试' }, + { key: 'products', text: '去逛作品' }, + { key: 'contact', text: '联系客服' } + ] + }) }) } finally { this.setData({ @@ -314,6 +349,9 @@ Page({ if (!selectedItems.length) { this.setData({ availableCoupons: [], + unavailableCoupons: [], + checkoutPreview: null, + vipTip: '', selectedCouponKey: NO_COUPON_KEY, couponSelectionTouched: false }) @@ -321,24 +359,25 @@ Page({ return } - const tags = new Set() - const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0) - selectedItems.forEach(item => { - String(item.tagNames || '') - .split(',') - .map(tag => tag.trim()) - .filter(Boolean) - .forEach(tag => tags.add(tag)) - }) - try { - const coupons = await couponApi.getAvailableCoupons( - Array.from(tags).join(','), - subtotalAmount, - selectedItems[0].shopId - ) + const selectedCoupon = this.getSelectedCoupon() + const preview = await orderApi.checkoutPreview({ + couponId: selectedCoupon ? selectedCoupon.id : undefined, + couponSourceType: selectedCoupon ? selectedCoupon.sourceType : (this.data.couponSelectionTouched && this.data.selectedCouponKey === NO_COUPON_KEY ? NO_COUPON_KEY : undefined), + items: selectedItems.map(item => ({ + productId: item.productId, + quantity: item.quantity, + artistId: item.artistId, + appointmentTime: item.appointmentValue + })) + }) - const list = Array.isArray(coupons) ? coupons.map(item => ({ + const list = Array.isArray(preview && preview.availableCoupons) ? preview.availableCoupons.map(item => ({ + ...item, + key: getCouponKey(item), + displayText: getCouponDisplay(item) + })) : [] + const unavailableCoupons = Array.isArray(preview && preview.unavailableCoupons) ? preview.unavailableCoupons.map(item => ({ ...item, key: getCouponKey(item), displayText: getCouponDisplay(item) @@ -348,6 +387,7 @@ Page({ if (selectedCouponKey !== NO_COUPON_KEY && !list.find(item => item.key === selectedCouponKey)) { selectedCouponKey = NO_COUPON_KEY } + const previewSubtotalAmount = Number((preview && preview.subtotalAmount) || this.data.subtotalAmount || 0) /** * `if` page method. Use this from WXML event bindings or lifecycle hooks. @@ -355,8 +395,7 @@ Page({ */ if (selectedCouponKey === NO_COUPON_KEY && !this.data.couponSelectionTouched) { const bestCoupons = list - .filter(item => item.sourceType === 'SYSTEM_VIP') - .sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount)) + .sort((left, right) => calculateCouponDiscount(right, previewSubtotalAmount) - calculateCouponDiscount(left, previewSubtotalAmount)) /** * `if` page method. Use this from WXML event bindings or lifecycle hooks. * Call guide: read or update page data with `this.setData(...)` inside the method when state changes. @@ -368,11 +407,17 @@ Page({ this.setData({ availableCoupons: list, + unavailableCoupons, + checkoutPreview: preview || null, + vipTip: preview && preview.vipTip ? preview.vipTip : '', selectedCouponKey }) } catch (error) { this.setData({ availableCoupons: [], + unavailableCoupons: [], + checkoutPreview: null, + vipTip: '', selectedCouponKey: NO_COUPON_KEY, couponSelectionTouched: false }) @@ -397,6 +442,60 @@ Page({ navigation.switchTab('/pages/products/index') }, + handleRecoveryAction(event) { + const key = event.currentTarget.dataset.key + if (key === 'retryCartLoad') { + this.setData({ recoveryState: clearRecoveryState() }) + this.loadCartItems() + return + } + if (key === 'retryCheckout') { + this.setData({ recoveryState: clearRecoveryState() }) + this.handleCheckout() + return + } + if (key === 'contact') { + this.handleContactSupport() + return + } + if (key === 'cart') { + this.setData({ recoveryState: clearRecoveryState() }) + return + } + + const actions = this.data.recoveryState.actions || [] + const action = actions.find(item => item.key === key) + if (action && action.route) { + this.openRecoveryRoute(action.route) + } + }, + + openRecoveryRoute(route) { + const pureRoute = String(route || '').split('?')[0] + if (!pureRoute) { + return + } + if (navigation.isTabPage(pureRoute)) { + navigation.switchTab(pureRoute) + return + } + navigation.navigate(route) + }, + + handleContactSupport() { + wx.showModal({ + title: '联系客服', + content: '请截图保留失败提示;如果担心重复下单,请先查看订单。也可以前往“我的”页联系门店或平台客服。', + confirmText: '去我的', + cancelText: '留在本页', + success: res => { + if (res.confirm) { + navigation.switchTab('/pages/profile/index') + } + } + }) + }, + async handleToggleSelect(event) { const index = Number(event.currentTarget.dataset.index) const cartItems = this.data.cartItems.slice() @@ -640,7 +739,7 @@ Page({ selectedCouponKey: event.detail.value, couponSelectionTouched: true }) - this.refreshSummary() + this.loadAvailableCoupons() }, async handleCheckout() { @@ -704,9 +803,18 @@ Page({ icon: 'none' }) } catch (error) { - wx.showToast({ - title: error.message || '订单创建失败', - icon: 'none' + this.setData({ + recoveryState: buildRecoveryState({ + title: '下单失败', + message: error, + fallbackMessage: '订单创建失败,请重试;如果担心重复下单,请先查看订单。', + actions: [ + { key: 'retryCheckout', text: '重试下单' }, + { key: 'orders', text: '查看订单' }, + { key: 'contact', text: '联系客服' }, + { key: 'cart', text: '返回购物车' } + ] + }) }) } finally { this.setData({ diff --git a/WeChatProgram/pages/cart/index.wxml b/WeChatProgram/pages/cart/index.wxml index e6030bd8..94cb091f 100644 --- a/WeChatProgram/pages/cart/index.wxml +++ b/WeChatProgram/pages/cart/index.wxml @@ -9,10 +9,24 @@ + + {{recoveryState.title}} + {{recoveryState.message}} + + {{item.text}} + + + - 结算准备 - 已选 {{selectedCount}} 个预约项目 - 确认美甲师和时间后再下单。 + {{heroKicker}} + {{heroTitle}} + {{heroDesc}} @@ -93,7 +107,7 @@ 优惠方式 - 系统会优先匹配 VIP 优惠。 + {{vipTip || '系统会优先匹配 VIP 优惠。'}} + + + 本单暂不可用 + + {{coupon.displayText}} + {{coupon.unavailableReason || '本单暂不可用'}} + + + {{checkoutPreview.summaryText}} + {{vipTip}} 选中项目 {{selectedCount}} 项 @@ -124,11 +148,11 @@ {{totalQuantity}} 件 - 小计 + 商品小计 {{subtotalText}} - 优惠 + 已省 -{{discountAmountText}} @@ -142,6 +166,20 @@ 正在加载购物车 + + {{recoveryState.title}} + {{recoveryState.message}} + + {{item.text}} + + + 购物车还是空的 先加购,再预约。 diff --git a/WeChatProgram/pages/cart/index.wxss b/WeChatProgram/pages/cart/index.wxss index 87a39a13..f219f625 100644 --- a/WeChatProgram/pages/cart/index.wxss +++ b/WeChatProgram/pages/cart/index.wxss @@ -31,6 +31,54 @@ line-height: 1.7; } +.recovery-card { + display: flex; + flex-direction: column; + gap: 14rpx; + margin-bottom: 20rpx; + padding: 26rpx; + border: 2rpx solid var(--theme-border); +} + +.recovery-title { + font-size: 30rpx; + font-weight: 800; + color: #2d2430; +} + +.recovery-desc { + font-size: 24rpx; + line-height: 1.6; + color: #8d7a84; +} + +.recovery-actions { + display: flex; + flex-wrap: wrap; + gap: 14rpx; +} + +.recovery-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 136rpx; + height: 60rpx; + padding: 0 20rpx; + border-radius: 999rpx; + background: #ffffff; + border: 2rpx solid var(--theme-border); + color: #5d4b55; + font-size: 24rpx; + font-weight: 700; +} + +.recovery-btn.primary { + background: var(--theme-primary); + border-color: var(--theme-primary); + color: #ffffff; +} + .cart-item-card + .cart-item-card, .coupon-card, .summary-card { @@ -260,6 +308,55 @@ font-weight: 700; } +.unavailable-coupon-list { + margin-top: 22rpx; + padding-top: 18rpx; + border-top: 2rpx solid #f6eaee; +} + +.unavailable-title { + font-size: 24rpx; + font-weight: 700; + color: #8d7a84; +} + +.unavailable-coupon { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 18rpx; + margin-top: 14rpx; + font-size: 22rpx; + color: #8d7a84; +} + +.unavailable-coupon text:first-child { + flex: 1; + min-width: 0; + color: #5d4b55; +} + +.unavailable-coupon text:last-child { + max-width: 260rpx; + text-align: right; +} + +.summary-preview, +.summary-vip { + margin-bottom: 14rpx; + padding: 16rpx 18rpx; + border-radius: 18rpx; + background: var(--theme-primary-soft); + color: #5d4b55; + font-size: 24rpx; + line-height: 1.6; +} + +.summary-vip { + color: var(--theme-primary); + font-weight: 700; +} + .summary-row { display: flex; align-items: center; diff --git a/WeChatProgram/pages/orders/index.js b/WeChatProgram/pages/orders/index.js index 48a2d457..e140a724 100644 --- a/WeChatProgram/pages/orders/index.js +++ b/WeChatProgram/pages/orders/index.js @@ -3,6 +3,7 @@ * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. */ const orderApi = require('../../api/order') +const cartApi = require('../../api/cart') /** * Purpose: auth supports index.js by holding or executing the auth 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. @@ -26,6 +27,7 @@ const theme = require('../../utils/theme') const { resolveLegacyImage } = require('../../utils/file') const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format') const { runWithLoading } = require('../../utils/loading') +const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery') /** * Purpose: REVIEW_SCORE_OPTIONS supports index.js by holding or executing the review score options page or API role. @@ -137,20 +139,49 @@ function buildPendingReview(review) { return review } +/** + * Purpose: formatImpactTime supports index.js by normalizing backend or order item appointment values for change summaries. + * Usage: call it when building user-visible artist-change cards and confirmation modal copy. + */ +function formatImpactTime(value) { + return formatDateTime(value) +} + /** * Purpose: buildArtistChangeSummary supports index.js by holding or executing the build artist change summary page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ -function buildArtistChangeSummary(request) { +function buildArtistChangeSummary(request, orderItem) { if (!request) { return null } - const originalName = request.originalArtistName || '原美甲师' - const requestedName = request.requestedArtistName || '新美甲师' + const originalName = request.originalArtistName || request.fromArtistName || (orderItem && orderItem.artistName) || '原美甲师' + const requestedName = request.requestedArtistName || request.toArtistName || '新美甲师' + const appointmentTime = formatImpactTime(request.appointmentTime || (orderItem && orderItem.appointmentTime)) + const timeImpactText = request.timeImpactText || (request.timeAffected ? '预约时间可能调整' : '预约时间不变') + const priceImpactText = request.priceImpactText || (request.priceAffected ? '订单价格可能调整' : '价格不变') + const priceValue = request.priceAffected ? request.newPrice : (request.newPrice || request.originalPrice || (orderItem && orderItem.price)) + const priceText = priceValue !== undefined && priceValue !== null && priceValue !== '' ? `¥${formatPrice(priceValue)}` : '' + const impactLines = [ + appointmentTime ? `${timeImpactText}:${appointmentTime}` : timeImpactText, + priceText ? `${priceImpactText}:${priceText}` : priceImpactText + ].filter(Boolean) + const originalArtistText = `原美甲师:${originalName}` + const requestedArtistText = `新美甲师:${requestedName}` return { ...request, + originalArtistText, + requestedArtistText, + artistLines: [originalArtistText, requestedArtistText], displayText: `改派申请:${originalName} → ${requestedName}`, - reasonText: trimText(request.reason) + reasonText: trimText(request.reason), + impactLines, + confirmText: [ + `原美甲师:${originalName}`, + `新美甲师:${requestedName}`, + request.reason ? `原因:${trimText(request.reason)}` : '', + ...impactLines + ].filter(Boolean).join('\n') } } @@ -167,6 +198,77 @@ function indexByOrderItemId(list) { }, {}) } +/** + * Purpose: formatTimelineTime keeps timeline timestamps short enough for mini-program cards. + * Usage: call it while building the order lifecycle timeline from backend date fields. + */ +function formatTimelineTime(value) { + return formatDateTime(value) || '' +} + +/** + * Purpose: latestChangeTime picks the most meaningful time from a change request record. + * Usage: use it when summarizing historical artist-change requests on the timeline. + */ +function latestChangeTime(request) { + return (request && (request.approvedTime || request.rejectedTime || request.reviewTime || request.createTime)) || '' +} + +/** + * Purpose: buildOrderTimeline creates a compact lifecycle timeline for one order. + * Usage: call it after pending reviews, submitted reviews, and change requests are loaded. + */ +function buildOrderTimeline(order, orderReviews, changeRequests, pendingReviews) { + const items = safeList(order && order.items) + const firstAppointment = items.map(item => item && item.appointmentTime).find(Boolean) + const changes = safeList(changeRequests) + const latestChange = changes + .slice() + .sort((left, right) => String(latestChangeTime(right)).localeCompare(String(latestChangeTime(left))))[0] + const submittedReviews = safeList(orderReviews).filter(isSubmittedReview) + const hasPendingReview = safeList(pendingReviews).some(review => sameId(review && review.orderId, order && order.id)) + const status = Number(order && order.status) + return [ + { + key: 'created', + title: '已创建', + text: formatTimelineTime(order && order.createTime) || '已提交', + done: true, + active: false + }, + { + key: 'appointment', + title: '预约时间', + text: formatTimelineTime(firstAppointment) || '待确认', + done: Boolean(firstAppointment), + active: status === 1 + }, + changes.length ? { + key: 'artist-change', + title: '改派记录', + text: `${changes.length} 次申请`, + subText: formatTimelineTime(latestChangeTime(latestChange)), + done: changes.every(request => String((request && request.status) || '').toUpperCase() !== 'PENDING'), + active: changes.some(request => String((request && request.status) || '').toUpperCase() === 'PENDING') + } : null, + { + key: status === 3 ? 'cancelled' : 'completed', + title: status === 3 ? '已取消' : '已完成', + text: formatTimelineTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || (status === 2 ? '服务完成' : (status === 3 ? '订单已取消' : '等待服务')), + done: status === 2 || status === 3, + active: status === 2 || status === 3 + }, + { + key: 'review', + title: '评价', + text: submittedReviews.length ? '已评价' : (hasPendingReview ? '待评价' : '完成后可评价'), + subText: formatTimelineTime((submittedReviews[0] && (submittedReviews[0].reviewTime || submittedReviews[0].submitTime)) || ''), + done: submittedReviews.length > 0, + active: hasPendingReview + } + ].filter(Boolean) +} + /** * Purpose: safeCall supports index.js by holding or executing the safe call page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. @@ -190,10 +292,14 @@ async function loadAssistData(orders) { const orderReviewListsPromise = Promise.all(orders.map(order => ( safeCall(() => orderApi.listOrderReviews(order.id), []) ))) - const [pendingReviews, pendingChanges, orderReviewLists] = await Promise.all([ + const orderChangeListsPromise = Promise.all(orders.map(order => ( + safeCall(() => orderApi.listOrderArtistChangeRequests(order.id), []) + ))) + const [pendingReviews, pendingChanges, orderReviewLists, orderChangeLists] = await Promise.all([ pendingReviewsPromise, pendingChangesPromise, - orderReviewListsPromise + orderReviewListsPromise, + orderChangeListsPromise ]) const submittedReviews = [] @@ -208,7 +314,16 @@ async function loadAssistData(orders) { return { pendingReviewByItemId: indexByOrderItemId(pendingReviews), submittedReviewByItemId: indexByOrderItemId(submittedReviews), - pendingChangeByItemId: indexByOrderItemId(pendingChanges) + pendingChangeByItemId: indexByOrderItemId(pendingChanges), + pendingReviews, + reviewsByOrderId: safeList(orders).reduce((result, order, index) => { + result[toId(order && order.id)] = safeList(orderReviewLists[index]) + return result + }, {}), + changesByOrderId: safeList(orders).reduce((result, order, index) => { + result[toId(order && order.id)] = safeList(orderChangeLists[index]) + return result + }, {}) } } @@ -230,6 +345,20 @@ function findReviewDraft(orders, reviewId) { return {} } +function normalizeRebookQuantity(quantity) { + const value = Number(quantity) + return isFinite(value) && value > 0 ? Math.max(1, Math.floor(value)) : 1 +} + +function getRebookableOrderItems(order) { + return safeList(order && order.items).filter(item => item && item.productId !== undefined && item.productId !== null) +} + +function findOrderById(orders, orderId) { + const orderIdText = toId(orderId) + return safeList(orders).find(order => toId(order.id) === orderIdText) || null +} + Page({ data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), { loading: false, @@ -240,7 +369,8 @@ Page({ * Usage: set it from onLoad route options and compare it while formatting order cards. */ focusOrderId: '', - reviewScoreOptions: REVIEW_SCORE_OPTIONS + reviewScoreOptions: REVIEW_SCORE_OPTIONS, + recoveryState: clearRecoveryState() }), /** @@ -249,7 +379,10 @@ Page({ */ onLoad(options) { this.setData({ - focusOrderId: (options && options.orderId) || '' + focusOrderId: (options && options.orderId) || '', + focusOrderItemId: (options && options.orderItemId) || '', + focusReviewId: (options && options.reviewId) || '', + focusReviewMode: (options && options.review) || '' }) }, @@ -265,13 +398,15 @@ Page({ const isLoggedIn = auth.isLoggedIn() this.setData({ isLoggedIn, - loading: isLoggedIn + loading: isLoggedIn, + recoveryState: clearRecoveryState() }) if (!isLoggedIn) { this.setData({ orders: [], - loading: false + loading: false, + recoveryState: clearRecoveryState() }) return } @@ -280,13 +415,27 @@ Page({ const orders = await orderApi.getOrderList() const list = safeList(orders) const assistData = await loadAssistData(list) + let resolvedFocusOrderId = this.data.focusOrderId + let resolvedFocusOrderItemId = this.data.focusOrderItemId + const targetReviewId = toId(this.data.focusReviewId) + if (!resolvedFocusOrderId && this.data.focusReviewMode === 'pending') { + const firstPending = safeList(assistData.pendingReviews)[0] + resolvedFocusOrderId = toId(firstPending && firstPending.orderId) + resolvedFocusOrderItemId = toId(firstPending && firstPending.orderItemId) + } else if (targetReviewId) { + const submittedReviews = Object.values(assistData.reviewsByOrderId || {}).reduce((all, reviews) => all.concat(safeList(reviews)), []) + const matchedReview = safeList(assistData.pendingReviews).concat(submittedReviews).find(review => sameId(review && review.id, targetReviewId)) + resolvedFocusOrderId = toId(matchedReview && matchedReview.orderId) || resolvedFocusOrderId + resolvedFocusOrderItemId = toId(matchedReview && matchedReview.orderItemId) || resolvedFocusOrderItemId + } const formattedOrders = await Promise.all(list.map(async order => ({ ...order, - focusTarget: sameId(order.id, this.data.focusOrderId), + focusTarget: sameId(order.id, resolvedFocusOrderId), statusText: getOrderStatusText(order), statusClass: getOrderStatusClass(order), shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '', actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`, + timeline: buildOrderTimeline(order, assistData.reviewsByOrderId[toId(order.id)], assistData.changesByOrderId[toId(order.id)], assistData.pendingReviews), items: await Promise.all(safeList(order.items).map(async item => { const itemId = toId(item.id) const inlinePendingReview = resolveRelatedRecord(item.pendingReview || order.pendingReview, item.id) @@ -294,13 +443,14 @@ Page({ const inlinePendingChange = resolveRelatedRecord(item.pendingArtistChangeRequest || order.pendingArtistChangeRequest, item.id) const pendingReview = buildPendingReview(inlinePendingReview || assistData.pendingReviewByItemId[itemId]) const reviewSummary = buildReviewSummary(inlineReviewSummary || assistData.submittedReviewByItemId[itemId]) - const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId]) + const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId], item) return { ...item, productImageUrl: await resolveLegacyImage(item.productImage), priceText: `\u00a5${formatPrice(item.price)}`, appointmentText: formatDateTime(item.appointmentTime), + focusTarget: sameId(order.id, resolvedFocusOrderId) && (!resolvedFocusOrderItemId || sameId(item.id, resolvedFocusOrderItemId)), pendingReview, reviewSummary, reviewDraft: pendingReview ? { rating: 0, content: '' } : null, @@ -309,16 +459,27 @@ Page({ })) }))) + formattedOrders.forEach(order => { + order.canRebook = Number(order.status) === 2 && getRebookableOrderItems(order).length > 0 + }) + this.setData({ - orders: formattedOrders + orders: formattedOrders, + recoveryState: clearRecoveryState() }) } catch (error) { this.setData({ - orders: [] - }) - wx.showToast({ - title: error.message || '\u8ba2\u5355\u5217\u8868\u52a0\u8f7d\u5931\u8d25', - icon: 'none' + orders: [], + recoveryState: buildRecoveryState({ + title: '订单列表加载失败', + message: error, + fallbackMessage: '订单暂时没有加载出来,请重试或稍后再查看。', + actions: [ + { key: 'retryOrdersLoad', text: '重试' }, + { key: 'products', text: '去逛作品' }, + { key: 'profile', text: '返回我的' } + ] + }) }) } finally { this.setData({ @@ -343,6 +504,33 @@ Page({ navigation.goBack('/pages/profile/index') }, + handleRecoveryAction(event) { + const key = event.currentTarget.dataset.key + if (key === 'retryOrdersLoad') { + this.setData({ recoveryState: clearRecoveryState() }) + this.loadOrders() + return + } + + const actions = this.data.recoveryState.actions || [] + const action = actions.find(item => item.key === key) + if (action && action.route) { + this.openRecoveryRoute(action.route) + } + }, + + openRecoveryRoute(route) { + const pureRoute = String(route || '').split('?')[0] + if (!pureRoute) { + return + } + if (navigation.isTabPage(pureRoute)) { + navigation.switchTab(pureRoute) + return + } + navigation.navigate(route) + }, + /** * Purpose: updateReviewDraft supports index.js by holding or executing the update review draft page or API role. * Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow. @@ -437,6 +625,7 @@ Page({ async handleApproveArtistChange(event) { const requestId = event.currentTarget.dataset.requestId + const confirmText = event.currentTarget.dataset.confirmText if (!requestId) { return } @@ -446,7 +635,7 @@ Page({ const confirmed = await new Promise(resolve => { wx.showModal({ title: '同意改派', - content: '确认同意这次美甲师改派申请吗?', + content: confirmText || '确认同意这次美甲师改派申请吗?', success: modalRes => resolve(Boolean(modalRes.confirm)) }) }) @@ -476,6 +665,7 @@ Page({ async handleRejectArtistChange(event) { const requestId = event.currentTarget.dataset.requestId + const confirmText = event.currentTarget.dataset.confirmText if (!requestId) { return } @@ -485,7 +675,7 @@ Page({ const confirmed = await new Promise(resolve => { wx.showModal({ title: '拒绝改派', - content: '确认拒绝这次美甲师改派申请吗?拒绝后可在下一步补充原因。', + content: confirmText ? `${confirmText}\n\n确认拒绝这次改派申请吗?拒绝后可在下一步补充原因。` : '确认拒绝这次美甲师改派申请吗?拒绝后可在下一步补充原因。', confirmText: '拒绝', success: modalRes => resolve(Boolean(modalRes.confirm)) }) @@ -541,6 +731,54 @@ Page({ }) }, + async handleRebookOrder(event) { + const orderId = event.currentTarget.dataset.orderId + const order = findOrderById(this.data.orders, orderId) + if (!order || !order.canRebook) { + wx.showToast({ + title: '这笔订单暂无可复刻作品', + icon: 'none' + }) + return + } + + const items = getRebookableOrderItems(order) + try { + await actionGuard.run(this, `order:rebook:${orderId}`, async () => { + await runWithLoading(async () => { + for (let i = 0; i < items.length; i += 1) { + await cartApi.addToCart({ + productId: items[i].productId, + quantity: normalizeRebookQuantity(items[i].quantity) + }) + } + await getApp().updateCartBadge() + }) + await new Promise(resolve => { + wx.showModal({ + title: '已加入购物车', + content: '请重新选择美甲师和预约时间后再提交订单。', + showCancel: false, + confirmText: '去选择', + success: () => resolve(), + fail: () => resolve() + }) + }) + await navigation.switchTab('/pages/cart/index') + }, { + message: '正在加入购物车,请勿重复点击' + }) + } catch (error) { + if (actionGuard.isGuardError(error)) { + return + } + wx.showToast({ + title: error.message || '复刻同款失败', + icon: 'none' + }) + } + }, + async handleCancelOrder(event) { const orderId = event.currentTarget.dataset.orderId if (!orderId) { diff --git a/WeChatProgram/pages/orders/index.wxml b/WeChatProgram/pages/orders/index.wxml index 5a5cf97f..ad5f0e3e 100644 --- a/WeChatProgram/pages/orders/index.wxml +++ b/WeChatProgram/pages/orders/index.wxml @@ -25,7 +25,20 @@ {{item.shopNameText}} - + + + {{node.title}} + {{node.text}} + {{node.subText}} + + + + {{orderItem.productTitle}} @@ -69,11 +82,20 @@ 待确认改派 - {{orderItem.pendingArtistChangeRequest.displayText}} + {{orderItem.pendingArtistChangeRequest.originalArtistText}} + {{orderItem.pendingArtistChangeRequest.requestedArtistText}} 原因:{{orderItem.pendingArtistChangeRequest.reasonText}} + + {{impactLine}} + - 同意改派 - 拒绝 + 同意改派 + 拒绝 @@ -81,7 +103,10 @@ 总计:{{item.actualAmountText}} - 取消订单 + + 复刻同款 + 取消订单 + @@ -90,6 +115,20 @@ 正在加载订单 + + {{recoveryState.title}} + {{recoveryState.message}} + + {{item.text}} + + + 你还没有订单 先去预约喜欢的款式。 diff --git a/WeChatProgram/pages/orders/index.wxss b/WeChatProgram/pages/orders/index.wxss index f74c203e..6669efff 100644 --- a/WeChatProgram/pages/orders/index.wxss +++ b/WeChatProgram/pages/orders/index.wxss @@ -2,6 +2,53 @@ margin-bottom: 20rpx; } +.recovery-card { + display: flex; + flex-direction: column; + gap: 14rpx; + padding: 26rpx; + border: 2rpx solid var(--theme-border); +} + +.recovery-title { + font-size: 30rpx; + font-weight: 800; + color: #2d2430; +} + +.recovery-desc { + font-size: 24rpx; + line-height: 1.6; + color: #8d7a84; +} + +.recovery-actions { + display: flex; + flex-wrap: wrap; + gap: 14rpx; +} + +.recovery-btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 136rpx; + height: 60rpx; + padding: 0 20rpx; + border-radius: 999rpx; + background: #ffffff; + border: 2rpx solid var(--theme-border); + color: #5d4b55; + font-size: 24rpx; + font-weight: 700; +} + +.recovery-btn.primary { + background: var(--theme-primary); + border-color: var(--theme-primary); + color: #ffffff; +} + .order-card + .order-card { margin-top: 20rpx; } @@ -35,6 +82,51 @@ line-height: 1.5; } +.order-timeline { + display: grid; + grid-template-columns: repeat(5, minmax(0, 1fr)); + gap: 10rpx; + margin-top: 18rpx; +} + +.timeline-node { + min-width: 0; + padding: 12rpx 10rpx; + border-radius: 12rpx; + background: var(--theme-primary-soft); + color: #8d7a84; +} + +.timeline-node.done { + color: var(--theme-primary); +} + +.timeline-node.active { + outline: 2rpx solid var(--theme-primary); +} + +.timeline-title, +.timeline-text, +.timeline-sub { + display: block; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.timeline-title { + font-size: 21rpx; + font-weight: 800; + color: #2d2430; +} + +.timeline-text, +.timeline-sub { + margin-top: 4rpx; + font-size: 20rpx; +} + .order-head-copy { flex: 1; min-width: 0; @@ -87,6 +179,13 @@ margin-top: 22rpx; } +.order-item.focus-target { + padding: 12rpx; + border-radius: 18rpx; + background: rgba(255, 247, 249, 0.9); + outline: 2rpx solid var(--theme-primary); +} + .order-thumb { width: 132rpx; height: 132rpx; @@ -118,13 +217,21 @@ align-items: center; } +.order-actions { + display: flex; + flex-wrap: wrap; + justify-content: flex-end; + gap: 14rpx; +} + .order-amount { font-size: 28rpx; font-weight: 700; color: #2d2430; } -.cancel-btn { +.cancel-btn, +.rebook-btn { display: inline-flex; align-items: center; justify-content: center; @@ -132,12 +239,20 @@ height: 60rpx; padding: 0 18rpx; border-radius: 999rpx; - background: var(--theme-primary-soft); - color: var(--theme-accent); font-size: 24rpx; font-weight: 700; } +.rebook-btn { + background: var(--theme-primary); + color: #ffffff; +} + +.cancel-btn { + background: var(--theme-primary-soft); + color: var(--theme-accent); +} + .review-summary, .review-panel, .change-panel { @@ -182,6 +297,20 @@ line-height: 1.6; } +.impact-list { + display: flex; + flex-direction: column; + gap: 8rpx; + margin-top: 12rpx; +} + +.impact-line { + font-size: 24rpx; + font-weight: 700; + color: var(--theme-primary); + line-height: 1.5; +} + .score-row { display: flex; flex-wrap: wrap; diff --git a/WeChatProgram/pages/product-detail/index.js b/WeChatProgram/pages/product-detail/index.js index 030bd4a1..6555e9eb 100644 --- a/WeChatProgram/pages/product-detail/index.js +++ b/WeChatProgram/pages/product-detail/index.js @@ -52,6 +52,7 @@ const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../u const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config') const { formatPrice, getProductTitle, splitCsv } = require('../../utils/format') const { runWithLoading } = require('../../utils/loading') +const { saveBuyNowContext } = require('../../utils/buy-now') /** * Purpose: parseTimeRange supports index.js by holding or executing the parse time range page or API role. @@ -208,7 +209,9 @@ Page({ ...product, displayTitle: getProductTitle(product), priceText: `¥${formatPrice(product.price)}`, - descriptionText: product.description || '商家还没有补充作品说明。' + descriptionText: product.description || '商家还没有补充作品说明。', + targetAudienceText: product.targetAudience || '', + precautionsText: product.precautions || '' } this.setData({ @@ -303,7 +306,10 @@ Page({ return } - previewImagesSafely(current, this.data.productImages) + previewImagesSafely(current, this.data.productImages, { + failMessage: '图片可能已过期,请重试;仍失败时可以返回作品列表重新进入。', + emptyMessage: '这件作品暂时没有可预览图片,可以返回作品列表查看其他款式。' + }) }, /** @@ -488,6 +494,7 @@ Page({ message: '操作进行中,请勿重复点击' }) await getApp().updateCartBadge() + saveBuyNowContext(product.id) wx.switchTab({ url: '/pages/cart/index' }) diff --git a/WeChatProgram/pages/product-detail/index.wxml b/WeChatProgram/pages/product-detail/index.wxml index 80460e73..4ad2aa84 100644 --- a/WeChatProgram/pages/product-detail/index.wxml +++ b/WeChatProgram/pages/product-detail/index.wxml @@ -79,6 +79,16 @@ 款式说明 {{product.descriptionText}} + + + 适合人群 + {{product.targetAudienceText}} + + + 注意事项 + {{product.precautionsText}} + + diff --git a/WeChatProgram/pages/product-detail/index.wxss b/WeChatProgram/pages/product-detail/index.wxss index fd302048..935f9489 100644 --- a/WeChatProgram/pages/product-detail/index.wxss +++ b/WeChatProgram/pages/product-detail/index.wxss @@ -164,6 +164,19 @@ font-size: 26rpx; line-height: 1.8; color: #5d4b55; + white-space: pre-wrap; +} + +.guidance-grid { + display: grid; + gap: 18rpx; + margin-top: 22rpx; +} + +.guidance-block { + padding: 22rpx; + border-radius: 22rpx; + background: var(--theme-primary-soft); } .comment-card { diff --git a/WeChatProgram/pages/products/index.js b/WeChatProgram/pages/products/index.js index fddb0325..c64012c9 100644 --- a/WeChatProgram/pages/products/index.js +++ b/WeChatProgram/pages/products/index.js @@ -78,6 +78,8 @@ Page({ loading: false, loadingMore: false, categories: [ALL_CATEGORY], + filterGroups: [], + selectedTagId: '', selectedCategory: ALL_CATEGORY, searchKeyword: '', products: [], @@ -197,10 +199,16 @@ Page({ }, async loadTags() { - const tags = await cache.remember('tags:all', CACHE_TTL.tags, () => tagApi.getAllTags()) - const names = Array.isArray(tags) ? tags.map(item => item.tagName).filter(Boolean) : [] + const groups = await cache.remember('tags:filter-options', CACHE_TTL.tags, () => tagApi.getFilterOptions()) + const normalizedGroups = (Array.isArray(groups) ? groups : []).map(group => ({ + ...group, + tags: (Array.isArray(group.tags) ? group.tags : []).map(tag => ({ + ...tag, + idText: String(tag.id) + })) + })) this.setData({ - categories: [ALL_CATEGORY].concat(names) + filterGroups: normalizedGroups }) }, @@ -225,10 +233,13 @@ Page({ async applyFilter(filter) { const keyword = String(filter.keyword || '').trim() const tag = String(filter.tag || '').trim() + const tagId = String(filter.tagId || '').trim() + const matchedTag = this.resolveFilterTag(tagId, tag) this.setData({ searchKeyword: keyword, - selectedCategory: tag && this.data.categories.includes(tag) ? tag : ALL_CATEGORY, + selectedTagId: matchedTag ? String(matchedTag.id) : '', + selectedCategory: matchedTag ? (matchedTag.displayName || matchedTag.tagName) : ALL_CATEGORY, page: 1, total: 0, hasMore: false @@ -246,11 +257,13 @@ Page({ try { const keyword = String(this.data.searchKeyword || '').trim() const tag = this.data.selectedCategory === ALL_CATEGORY ? '' : this.data.selectedCategory + const tagIds = this.data.selectedTagId || '' const result = await productApi.getProductPage({ page: nextPage, size: this.data.pageSize, keyword: keyword || undefined, - tag: tag || undefined + tag: tagIds ? undefined : (tag || undefined), + tagIds: tagIds || undefined }) const cards = await buildProductCards(result && result.list ? result.list : []) const displayCards = await this.attachCartState(cards) @@ -333,6 +346,33 @@ Page({ return chips.join(' \u00b7 ') }, + /** + * Purpose: flattenFilterTags returns all scene-filter tags for query matching. + * Usage: call before applying route or pending filters. + */ + flattenFilterTags() { + return (Array.isArray(this.data.filterGroups) ? this.data.filterGroups : []) + .reduce((list, group) => list.concat(Array.isArray(group.tags) ? group.tags : []), []) + }, + + /** + * Purpose: resolveFilterTag matches route filter text or id to a visible scene tag. + * Usage: call from applyFilter so old tag query links still select the right chip. + */ + resolveFilterTag(tagId, tagName) { + const tags = this.flattenFilterTags() + if (tagId) { + const byId = tags.find(item => String(item.id) === tagId) + if (byId) { + return byId + } + } + if (!tagName) { + return null + } + return tags.find(item => item.tagName === tagName || item.displayName === tagName) || null + }, + /** * `normalizeId` page method. Use this from WXML event bindings or lifecycle hooks. * Call guide: read or update page data with `this.setData(...)` inside the method when state changes. @@ -447,6 +487,7 @@ Page({ await actionGuard.run(this, 'products:search', async () => { this.setData({ selectedCategory: ALL_CATEGORY, + selectedTagId: '', page: 1 }) await runWithLoading(() => this.loadProducts(true)) @@ -466,11 +507,13 @@ Page({ async handleSelectCategory(event) { const category = event.currentTarget.dataset.category + const tagId = event.currentTarget.dataset.tagId ? String(event.currentTarget.dataset.tagId) : '' resetKeyboardSafe(this) try { - await actionGuard.run(this, `products:category:${category}`, async () => { + await actionGuard.run(this, `products:category:${category}:${tagId}`, async () => { this.setData({ selectedCategory: category, + selectedTagId: tagId, searchKeyword: '', page: 1 }) @@ -495,6 +538,7 @@ Page({ await actionGuard.run(this, 'products:reset', async () => { this.setData({ selectedCategory: ALL_CATEGORY, + selectedTagId: '', searchKeyword: '', page: 1 }) diff --git a/WeChatProgram/pages/products/index.wxml b/WeChatProgram/pages/products/index.wxml index 5b55afc1..39a1d8a8 100644 --- a/WeChatProgram/pages/products/index.wxml +++ b/WeChatProgram/pages/products/index.wxml @@ -25,13 +25,26 @@ - {{item}} + 全部 + + + {{group.groupName}} + + {{tag.displayName || tag.tagName}} + diff --git a/WeChatProgram/pages/products/index.wxss b/WeChatProgram/pages/products/index.wxss index c47252f7..96ecace6 100644 --- a/WeChatProgram/pages/products/index.wxss +++ b/WeChatProgram/pages/products/index.wxss @@ -83,6 +83,19 @@ font-weight: 600; } +.filter-group { + display: inline-flex; + align-items: center; + gap: 12rpx; + flex-shrink: 0; +} + +.filter-group-title { + color: #a4939c; + font-size: 22rpx; + font-weight: 700; +} + .category-item.active { background: var(--theme-primary-soft); color: var(--theme-primary); diff --git a/WeChatProgram/pages/profile/index.js b/WeChatProgram/pages/profile/index.js index b8113b6d..b2c72604 100644 --- a/WeChatProgram/pages/profile/index.js +++ b/WeChatProgram/pages/profile/index.js @@ -57,6 +57,7 @@ Page({ needSetPassword: false, userInfo: null, orderCount: 0, + pendingReviewCount: 0, couponCount: 0, wishlistCount: 0, unreadMessageCount: 0, @@ -96,18 +97,20 @@ Page({ } try { - const [userInfo, orders, coupons, wishlist, unreadMessages] = await Promise.all([ + const [userInfo, orders, coupons, wishlist, unreadMessages, pendingReviews] = await Promise.all([ userApi.getUserInfo(), orderApi.getOrderList(), couponApi.listUserCoupons(), wishlistApi.getWishlist(), - userApi.getMyUnreadMessageCount() + userApi.getMyUnreadMessageCount(), + orderApi.listMyPendingReviews().catch(() => []) ]) getApp().refreshUserInfo(userInfo) this.setData({ userInfo, orderCount: Array.isArray(orders) ? orders.length : 0, + pendingReviewCount: Array.isArray(pendingReviews) ? pendingReviews.length : 0, couponCount: Array.isArray(coupons) ? coupons.length : 0, wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0, unreadMessageCount: Number((unreadMessages && unreadMessages.unreadCount) || 0) @@ -160,6 +163,20 @@ Page({ navigation.navigate('/pages/orders/index') }, + /** + * Purpose: handleOpenPendingReviews jumps straight to the order-page pending review focus. + * Usage: bind the pending-review card in profile WXML. + */ + handleOpenPendingReviews() { + if (!navigation.ensureLogin('查看待评价')) { + return + } + navigation.navigate('/pages/orders/index', { + review: 'pending', + source: 'profile' + }) + }, + /** * `handleOpenWishlist` page method. Use this from WXML event bindings or lifecycle hooks. * Call guide: read or update page data with `this.setData(...)` inside the method when state changes. diff --git a/WeChatProgram/pages/profile/index.wxml b/WeChatProgram/pages/profile/index.wxml index 2eb90fa3..6e5b3979 100644 --- a/WeChatProgram/pages/profile/index.wxml +++ b/WeChatProgram/pages/profile/index.wxml @@ -37,6 +37,10 @@ {{couponCount}} + + 待评价 {{pendingReviewCount}} + 给服务过你的美甲师一点反馈 + @@ -57,6 +61,7 @@ 常用入口 我的订单 + 待评价 {{pendingReviewCount}} > diff --git a/WeChatProgram/pages/profile/index.wxss b/WeChatProgram/pages/profile/index.wxss index 585bac87..651fe96b 100644 --- a/WeChatProgram/pages/profile/index.wxss +++ b/WeChatProgram/pages/profile/index.wxss @@ -94,6 +94,23 @@ margin-top: 26rpx; } +.pending-review-card { + display: grid; + gap: 8rpx; + margin-top: 22rpx; + padding: 20rpx 24rpx; + border-radius: 20rpx; + background: var(--theme-primary-soft); + color: #8d7a84; + font-size: 24rpx; +} + +.pending-review-card text:first-child { + color: var(--theme-primary); + font-size: 28rpx; + font-weight: 700; +} + .shop-box { display: flex; align-items: center; diff --git a/WeChatProgram/pages/shop-detail/index.js b/WeChatProgram/pages/shop-detail/index.js index 044b1575..fb89de0e 100644 --- a/WeChatProgram/pages/shop-detail/index.js +++ b/WeChatProgram/pages/shop-detail/index.js @@ -20,6 +20,7 @@ const navigation = require('../../utils/navigation') const theme = require('../../utils/theme') const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file') const { DEFAULT_SHOP_IMAGE } = require('../../utils/config') +const { showRecoveryModal } = require('../../utils/recovery') /** * shop-detail page logic. @@ -38,6 +39,7 @@ Page({ */ managerContact: null, distanceText: '', + trustProfile: null, shopImages: [] }), @@ -78,7 +80,11 @@ Page({ try { const shopInfo = await shopApi.getShopById(this.data.shopId) - const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE) + const trustProfile = await shopApi.getTrustProfile(this.data.shopId).catch(() => null) + const trustImages = trustProfile && Array.isArray(trustProfile.environmentImages) ? trustProfile.environmentImages.filter(Boolean) : [] + const shopImages = trustImages.length + ? trustImages + : await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE) const shopTheme = theme.resolveShopTheme(shopInfo) this.setData(theme.pageThemeData(shopTheme)) if (shopTheme.backgroundImageFileId) { @@ -91,6 +97,7 @@ Page({ } this.setData({ shopInfo, + trustProfile: this.normalizeTrustProfile(trustProfile), shopImages, distanceText: '' }) @@ -106,6 +113,47 @@ Page({ } }, + /** + * Purpose: normalizeTrustProfile prepares backend trust fields for WXML display. + * Usage: call after getTrustProfile so metrics and lists have safe defaults. + */ + normalizeTrustProfile(profile) { + if (!profile) { + return null + } + const stats = profile.stats || {} + return { + ...profile, + ratingText: Number(stats.averageRating || 0) > 0 ? Number(stats.averageRating).toFixed(1) : '暂无', + reviewCount: Number(stats.reviewCount || 0), + productCount: Number(stats.productCount || 0), + availabilityText: profile.availabilitySummary && profile.availabilitySummary.summaryText + ? profile.availabilitySummary.summaryText + : '预约前会再次确认档期', + featuredProducts: (Array.isArray(profile.featuredProducts) ? profile.featuredProducts : []).map(item => ({ + ...item, + priceText: Number(item.price || 0).toFixed(2) + })), + recentReviews: (Array.isArray(profile.recentReviews) ? profile.recentReviews : []).map(item => ({ + ...item, + ratingText: Number(item.ratingScore || 0) > 0 ? Number(item.ratingScore).toFixed(1) : '暂无', + submittedText: item.submittedAt ? String(item.submittedAt).replace('T', ' ').slice(0, 16) : '' + })) + } + }, + + /** + * Purpose: handleOpenProduct navigates from trust-profile cards to product details. + * Usage: bind product cards to this method with data-id. + */ + handleOpenProduct(event) { + const productId = event.currentTarget.dataset.id + if (!productId) { + return + } + navigation.navigate('/pages/product-detail/index', { id: productId }) + }, + /** * `handleBack` page method. Use this from WXML event bindings or lifecycle hooks. * Call guide: read or update page data with `this.setData(...)` inside the method when state changes. @@ -164,9 +212,21 @@ Page({ icon: 'none' }) } catch (error) { - wx.showToast({ - title: error.message || '联系方式获取失败', - icon: 'none' + showRecoveryModal({ + title: '联系方式获取失败', + message: error.message || '暂时没有拿到联系方式,请重试;也可以先复制门店名,稍后从“我的”页联系客服。', + actions: [ + { key: 'retry', text: '重试联系' }, + { key: 'profile', text: '去我的' } + ] + }).then(action => { + if (action && action.key === 'retry') { + this.handleContactManager() + return + } + if (action && action.key === 'profile') { + navigation.switchTab('/pages/profile/index') + } }) } }, diff --git a/WeChatProgram/pages/shop-detail/index.wxml b/WeChatProgram/pages/shop-detail/index.wxml index 5445c24b..3f740ca1 100644 --- a/WeChatProgram/pages/shop-detail/index.wxml +++ b/WeChatProgram/pages/shop-detail/index.wxml @@ -21,10 +21,25 @@ {{shopInfo.address || '门店地址待补充'}} {{distanceText}} + + + {{trustProfile.ratingText}} + {{trustProfile.reviewCount}} 条评价 + + + {{trustProfile.productCount}} + 在售作品 + + + {{trustProfile.businessStatusText || '可浏览'}} + {{trustProfile.availabilityText}} + + + 营业时间 - {{shopInfo.businessHours || '待补充'}} + {{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}} 以到店服务时间为准 @@ -36,7 +51,7 @@ 营业时间 - {{shopInfo.businessHours || '待补充'}} + {{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}} @@ -63,6 +78,52 @@ + + + + 可预约作品 + 先看看本店热门款 + {{trustProfile.availabilityText}} + + + + + + 作 + + {{item.title || '美甲作品'}} + ¥{{item.priceText}} + {{item.bookingHint || '下单前选择美甲师和时间'}} + + + + + + + + + 近期评价 + 真实体验反馈 + + + + + + {{item.productTitle || '订单评价'}} + {{item.ratingText}} + + {{item.content || '用户已完成评价'}} + {{item.submittedText}} + + + + diff --git a/WeChatProgram/pages/shop-detail/index.wxss b/WeChatProgram/pages/shop-detail/index.wxss index adc9ec2a..641646e3 100644 --- a/WeChatProgram/pages/shop-detail/index.wxss +++ b/WeChatProgram/pages/shop-detail/index.wxss @@ -57,6 +57,34 @@ margin-top: 24rpx; } +.trust-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 14rpx; + margin-top: 24rpx; +} + +.trust-card { + display: grid; + gap: 8rpx; + min-height: 112rpx; + padding: 18rpx; + border-radius: 16rpx; + background: var(--theme-primary-soft); +} + +.trust-value { + color: var(--theme-primary); + font-size: 28rpx; + font-weight: 700; +} + +.trust-label { + color: #8d7a84; + font-size: 22rpx; + line-height: 1.35; +} + .shop-summary-value { font-size: 26rpx; line-height: 1.6; @@ -120,6 +148,86 @@ gap: 18rpx; } +.featured-list, +.review-list { + display: grid; + gap: 18rpx; +} + +.featured-card { + display: grid; + grid-template-columns: 150rpx minmax(0, 1fr); + gap: 18rpx; + padding: 18rpx; + border-radius: 24rpx; + background: #fff; +} + +.featured-cover { + width: 150rpx; + height: 150rpx; + border-radius: 20rpx; + background: var(--theme-primary-soft); +} + +.featured-cover.placeholder { + display: flex; + align-items: center; + justify-content: center; + color: var(--theme-primary); + font-size: 40rpx; + font-weight: 700; +} + +.featured-info { + display: grid; + align-content: center; + gap: 10rpx; + min-width: 0; +} + +.featured-title { + color: #2d2430; + font-size: 28rpx; + font-weight: 700; +} + +.featured-price { + color: var(--theme-primary); + font-size: 28rpx; + font-weight: 700; +} + +.featured-hint, +.review-time { + color: #8d7a84; + font-size: 22rpx; + line-height: 1.5; +} + +.review-card { + display: grid; + gap: 12rpx; + padding: 22rpx; + border-radius: 24rpx; + background: #fff; +} + +.review-head { + display: flex; + justify-content: space-between; + gap: 16rpx; + color: #2d2430; + font-size: 26rpx; + font-weight: 700; +} + +.review-content { + color: #5d4b55; + font-size: 25rpx; + line-height: 1.6; +} + .gallery-image { width: calc(50% - 9rpx); height: 240rpx; diff --git a/WeChatProgram/pages/wishlist/index.js b/WeChatProgram/pages/wishlist/index.js index 49ec5316..b818c246 100644 --- a/WeChatProgram/pages/wishlist/index.js +++ b/WeChatProgram/pages/wishlist/index.js @@ -39,7 +39,10 @@ Page({ data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), { loading: false, isLoggedIn: false, - wishlist: [] + wishlist: [], + visibleWishlist: [], + groups: [], + activeGroupId: '' }), /** @@ -65,29 +68,42 @@ Page({ this.cartProductIdSet = new Set() this.setData({ wishlist: [], + visibleWishlist: [], + groups: [], + activeGroupId: '', loading: false }) return } try { - const wishlist = await wishlistApi.getWishlist() + const [wishlist, groups] = await Promise.all([ + wishlistApi.getWishlist(), + wishlistApi.getGroups() + ]) const list = Array.isArray(wishlist) ? wishlist : [] + const groupList = Array.isArray(groups) ? groups : [] const cartProductIdSet = await this.fetchCartProductIdSet() const cards = await Promise.all(list.map(async item => ({ id: item.id, productId: item.productId, + groupId: this.normalizeId(item.groupId), + groupName: item.groupName || '\u6700\u8fd1\u60f3\u505a', + note: item.note || '', productCard: this.markCardInCart( await buildProductCard(item.product || {}), cartProductIdSet ) }))) this.setData({ - wishlist: cards + wishlist: cards, + groups: this.buildGroupTabs(groupList, this.data.activeGroupId), + visibleWishlist: this.filterWishlist(cards, this.data.activeGroupId) }) } catch (error) { this.setData({ - wishlist: [] + wishlist: [], + visibleWishlist: [] }) wx.showToast({ title: error.message || '\u6536\u85cf\u5217\u8868\u52a0\u8f7d\u5931\u8d25', @@ -108,6 +124,36 @@ Page({ return value === undefined || value === null ? '' : String(value) }, + filterWishlist(list, groupId) { + const normalizedGroupId = this.normalizeId(groupId) + if (!normalizedGroupId) { + return list + } + return list.filter(item => this.normalizeId(item && item.groupId) === normalizedGroupId) + }, + + buildGroupTabs(groups, activeGroupId) { + const normalizedActiveGroupId = this.normalizeId(activeGroupId) + return (Array.isArray(groups) ? groups : []).map(group => { + const id = this.normalizeId(group && group.id) + return { + id, + name: group.name, + itemCount: group.itemCount || 0, + active: id === normalizedActiveGroupId + } + }) + }, + + handleGroupSelect(event) { + const groupId = this.normalizeId(event.currentTarget.dataset.groupId) + this.setData({ + activeGroupId: groupId, + groups: this.buildGroupTabs(this.data.groups, groupId), + visibleWishlist: this.filterWishlist(this.data.wishlist, groupId) + }) + }, + async fetchCartProductIdSet() { try { const cartList = await cartApi.getCartList() @@ -152,18 +198,20 @@ Page({ this.cartProductIdSet = this.cartProductIdSet || new Set() this.cartProductIdSet.add(normalizedId) - this.setData({ - wishlist: this.data.wishlist.map(item => ( - this.normalizeId(item && item.productId) === normalizedId - ? { - ...item, - productCard: { - ...item.productCard, - inCart: true - } + const nextWishlist = this.data.wishlist.map(item => ( + this.normalizeId(item && item.productId) === normalizedId + ? { + ...item, + productCard: { + ...item.productCard, + inCart: true } - : item - )) + } + : item + )) + this.setData({ + wishlist: nextWishlist, + visibleWishlist: this.filterWishlist(nextWishlist, this.data.activeGroupId) }) }, diff --git a/WeChatProgram/pages/wishlist/index.wxml b/WeChatProgram/pages/wishlist/index.wxml index 6a93580a..065e6601 100644 --- a/WeChatProgram/pages/wishlist/index.wxml +++ b/WeChatProgram/pages/wishlist/index.wxml @@ -15,7 +15,22 @@ 喜欢的款式先收藏。 - + + 全部 + {{item.name}} + + + + + {{item.groupName || '最近想做'}} + {{item.note}} + 取消收藏 + + + 当前分组还没有作品 + diff --git a/WeChatProgram/pages/wishlist/index.wxss b/WeChatProgram/pages/wishlist/index.wxss index 43a030e9..2c9821bb 100644 --- a/WeChatProgram/pages/wishlist/index.wxss +++ b/WeChatProgram/pages/wishlist/index.wxss @@ -6,6 +6,58 @@ margin-top: 22rpx; } +.wishlist-groups { + display: block; + white-space: nowrap; + margin-bottom: 20rpx; +} + +.wishlist-group-chip { + display: inline-flex; + align-items: center; + justify-content: center; + height: 58rpx; + min-width: 92rpx; + margin-right: 14rpx; + padding: 0 24rpx; + border: 2rpx solid var(--theme-border); + border-radius: 16rpx; + background: var(--theme-card-bg); + color: var(--text-secondary); + font-size: 24rpx; + white-space: nowrap; +} + +.wishlist-group-chip--active { + border-color: var(--theme-primary); + background: var(--theme-primary-soft); + color: var(--theme-primary); + font-weight: 600; +} + +.wishlist-meta { + display: flex; + flex-direction: column; + gap: 8rpx; + margin-top: 12rpx; +} + +.wishlist-group-name { + align-self: flex-start; + padding: 4rpx 16rpx; + border-radius: 14rpx; + background: var(--theme-primary-soft); + color: var(--theme-accent); + font-size: 22rpx; +} + +.wishlist-note { + color: var(--text-secondary); + font-size: 24rpx; + line-height: 34rpx; + word-break: break-word; +} + .wishlist-actions { display: flex; gap: 16rpx; diff --git a/WeChatProgram/utils/buy-now.js b/WeChatProgram/utils/buy-now.js new file mode 100644 index 00000000..989c9f03 --- /dev/null +++ b/WeChatProgram/utils/buy-now.js @@ -0,0 +1,49 @@ +const STORAGE_KEY = 'YUMI_BUY_NOW_CONTEXT' + +function createBuyNowContext(productId) { + return { + mode: 'buyNow', + productId: String(productId || ''), + createdAt: Date.now() + } +} + +function saveBuyNowContext(productId) { + const context = createBuyNowContext(productId) + wx.setStorageSync(STORAGE_KEY, context) + return context +} + +function readBuyNowContext(maxAgeMs = 5 * 60 * 1000) { + const context = wx.getStorageSync(STORAGE_KEY) + if (!context || context.mode !== 'buyNow' || !context.productId) { + return null + } + if (Date.now() - Number(context.createdAt || 0) > maxAgeMs) { + return null + } + return context +} + +function clearBuyNowContext() { + wx.removeStorageSync(STORAGE_KEY) +} + +function consumeBuyNowContext(maxAgeMs = 5 * 60 * 1000) { + const context = readBuyNowContext(maxAgeMs) + clearBuyNowContext() + return context +} + +function isBuyNowCartItem(item, productId) { + return Boolean(productId) && String(item && item.productId || '') === String(productId) +} + +module.exports = { + STORAGE_KEY, + clearBuyNowContext, + consumeBuyNowContext, + isBuyNowCartItem, + readBuyNowContext, + saveBuyNowContext +} diff --git a/WeChatProgram/utils/file.js b/WeChatProgram/utils/file.js index de70a239..263efdbe 100644 --- a/WeChatProgram/utils/file.js +++ b/WeChatProgram/utils/file.js @@ -6,6 +6,17 @@ const fileApi = require('../api/file') const { DEFAULT_PRODUCT_IMAGE } = require('./config') const { CACHE_TTL } = require('./config') const { splitCsv } = require('./format') +const { showRecoveryModal } = require('./recovery') + +function handlePreviewRecoveryAction(action) { + if (!action || action.key !== 'products') { + return + } + wx.switchTab({ + url: '/pages/products/index', + fail() {} + }) +} /** * Purpose: urlCache supports file.js by holding or executing the url cache page or API role. @@ -91,24 +102,45 @@ async function resolveLegacyImage(value, fallbackImage) { * Purpose: previewImagesSafely opens wx.previewImage with a user-facing fallback when signed URLs expire or preview fails. * Usage: pass the current image URL and full URL list from image tap handlers instead of calling wx.previewImage directly. */ -function previewImagesSafely(current, urls) { +function previewImagesSafely(current, urls, options) { + const config = options || {} const list = (Array.isArray(urls) ? urls : [current]).filter(Boolean) if (!current || !list.length) { - wx.showToast({ + return showRecoveryModal({ title: '图片暂不可预览', - icon: 'none' + message: config.emptyMessage || '没有可预览的图片,请返回作品列表查看其他款式。', + actions: [ + { key: 'dismiss', text: '知道了' }, + { key: 'products', text: '看作品' } + ] + }).then(action => { + handlePreviewRecoveryAction(action) + return action }) - return } - wx.previewImage({ - current, - urls: list, - fail: () => { - wx.showToast({ - title: '图片预览失败,请稍后重试', - icon: 'none' - }) - } + return new Promise(resolve => { + wx.previewImage({ + current, + urls: list, + success: () => resolve(null), + fail: () => { + showRecoveryModal({ + title: '图片预览失败', + message: config.failMessage || '图片链接可能已过期,请重试;仍失败时可以返回作品列表重新进入。', + actions: [ + { key: 'retry', text: '重试' }, + { key: 'products', text: '看作品' } + ] + }).then(action => { + if (action && action.key === 'retry') { + previewImagesSafely(current, list, config).then(resolve) + return + } + handlePreviewRecoveryAction(action) + resolve(action) + }) + } + }) }) } diff --git a/WeChatProgram/utils/recovery.js b/WeChatProgram/utils/recovery.js new file mode 100644 index 00000000..29b7e055 --- /dev/null +++ b/WeChatProgram/utils/recovery.js @@ -0,0 +1,78 @@ +const DEFAULT_ROUTES = { + cart: '/pages/cart/index', + orders: '/pages/orders/index', + products: '/pages/products/index', + profile: '/pages/profile/index' +} + +function normalizeRecoveryMessage(error, fallbackMessage) { + if (typeof error === 'string' && error.trim()) { + return error.trim() + } + if (error && error.message) { + return String(error.message).trim() + } + return fallbackMessage || '操作失败,请稍后重试' +} + +function normalizeRecoveryActions(actions) { + return (Array.isArray(actions) ? actions : []) + .filter(action => action && action.key && action.text) + .map((action, index) => ({ + key: action.key, + text: action.text, + route: action.route || DEFAULT_ROUTES[action.key] || '', + primary: action.primary !== undefined ? Boolean(action.primary) : index === 0 + })) +} + +function buildRecoveryState(options) { + const config = options || {} + return { + visible: true, + title: config.title || '操作失败', + message: normalizeRecoveryMessage(config.message || config.error, config.fallbackMessage), + actions: normalizeRecoveryActions(config.actions) + } +} + +function clearRecoveryState() { + return { + visible: false, + title: '', + message: '', + actions: [] + } +} + +function showRecoveryModal(options) { + const state = buildRecoveryState(options) + const primaryAction = state.actions.find(action => action.primary) || state.actions[0] + const secondaryAction = state.actions.find(action => action !== primaryAction) + + return new Promise(resolve => { + wx.showModal({ + title: state.title, + content: state.message, + confirmText: primaryAction ? primaryAction.text : '知道了', + cancelText: secondaryAction ? secondaryAction.text : '取消', + showCancel: Boolean(secondaryAction), + success: result => { + if (result.confirm) { + resolve(primaryAction || null) + return + } + resolve(secondaryAction || null) + }, + fail: () => resolve(null) + }) + }) +} + +module.exports = { + DEFAULT_ROUTES, + normalizeRecoveryMessage, + buildRecoveryState, + clearRecoveryState, + showRecoveryModal +} diff --git a/WeChatProgram/utils/recovery.test.js b/WeChatProgram/utils/recovery.test.js new file mode 100644 index 00000000..47424ddb --- /dev/null +++ b/WeChatProgram/utils/recovery.test.js @@ -0,0 +1,30 @@ +const assert = require('assert') + +const recovery = require('./recovery') + +const checkoutState = recovery.buildRecoveryState({ + title: '下单失败', + message: new Error('库存不足'), + fallbackMessage: '订单创建失败', + actions: [ + { key: 'retry', text: '重试下单' }, + { key: 'orders', text: '查看订单' }, + { key: 'contact', text: '联系客服' }, + { key: 'cart', text: '返回购物车' } + ] +}) + +assert.strictEqual(checkoutState.visible, true) +assert.strictEqual(checkoutState.title, '下单失败') +assert.strictEqual(checkoutState.message, '库存不足') +assert.strictEqual(checkoutState.actions.length, 4) +assert.strictEqual(checkoutState.actions[0].key, 'retry') +assert.strictEqual(checkoutState.actions[0].primary, true) +assert.strictEqual(checkoutState.actions[3].route, '/pages/cart/index') + +const emptyState = recovery.clearRecoveryState() +assert.strictEqual(emptyState.visible, false) +assert.deepStrictEqual(emptyState.actions, []) + +const normalized = recovery.normalizeRecoveryMessage(null, '图片预览失败') +assert.strictEqual(normalized, '图片预览失败') diff --git a/WeChatProgram/utils/request.js b/WeChatProgram/utils/request.js index 83787e28..200aa38a 100644 --- a/WeChatProgram/utils/request.js +++ b/WeChatProgram/utils/request.js @@ -96,10 +96,14 @@ function isWhitelistedPath(url) { '/product/get/', '/product/list/', '/comment/list/product/', + '/nail-artist/profile/', + '/nail-artist/', '/shop/get/', + '/shop/trust-profile/', '/shop/list/public', '/shop/list/simple', '/tag/list/all', + '/tag/list/filter-options', '/file/get-signed-url/' ].some(path => String(url || '').includes(path)) } diff --git a/YumiNail-Admin-Program/pages/product-form/index.js b/YumiNail-Admin-Program/pages/product-form/index.js index a53a8305..fecb4f4e 100644 --- a/YumiNail-Admin-Program/pages/product-form/index.js +++ b/YumiNail-Admin-Program/pages/product-form/index.js @@ -155,6 +155,16 @@ Page({ * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ description: '', + /** + * Purpose: targetAudience records who or which scene this product is suitable for. + * Usage: edit it in the product form and submit it with create/update payloads. + */ + targetAudience: '', + /** + * Purpose: precautions records service reminders for this product. + * Usage: edit it in the product form and submit it with create/update payloads. + */ + precautions: '', /** * Purpose: price supports index.js by holding or executing the price page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. @@ -230,6 +240,16 @@ Page({ * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ description: currentProduct.description || '', + /** + * Purpose: targetAudience restores the existing product suitable-audience text in edit mode. + * Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it. + */ + targetAudience: currentProduct.targetAudience || '', + /** + * Purpose: precautions restores the existing product reminder text in edit mode. + * Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it. + */ + precautions: currentProduct.precautions || '', /** * Purpose: price supports index.js by holding or executing the price page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. @@ -700,6 +720,16 @@ Page({ * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ description: this.data.form.description || undefined, + /** + * Purpose: targetAudience sends the optional suitable-audience text to the backend. + * Usage: leave it undefined when empty so old products can hide the section on user detail pages. + */ + targetAudience: this.data.form.targetAudience || undefined, + /** + * Purpose: precautions sends the optional reminder text to the backend. + * Usage: leave it undefined when empty so old products can hide the section on user detail pages. + */ + precautions: this.data.form.precautions || undefined, /** * Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. diff --git a/YumiNail-Admin-Program/pages/product-form/index.wxml b/YumiNail-Admin-Program/pages/product-form/index.wxml index 147b1644..6c3c526c 100644 --- a/YumiNail-Admin-Program/pages/product-form/index.wxml +++ b/YumiNail-Admin-Program/pages/product-form/index.wxml @@ -26,6 +26,14 @@ 作品描述 + + 适合人群 + + + + 注意事项 + + 点赞数量