功能:新增微信小程序界面
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
orders: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({
|
||||
isLoggedIn,
|
||||
loading: isLoggedIn
|
||||
})
|
||||
|
||||
if (!isLoggedIn) {
|
||||
this.setData({
|
||||
orders: [],
|
||||
loading: false
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const orders = await orderApi.getOrderList()
|
||||
const list = Array.isArray(orders) ? orders : []
|
||||
const formattedOrders = await Promise.all(list.map(async order => ({
|
||||
...order,
|
||||
statusText: getOrderStatusText(order),
|
||||
statusClass: getOrderStatusClass(order),
|
||||
actualAmountText: `¥${formatPrice(order.actualAmount)}`,
|
||||
items: await Promise.all((order.items || []).map(async item => ({
|
||||
...item,
|
||||
productImageUrl: await resolveLegacyImage(item.productImage),
|
||||
priceText: `¥${formatPrice(item.price)}`,
|
||||
appointmentText: formatDateTime(item.appointmentTime)
|
||||
})))
|
||||
})))
|
||||
|
||||
this.setData({
|
||||
orders: formattedOrders
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
orders: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '订单列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/orders/index')
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/profile/index')
|
||||
},
|
||||
|
||||
async handleCancelOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
if (!orderId) {
|
||||
return
|
||||
}
|
||||
|
||||
const result = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '取消订单',
|
||||
content: '确认取消这笔订单吗?',
|
||||
success: modalRes => resolve(Boolean(modalRes.confirm))
|
||||
})
|
||||
})
|
||||
|
||||
if (!result) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => orderApi.cancelOrder(orderId))
|
||||
wx.showToast({
|
||||
title: '订单已取消',
|
||||
icon: 'none'
|
||||
})
|
||||
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,53 @@
|
||||
<navigation-bar title="我的订单" color="#2d2430" background="#fff7f8" bindback="handleBack"></navigation-bar>
|
||||
|
||||
<view class="page-shell orders-page">
|
||||
<view class="page-content">
|
||||
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
|
||||
<text class="empty-title">登录后查看订单</text>
|
||||
<text class="empty-desc">预约状态、取消进度和服务记录都会展示在这里。</text>
|
||||
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
|
||||
</view>
|
||||
|
||||
<block wx:elif="{{orders.length}}">
|
||||
<view class="page-hero orders-hero">
|
||||
<text class="hero-kicker">预约记录</text>
|
||||
<text class="hero-title">共 {{orders.length}} 笔订单</text>
|
||||
<text class="hero-desc">这里展示每笔订单的状态、项目、预约时间以及取消入口。</text>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card">
|
||||
<view class="order-head">
|
||||
<view class="order-head-copy">
|
||||
<text class="order-label">订单号</text>
|
||||
<text class="order-no">{{item.orderNo}}</text>
|
||||
</view>
|
||||
<text class="order-status {{item.statusClass}}">{{item.statusText}}</text>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item">
|
||||
<image class="order-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill"></image>
|
||||
<view class="order-main">
|
||||
<view class="order-title">{{orderItem.productTitle}}</view>
|
||||
<view class="order-line">{{orderItem.priceText}} x {{orderItem.quantity}}</view>
|
||||
<view wx:if="{{orderItem.artistName}}" class="order-line">美甲师:{{orderItem.artistName}}</view>
|
||||
<view wx:if="{{orderItem.appointmentText}}" class="order-line">预约时间:{{orderItem.appointmentText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="order-foot">
|
||||
<text class="order-amount">总计:{{item.actualAmountText}}</text>
|
||||
<view wx:if="{{item.status == 1}}" class="cancel-btn" data-order-id="{{item.id}}" bindtap="handleCancelOrder">取消订单</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:elif="{{loading}}" class="page-card empty-card">
|
||||
<text class="empty-title">正在加载订单</text>
|
||||
</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,126 @@
|
||||
.orders-hero {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.order-card + .order-card {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
padding: 26rpx;
|
||||
}
|
||||
|
||||
.order-head,
|
||||
.order-foot {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
}
|
||||
|
||||
.order-head {
|
||||
padding-bottom: 18rpx;
|
||||
border-bottom: 2rpx solid #f3e7eb;
|
||||
}
|
||||
|
||||
.order-head-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.order-label {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
display: block;
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
color: #5d4b55;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 120rpx;
|
||||
height: 48rpx;
|
||||
padding: 0 16rpx;
|
||||
border-radius: 999rpx;
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.order-status.pending {
|
||||
background: #fff6e8;
|
||||
color: #cb7b00;
|
||||
}
|
||||
|
||||
.order-status.completed {
|
||||
background: #ecfbf3;
|
||||
color: #2ea36f;
|
||||
}
|
||||
|
||||
.order-status.cancelled {
|
||||
background: #fff1f5;
|
||||
color: #d5536f;
|
||||
}
|
||||
|
||||
.order-item {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.order-thumb {
|
||||
width: 132rpx;
|
||||
height: 132rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #f6edf1;
|
||||
}
|
||||
|
||||
.order-main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.order-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #2d2430;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.order-line {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: #8d7a84;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.order-foot {
|
||||
margin-top: 24rpx;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-amount {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 144rpx;
|
||||
height: 60rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #fff1f5;
|
||||
color: #d5536f;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
Reference in New Issue
Block a user