feat: present miniapp order details with formatted amounts

This commit is contained in:
王鹏
2026-07-07 17:58:06 +08:00
parent 18bd5497cd
commit 47f4a24760
4 changed files with 45 additions and 10 deletions

View File

@@ -38,6 +38,23 @@ function toOrderCards({ goodsOrders = [], expressOrders = [], groupBuyOrders = [
return orders
}
module.exports = {
toOrderCards
function toOrderDetail(type, order) {
const detail = Object.assign({}, order, {
statusText: statusText(order && order.status)
})
if (type === 'goods') {
detail.totalAmountText = '¥' + yuan(order.totalAmountCent)
detail.deliveryFeeText = '¥' + yuan(order.deliveryFeeCent)
detail.payableAmountText = '¥' + yuan(order.payableAmountCent)
} else if (type === 'express') {
detail.feeText = '¥' + yuan(order.feeCent)
} else if (type === 'group') {
detail.amountText = '¥' + yuan(order.amountCent)
}
return detail
}
module.exports = {
toOrderCards,
toOrderDetail
}

View File

@@ -1,4 +1,4 @@
const { toOrderCards } = require('./orderPresenter')
const { toOrderCards, toOrderDetail } = require('./orderPresenter')
describe('toOrderCards', () => {
test('normalizes mixed orders for list display', () => {
@@ -14,4 +14,21 @@ describe('toOrderCards', () => {
expect.objectContaining({ id: 3, type: 'group', title: 'Today eggs', amountText: '¥59.80', statusText: '待确认' })
])
})
test('normalizes an order detail for display', () => {
expect(toOrderDetail('goods', {
id: 1,
orderNo: 'GO00000001',
totalAmountCent: 1290,
deliveryFeeCent: 300,
payableAmountCent: 1590,
status: 'PENDING_DELIVERY'
})).toEqual(expect.objectContaining({
orderNo: 'GO00000001',
statusText: '待配送',
totalAmountText: '¥12.90',
deliveryFeeText: '¥3.00',
payableAmountText: '¥15.90'
}))
})
})