重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,151 @@
const orderApi = require('../../api/order')
const afterSaleApi = require('../../api/after-sale')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function safeList(value) {
return Array.isArray(value) ? value : []
}
function sameId(left, right) {
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
}
function formatMoney(value) {
return `¥${formatPrice(value)}`
}
function buildTimeline(order, reviews, changes, afterSales) {
const items = safeList(order && order.items)
const firstAppointment = items.map(item => item && item.appointmentTime).find(Boolean)
const status = Number(order && order.status)
return [
{ key: 'created', title: '已创建', text: formatDateTime(order && order.createTime) || '已提交', done: true, active: false },
{ key: 'appointment', title: '预约时间', text: formatDateTime(firstAppointment) || '待确认', done: Boolean(firstAppointment), active: status === 1 },
{ key: 'service', title: status === 3 ? '已取消' : '服务完成', text: formatDateTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || '等待服务', done: status === 2 || status === 3, active: status === 2 || status === 3 },
{ key: 'change', title: '改派记录', text: changes.length ? `${changes.length} 条记录` : '暂无改派', done: changes.length > 0, active: changes.some(item => String(item.status || '').toUpperCase() === 'PENDING') },
{ key: 'after-sale', title: '售后/评价', text: afterSales.length ? `${afterSales.length} 条售后` : (reviews.length ? `${reviews.length} 条评价` : '暂无记录'), done: afterSales.length > 0 || reviews.length > 0, active: afterSales.some(item => String(item.status || '').toUpperCase() === 'PENDING') }
]
}
async function formatOrder(order, reviews, changes, afterSales) {
const items = await Promise.all(safeList(order && order.items).map(async item => ({
...item,
productImageUrl: await resolveLegacyImage(item.productImage),
priceText: formatMoney(item.price),
appointmentText: formatDateTime(item.appointmentTime)
})))
return {
...order,
items,
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
amountText: formatMoney(order && (order.actualAmount || order.totalAmount)),
canApplyAfterSale: Number(order && order.status) === 2 || String(order && order.paymentStatus || '').toUpperCase() === 'PAID',
timeline: buildTimeline(order, reviews, changes, afterSales)
}
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
id: '',
loading: false,
order: null,
reviews: [],
changes: [],
afterSales: [],
contact: null,
isLoggedIn: false
}),
onLoad(options) {
this.setData({
id: (options && (options.id || options.orderId)) || ''
})
},
onShow() {
this.loadOrder()
},
handleBack() {
navigation.goBack('/pages/orders/index')
},
async loadOrder() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
if (!this.data.id) {
return
}
this.setData({ loading: true })
try {
const [order, reviews, changes, afterSalePage, contact] = await Promise.all([
orderApi.getOrderDetail(this.data.id),
orderApi.listOrderReviews(this.data.id).catch(() => []),
orderApi.listOrderArtistChangeRequests(this.data.id).catch(() => []),
afterSaleApi.getMyAfterSales({ page: 1, size: 50 }).catch(() => ({ list: [] })),
userApi.getOrderArtistContact(this.data.id).catch(() => null)
])
const afterSales = safeList(afterSalePage && afterSalePage.list).filter(item => sameId(item.orderId, this.data.id))
this.setData({
order: await formatOrder(order, reviews || [], changes || [], afterSales),
reviews: reviews || [],
changes: changes || [],
afterSales,
contact
})
} catch (error) {
wx.showToast({
title: error.message || '订单详情加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
openProgress() {
navigation.navigate('/pages/service-progress/index', { orderId: this.data.id })
},
openAfterSaleApply(event) {
const orderItemId = event.currentTarget.dataset.itemId || ''
navigation.navigate('/pages/after-sale-apply/index', {
orderId: this.data.id,
orderItemId
})
},
openAfterSales() {
navigation.navigate('/pages/after-sales/index', { orderId: this.data.id })
},
async handleCancelOrder() {
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '取消订单',
content: '确认取消这笔订单吗?',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) return
try {
await runWithLoading(() => orderApi.cancelOrder(this.data.id))
wx.showToast({ title: '订单已取消', icon: 'none' })
await this.loadOrder()
} catch (error) {
wx.showToast({ title: error.message || '取消订单失败', icon: 'none' })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,71 @@
<navigation-bar title="订单详情" showBack="{{true}}" fallbackPath="/pages/orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell detail-page" style="{{themeVars}}">
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看订�?/text>
<text class="empty-desc">订单详情霢�要先登录�?/text>
</view>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载订单</text>
</view>
<block wx:elif="{{order}}">
<view class="page-hero">
<text class="hero-kicker">预约订单</text>
<text class="hero-title">{{order.orderNo}}</text>
<text class="hero-desc">{{order.shopName || '当前门店'}} · {{order.statusText}}</text>
<view class="summary-strip">
<view class="summary-metric">
<text class="summary-label">订单金额</text>
<text class="summary-value">{{order.amountText}}</text>
</view>
<view class="summary-metric">
<text class="summary-label">项目�?/text>
<text class="summary-value">{{order.items.length}}</text>
</view>
</view>
</view>
<view class="page-card timeline-card">
<view wx:for="{{order.timeline}}" wx:key="key" class="timeline-node {{item.done ? 'done' : ''}} {{item.active ? 'active' : ''}}">
<text class="timeline-title">{{item.title}}</text>
<text class="timeline-text">{{item.text}}</text>
</view>
</view>
<view class="page-card detail-card">
<view wx:for="{{order.items}}" wx:key="id" class="item-row">
<image class="item-thumb" src="{{item.productImageUrl}}" mode="aspectFill"></image>
<view class="item-main">
<text class="item-title">{{item.productTitle}}</text>
<text class="item-line">{{item.priceText}} x {{item.quantity}}</text>
<text wx:if="{{item.artistName}}" class="item-line">美甲师:{{item.artistName}}</text>
<text wx:if="{{item.appointmentText}}" class="item-line">预约:{{item.appointmentText}}</text>
<view wx:if="{{order.canApplyAfterSale}}" class="soft-chip" data-item-id="{{item.id}}" bindtap="openAfterSaleApply">申请售后</view>
</view>
</view>
</view>
<view wx:if="{{contact}}" class="page-card contact-card">
<text class="section-title">联系信息</text>
<text class="contact-line">{{contact.contactName || contact.roleLabel || '服务联系�?}}</text>
<text wx:if="{{contact.phoneAvailable && contact.phone}}" class="contact-line">电话:{{contact.phone}}</text>
<text wx:if="{{contact.wechatAvailable && contact.wechatId}}" class="contact-line">微信:{{contact.wechatId}}</text>
<text wx:if="{{contact.platformContactText}}" class="contact-line">{{contact.platformContactText}}</text>
</view>
<view class="action-row">
<view class="secondary-btn" bindtap="openProgress">服务进度</view>
<view class="secondary-btn" bindtap="openAfterSales">售后记录</view>
<view wx:if="{{order.status == 1}}" class="secondary-btn danger" bindtap="handleCancelOrder">取消订单</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">未找到订�?/text>
<text class="empty-desc">请从订单中心重新进入�?/text>
</view>
</view>
</view>
@@ -0,0 +1,103 @@
.timeline-card,
.detail-card,
.contact-card {
margin-top: 22rpx;
padding: 24rpx;
}
.timeline-card {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8rpx;
}
.timeline-node {
min-width: 0;
padding: 12rpx 8rpx;
border-radius: 14rpx;
background: var(--theme-primary-soft);
color: #504444;
}
.timeline-node.done,
.timeline-node.active {
color: var(--theme-primary);
}
.timeline-title,
.timeline-text,
.contact-line {
display: block;
}
.timeline-title,
.timeline-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.timeline-title {
font-size: 21rpx;
font-weight: 800;
}
.timeline-text {
margin-top: 6rpx;
font-size: 20rpx;
}
.item-row {
display: flex;
gap: 18rpx;
padding: 20rpx 0;
border-top: 2rpx solid var(--theme-border);
}
.item-row:first-child {
padding-top: 0;
border-top: 0;
}
.item-thumb {
width: 132rpx;
height: 132rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
}
.item-main {
flex: 1;
min-width: 0;
}
.item-title {
display: block;
color: var(--text-primary);
font-size: 29rpx;
font-weight: 800;
line-height: 1.45;
}
.item-line,
.contact-line {
display: block;
margin-top: 10rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.soft-chip {
margin-top: 16rpx;
}
.action-row {
display: grid;
gap: 16rpx;
margin-top: 24rpx;
}
.secondary-btn.danger {
color: var(--theme-accent);
}