调整周视图和客户页展示样式
This commit is contained in:
@@ -1,9 +1,76 @@
|
||||
const customersApi = require('../../api/customers')
|
||||
|
||||
const DEFAULT_CUSTOMER_AVATARS = [
|
||||
'/assets/images/default-avatar-1.png',
|
||||
'/assets/images/default-avatar-2.png',
|
||||
'/assets/images/default-avatar-3.png',
|
||||
'/assets/images/default-avatar-4.png'
|
||||
]
|
||||
|
||||
function formatCustomerAmount(value) {
|
||||
const amount = Number(value || 0)
|
||||
return Number.isFinite(amount) ? amount.toFixed(2) : '0.00'
|
||||
}
|
||||
|
||||
function formatCustomerDate(value) {
|
||||
if (!value) {
|
||||
return '-'
|
||||
}
|
||||
return String(value).replace('T', ' ').slice(0, 10)
|
||||
}
|
||||
|
||||
function resolveCustomerAmount(item) {
|
||||
return item.lastOrderAmount
|
||||
|| item.lastConsumeAmount
|
||||
|| item.totalAmount
|
||||
|| item.amount
|
||||
|| 0
|
||||
}
|
||||
|
||||
function resolveCustomerMonthAmount(item) {
|
||||
return item.monthAmount
|
||||
|| item.monthConsumeAmount
|
||||
|| item.monthConsumption
|
||||
|| item.totalAmount
|
||||
|| 0
|
||||
}
|
||||
|
||||
function resolveCustomerTag(item) {
|
||||
return item.memberLevelName
|
||||
|| item.levelName
|
||||
|| item.tagName
|
||||
|| (item.member ? '会员' : '普通客户')
|
||||
}
|
||||
|
||||
function isToday(value) {
|
||||
if (!value) {
|
||||
return false
|
||||
}
|
||||
return formatCustomerDate(value) === new Date().toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
function mapCustomer(item, index) {
|
||||
const name = item.nickname || item.name || item.account || '客户'
|
||||
return {
|
||||
id: item.id,
|
||||
name,
|
||||
avatar: item.avatar || item.avatarUrl || item.customerAvatar || DEFAULT_CUSTOMER_AVATARS[index % DEFAULT_CUSTOMER_AVATARS.length],
|
||||
tagText: resolveCustomerTag(item),
|
||||
amountText: formatCustomerAmount(resolveCustomerAmount(item)),
|
||||
lastDateText: formatCustomerDate(item.lastOrderTime || item.lastConsumeTime),
|
||||
arrivedToday: isToday(item.lastOrderTime || item.lastConsumeTime)
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
customers: [],
|
||||
customerStats: {
|
||||
todayArrival: 0,
|
||||
monthAmount: '0.00',
|
||||
memberCount: 0
|
||||
},
|
||||
loadError: '',
|
||||
createModalVisible: false,
|
||||
creating: false,
|
||||
@@ -27,15 +94,16 @@ Page({
|
||||
try {
|
||||
const data = await customersApi.list({ keyword: this.data.keyword, page: 1, size: 30 })
|
||||
const list = data.list || data || []
|
||||
const customers = list.map(mapCustomer)
|
||||
const monthAmount = list.reduce((total, item) => total + Number(resolveCustomerMonthAmount(item) || 0), 0)
|
||||
this.setData({
|
||||
loadError: '',
|
||||
customers: list.map(item => ({
|
||||
id: item.id,
|
||||
name: item.nickname || item.name || item.account || '客户',
|
||||
shortName: (item.nickname || item.name || item.account || '客户').slice(-1),
|
||||
phone: item.contactPhone || item.phone || '未填写',
|
||||
lastTime: item.lastOrderTime || item.lastConsumeTime || '-'
|
||||
}))
|
||||
customers,
|
||||
customerStats: {
|
||||
todayArrival: customers.filter(item => item.arrivedToday).length,
|
||||
monthAmount: formatCustomerAmount(monthAmount),
|
||||
memberCount: list.filter(item => item.member || item.memberLevelName || item.levelName).length
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
|
||||
Reference in New Issue
Block a user