feat: present miniapp orders with formatted status
This commit is contained in:
@@ -2,6 +2,7 @@ const { listGoodsOrders } = require('../../api/orderApi')
|
||||
const { listExpressOrders } = require('../../api/expressApi')
|
||||
const { listGroupBuyOrders } = require('../../api/groupBuyApi')
|
||||
const { statusText } = require('../../utils/request')
|
||||
const { toOrderCards } = require('../../utils/orderPresenter')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -25,35 +26,7 @@ Page({
|
||||
listGroupBuyOrders().catch(() => [])
|
||||
])
|
||||
.then(([goodsOrders, expressOrders, groupBuyOrders]) => {
|
||||
const orders = []
|
||||
;(goodsOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'goods',
|
||||
typeText: '商品订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.orderNo,
|
||||
amountCent: item.payableAmountCent,
|
||||
status: item.status
|
||||
}))
|
||||
;(expressOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'express',
|
||||
typeText: '快递代取',
|
||||
orderNo: item.orderNo,
|
||||
title: item.expressCompany + ' ' + item.pickupCode,
|
||||
amountCent: item.feeCent,
|
||||
status: item.status
|
||||
}))
|
||||
;(groupBuyOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'group',
|
||||
typeText: '团购订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.groupBuyTitle,
|
||||
amountCent: item.amountCent,
|
||||
status: item.status
|
||||
}))
|
||||
this.setData({ orders })
|
||||
this.setData({ orders: toOrderCards({ goodsOrders, expressOrders, groupBuyOrders }) })
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<view>{{item.title}}</view>
|
||||
<view class="muted">{{item.typeText}} {{item.orderNo}}</view>
|
||||
</view>
|
||||
<view class="tag">{{item.status}}</view>
|
||||
<view class="tag">{{item.statusText}}</view>
|
||||
</view>
|
||||
<view class="row between">
|
||||
<view class="muted">状态:{{item.status}}</view>
|
||||
<view class="price">¥{{item.amountCent / 100}}</view>
|
||||
<view class="muted">状态:{{item.statusText}}</view>
|
||||
<view class="price">{{item.amountText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{!orders.length && !loading}}" class="card muted">暂无订单</view>
|
||||
|
||||
43
miniapp/miniprogram/utils/orderPresenter.js
Normal file
43
miniapp/miniprogram/utils/orderPresenter.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { statusText, yuan } = require('./request')
|
||||
|
||||
function toOrderCards({ goodsOrders = [], expressOrders = [], groupBuyOrders = [] }) {
|
||||
const orders = []
|
||||
;(goodsOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'goods',
|
||||
typeText: '商品订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.orderNo,
|
||||
amountCent: item.payableAmountCent,
|
||||
amountText: '¥' + yuan(item.payableAmountCent),
|
||||
status: item.status,
|
||||
statusText: statusText(item.status)
|
||||
}))
|
||||
;(expressOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'express',
|
||||
typeText: '快递代取',
|
||||
orderNo: item.orderNo,
|
||||
title: item.expressCompany + ' ' + item.pickupCode,
|
||||
amountCent: item.feeCent,
|
||||
amountText: '¥' + yuan(item.feeCent),
|
||||
status: item.status,
|
||||
statusText: statusText(item.status)
|
||||
}))
|
||||
;(groupBuyOrders || []).forEach((item) => orders.push({
|
||||
id: item.id,
|
||||
type: 'group',
|
||||
typeText: '团购订单',
|
||||
orderNo: item.orderNo,
|
||||
title: item.groupBuyTitle,
|
||||
amountCent: item.amountCent,
|
||||
amountText: '¥' + yuan(item.amountCent),
|
||||
status: item.status,
|
||||
statusText: statusText(item.status)
|
||||
}))
|
||||
return orders
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toOrderCards
|
||||
}
|
||||
17
miniapp/miniprogram/utils/orderPresenter.test.js
Normal file
17
miniapp/miniprogram/utils/orderPresenter.test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const { toOrderCards } = require('./orderPresenter')
|
||||
|
||||
describe('toOrderCards', () => {
|
||||
test('normalizes mixed orders for list display', () => {
|
||||
const cards = toOrderCards({
|
||||
goodsOrders: [{ id: 1, orderNo: 'GO00000001', payableAmountCent: 1590, status: 'PENDING_DELIVERY' }],
|
||||
expressOrders: [{ id: 2, orderNo: 'EO00000001', expressCompany: 'SF', pickupCode: 'A1', feeCent: 400, status: 'PENDING_PICKUP' }],
|
||||
groupBuyOrders: [{ id: 3, orderNo: 'GB00000001', groupBuyTitle: 'Today eggs', amountCent: 5980, status: 'PENDING_CONFIRM' }]
|
||||
})
|
||||
|
||||
expect(cards).toEqual([
|
||||
expect.objectContaining({ id: 1, type: 'goods', title: 'GO00000001', amountText: '¥15.90', statusText: '待配送' }),
|
||||
expect.objectContaining({ id: 2, type: 'express', title: 'SF A1', amountText: '¥4.00', statusText: '待自提' }),
|
||||
expect.objectContaining({ id: 3, type: 'group', title: 'Today eggs', amountText: '¥59.80', statusText: '待确认' })
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user