61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
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
|
|
}
|
|
|
|
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
|
|
}
|