feat: present miniapp order details with formatted amounts
This commit is contained in:
@@ -2,6 +2,7 @@ const { getGoodsOrderDetail, cancelGoodsOrder } = require('../../api/orderApi')
|
||||
const { getExpressOrderDetail, cancelExpressOrder, completeExpressOrder } = require('../../api/expressApi')
|
||||
const { getGroupBuyOrderDetail, cancelGroupBuyOrder } = require('../../api/groupBuyApi')
|
||||
const { statusText } = require('../../utils/request')
|
||||
const { toOrderDetail } = require('../../utils/orderPresenter')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -23,7 +24,7 @@ Page({
|
||||
group: getGroupBuyOrderDetail
|
||||
}
|
||||
loaders[this.type](this.id)
|
||||
.then((order) => this.setData({ order }))
|
||||
.then((order) => this.setData({ order: toOrderDetail(this.type, order) }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<view class="page" wx:if="{{order}}">
|
||||
<view class="card">
|
||||
<view class="section-title">{{order.orderNo}}</view>
|
||||
<view class="tag">{{order.status}}</view>
|
||||
<view class="tag">{{order.statusText}}</view>
|
||||
<view class="muted">类型:{{type}}</view>
|
||||
</view>
|
||||
<view class="card">
|
||||
<view wx:if="{{type === 'goods'}}">
|
||||
<view>商品金额:¥{{order.totalAmountCent / 100}}</view>
|
||||
<view>配送费:¥{{order.deliveryFeeCent / 100}}</view>
|
||||
<view class="price">应收:¥{{order.payableAmountCent / 100}}</view>
|
||||
<view>商品金额:{{order.totalAmountText}}</view>
|
||||
<view>配送费:{{order.deliveryFeeText}}</view>
|
||||
<view class="price">应收:{{order.payableAmountText}}</view>
|
||||
<view class="muted">{{order.deliveryMethod}}</view>
|
||||
</view>
|
||||
<view wx:if="{{type === 'express'}}">
|
||||
<view>{{order.expressCompany}} / {{order.pickupCode}}</view>
|
||||
<view class="muted">{{order.pickupAddress}}</view>
|
||||
<view class="price">服务费:¥{{order.feeCent / 100}}</view>
|
||||
<view class="price">服务费:{{order.feeText}}</view>
|
||||
</view>
|
||||
<view wx:if="{{type === 'group'}}">
|
||||
<view>{{order.groupBuyTitle}}</view>
|
||||
<view>数量:{{order.quantity}}</view>
|
||||
<view class="price">金额:¥{{order.amountCent / 100}}</view>
|
||||
<view class="price">金额:{{order.amountText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="button-row">
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user