调整周视图和客户页展示样式
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({
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
<view class="page">
|
||||
<view class="customer-toolbar">
|
||||
<view class="search-card card">
|
||||
<input value="{{keyword}}" bindinput="onSearchInput" placeholder="搜索客户姓名或手机号" />
|
||||
<view class="page customer-page">
|
||||
<view class="customer-header">
|
||||
<text class="customer-title">客户</text>
|
||||
<button class="compact-btn customer-edit-btn" bindtap="addCustomer">编辑</button>
|
||||
</view>
|
||||
|
||||
<view class="search-card card">
|
||||
<text class="search-icon">⌕</text>
|
||||
<input value="{{keyword}}" bindinput="onSearchInput" placeholder="搜索客户姓名或手机号" />
|
||||
</view>
|
||||
|
||||
<view class="customer-stats card">
|
||||
<view class="customer-stat">
|
||||
<text class="customer-stat-value">{{customerStats.todayArrival}}</text>
|
||||
<text class="customer-stat-label">今日到店</text>
|
||||
</view>
|
||||
<view class="customer-stat">
|
||||
<text class="customer-stat-value">¥{{customerStats.monthAmount}}</text>
|
||||
<text class="customer-stat-label">本月消费</text>
|
||||
</view>
|
||||
<view class="customer-stat">
|
||||
<text class="customer-stat-value">{{customerStats.memberCount}}</text>
|
||||
<text class="customer-stat-label">会员人数</text>
|
||||
</view>
|
||||
<button class="compact-btn add-customer-btn" bindtap="addCustomer">+</button>
|
||||
</view>
|
||||
|
||||
<view class="list section">
|
||||
@@ -13,16 +31,20 @@
|
||||
</view>
|
||||
<view wx:elif="{{customers.length === 0}}" class="empty card">暂无客户</view>
|
||||
<view wx:for="{{customers}}" wx:key="id" class="card list-card customer-card" data-id="{{item.id}}" bindtap="openDetail">
|
||||
<view class="customer-identity">
|
||||
<view class="customer-avatar">{{item.shortName}}</view>
|
||||
<view class="customer-copy">
|
||||
<view class="customer-name-row">
|
||||
<text class="name">{{item.name}}</text>
|
||||
<text class="customer-status">已建档</text>
|
||||
</view>
|
||||
<text class="meta">{{item.phone}}</text>
|
||||
<text class="meta">最近消费 {{item.lastTime}}</text>
|
||||
<view class="customer-avatar-wrap">
|
||||
<image class="customer-avatar-image" src="{{item.avatar}}" mode="aspectFill"></image>
|
||||
<view class="customer-online-dot"></view>
|
||||
</view>
|
||||
<view class="customer-copy">
|
||||
<view class="customer-name-row">
|
||||
<text class="name">{{item.name}}</text>
|
||||
<text class="customer-status">{{item.tagText}}</text>
|
||||
</view>
|
||||
<view class="customer-detail-row">
|
||||
<text class="meta-label">最近消费</text>
|
||||
<text class="amount">¥{{item.amountText}}</text>
|
||||
</view>
|
||||
<text class="meta">最近到店 {{item.lastDateText}}</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
@@ -32,7 +54,7 @@
|
||||
<view class="customer-modal" catchtap="stopTap">
|
||||
<view class="modal-head">
|
||||
<text class="modal-title">新增客户</text>
|
||||
<view class="modal-close" bindtap="closeCreateModal">×</view>
|
||||
<view class="modal-close" bindtap="closeCreateModal"></view>
|
||||
</view>
|
||||
<view class="form-grid">
|
||||
<view class="modal-field">
|
||||
|
||||
@@ -1,75 +1,130 @@
|
||||
.customer-toolbar {
|
||||
.customer-page {
|
||||
padding-top: 30rpx;
|
||||
}
|
||||
|
||||
.customer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
margin-bottom: 8rpx;
|
||||
justify-content: space-between;
|
||||
margin: 0 4rpx 26rpx;
|
||||
}
|
||||
|
||||
.customer-title {
|
||||
color: #302a25;
|
||||
font-size: 42rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.customer-edit-btn {
|
||||
width: 112rpx;
|
||||
min-width: 112rpx;
|
||||
max-width: 112rpx;
|
||||
height: 58rpx;
|
||||
font-size: 23rpx;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
flex: 1;
|
||||
padding: 0 24rpx;
|
||||
height: 84rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-color: rgba(111, 143, 131, 0.12);
|
||||
background: rgba(255, 255, 255, 0.82);
|
||||
gap: 12rpx;
|
||||
width: 100%;
|
||||
height: 82rpx;
|
||||
padding: 0 24rpx;
|
||||
border-color: rgba(111, 143, 131, 0.1);
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
box-shadow: 0 8rpx 22rpx rgba(78, 96, 78, 0.05);
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
color: #a49b91;
|
||||
font-size: 42rpx;
|
||||
line-height: 1;
|
||||
transform: rotate(-18deg);
|
||||
}
|
||||
|
||||
.search-card input {
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.add-customer-btn {
|
||||
width: 84rpx;
|
||||
min-width: 84rpx;
|
||||
max-width: 84rpx;
|
||||
height: 84rpx;
|
||||
min-height: 84rpx;
|
||||
padding: 0;
|
||||
border-radius: 50%;
|
||||
background: #6f8f83;
|
||||
color: #fffdf8;
|
||||
font-size: 42rpx;
|
||||
font-weight: 400;
|
||||
line-height: 84rpx;
|
||||
box-shadow: 0 10rpx 22rpx rgba(111, 143, 131, 0.2);
|
||||
.customer-stats {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
margin-top: 22rpx;
|
||||
padding: 22rpx 0;
|
||||
border-color: rgba(111, 143, 131, 0.08);
|
||||
background: rgba(255, 255, 255, 0.72);
|
||||
}
|
||||
|
||||
.customer-stat {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
border-right: 1rpx solid #eee8df;
|
||||
}
|
||||
|
||||
.customer-stat:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.customer-stat-value {
|
||||
color: #3d594e;
|
||||
font-size: 30rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.customer-stat-label {
|
||||
color: #9c948b;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin-top: 28rpx;
|
||||
}
|
||||
|
||||
.customer-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 22rpx 20rpx;
|
||||
border-color: rgba(111, 143, 131, 0.1);
|
||||
background: rgba(255, 255, 255, 0.86);
|
||||
gap: 18rpx;
|
||||
min-height: 132rpx;
|
||||
padding: 20rpx;
|
||||
border-color: rgba(111, 143, 131, 0.08);
|
||||
background: rgba(255, 255, 255, 0.84);
|
||||
box-shadow: 0 8rpx 20rpx rgba(78, 96, 78, 0.045);
|
||||
}
|
||||
|
||||
.customer-identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
gap: 18rpx;
|
||||
.customer-avatar-wrap {
|
||||
position: relative;
|
||||
flex: 0 0 auto;
|
||||
width: 84rpx;
|
||||
height: 84rpx;
|
||||
}
|
||||
|
||||
.customer-avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: 76rpx;
|
||||
height: 76rpx;
|
||||
border: 4rpx solid #f4faf2;
|
||||
.customer-avatar-image {
|
||||
display: block;
|
||||
width: 84rpx;
|
||||
height: 84rpx;
|
||||
border: 4rpx solid #f5faf3;
|
||||
border-radius: 50%;
|
||||
background: #dcece0;
|
||||
color: #4f8068;
|
||||
font-size: 30rpx;
|
||||
font-weight: 900;
|
||||
background: #e3eee2;
|
||||
}
|
||||
|
||||
.customer-online-dot {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 2rpx;
|
||||
width: 16rpx;
|
||||
height: 16rpx;
|
||||
border: 3rpx solid #fffdf8;
|
||||
border-radius: 50%;
|
||||
background: #85b58a;
|
||||
}
|
||||
|
||||
.customer-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -77,40 +132,60 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.name {
|
||||
overflow: hidden;
|
||||
color: #292520;
|
||||
font-size: 29rpx;
|
||||
font-weight: 800;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.customer-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex: 0 0 auto;
|
||||
min-height: 32rpx;
|
||||
padding: 0 10rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #eff7ef;
|
||||
color: #6a9876;
|
||||
background: #fff0df;
|
||||
color: #bd7a4d;
|
||||
font-size: 18rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.name,
|
||||
.customer-detail-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12rpx;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.meta-label,
|
||||
.meta {
|
||||
color: #9b938a;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.amount {
|
||||
color: #557c69;
|
||||
font-size: 25rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.meta {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.name {
|
||||
color: #292520;
|
||||
font-size: 29rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.meta {
|
||||
margin-top: 8rpx;
|
||||
color: #928a81;
|
||||
font-size: 24rpx;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
flex: 0 0 auto;
|
||||
color: #b0a79e;
|
||||
font-size: 48rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
@@ -163,19 +238,16 @@
|
||||
border: 1rpx solid #e4d8ca;
|
||||
border-radius: 50%;
|
||||
background: #fffaf4;
|
||||
color: transparent;
|
||||
font-size: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.modal-close::before,
|
||||
.modal-close::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 22rpx;
|
||||
height: 3rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #61554c;
|
||||
content: "";
|
||||
}
|
||||
|
||||
.modal-close::before {
|
||||
|
||||
Reference in New Issue
Block a user