重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
const orderApi = require('../../api/order')
|
||||
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 : []
|
||||
}
|
||||
|
||||
async function formatOrder(order) {
|
||||
return {
|
||||
...order,
|
||||
statusText: getOrderStatusText(order),
|
||||
statusClass: getOrderStatusClass(order),
|
||||
amountText: `¥${formatPrice(order && order.actualAmount)}`,
|
||||
items: await Promise.all(safeList(order && order.items).map(async item => ({
|
||||
...item,
|
||||
productImageUrl: await resolveLegacyImage(item.productImage),
|
||||
priceText: `¥${formatPrice(item.price)}`,
|
||||
appointmentText: formatDateTime(item.appointmentTime)
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
orders: [],
|
||||
focusOrderId: ''
|
||||
}),
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
focusOrderId: (options && options.orderId) || ''
|
||||
})
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/profile/index')
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({ isLoggedIn })
|
||||
if (!isLoggedIn) {
|
||||
navigation.openAuth(navigation.getCurrentPageUrl())
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const list = safeList(await orderApi.getArtistOrders())
|
||||
const orders = await Promise.all(list.map(formatOrder))
|
||||
this.setData({ orders })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '美甲师订单加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
openCalendar() {
|
||||
navigation.navigate('/pages/artist-calendar/index')
|
||||
},
|
||||
|
||||
async completeOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
if (!orderId) return
|
||||
const confirmed = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '完成服务',
|
||||
content: '确认这笔订单已经完成服务吗?',
|
||||
success: res => resolve(Boolean(res.confirm))
|
||||
})
|
||||
})
|
||||
if (!confirmed) return
|
||||
try {
|
||||
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
|
||||
wx.showToast({ title: '服务已完成', icon: 'none' })
|
||||
await this.loadOrders()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '完成订单失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<navigation-bar title="美甲师订�? showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
|
||||
|
||||
<view class="page-shell" style="{{themeVars}}">
|
||||
<view class="page-content">
|
||||
<view class="page-hero">
|
||||
<text class="hero-kicker">服务订单</text>
|
||||
<text class="hero-title">{{orders.length}} 笔相关订�?/text>
|
||||
<text class="hero-desc">查看客户预约、项目和服务完成状����?/text>
|
||||
<view class="hero-action-row">
|
||||
<view class="hero-action secondary" bindtap="openCalendar">预约日历</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loading}}" class="page-card empty-card">
|
||||
<text class="empty-title">正在加载订单</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{orders.length}}">
|
||||
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card {{item.id == focusOrderId ? 'focus-target' : ''}}">
|
||||
<view class="order-head">
|
||||
<view>
|
||||
<text class="order-no">{{item.orderNo}}</text>
|
||||
<text class="order-line">{{item.customerNickname || '客户'}} {{item.customerPhoneMasked || ''}}</text>
|
||||
</view>
|
||||
<text class="chip">{{item.statusText}}</text>
|
||||
</view>
|
||||
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="item-row">
|
||||
<image class="item-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill"></image>
|
||||
<view class="item-main">
|
||||
<text class="item-title">{{orderItem.productTitle}}</text>
|
||||
<text class="item-line">{{orderItem.priceText}} x {{orderItem.quantity}}</text>
|
||||
<text wx:if="{{orderItem.appointmentText}}" class="item-line">预约:{{orderItem.appointmentText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="order-foot">
|
||||
<text class="order-amount">{{item.amountText}}</text>
|
||||
<view wx:if="{{item.status == 1}}" class="ghost-btn" data-order-id="{{item.id}}" bindtap="completeOrder">完成服务</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">暂无相关订单</text>
|
||||
<text class="empty-desc">有客户预约你服务的项目后会出现在这里�?/text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,70 @@
|
||||
.order-card {
|
||||
margin-top: 22rpx;
|
||||
padding: 26rpx;
|
||||
}
|
||||
|
||||
.order-card.focus-target {
|
||||
border-color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.order-head,
|
||||
.order-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
}
|
||||
|
||||
.order-no,
|
||||
.order-line,
|
||||
.order-amount {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.order-line {
|
||||
margin-top: 8rpx;
|
||||
color: #504444;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.item-thumb {
|
||||
width: 116rpx;
|
||||
height: 116rpx;
|
||||
border-radius: 22rpx;
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
display: block;
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.order-foot {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.order-amount {
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
Reference in New Issue
Block a user