Files
JayuCloud/FingertipManager-Program/pages/customers/index.js
T

45 lines
1.3 KiB
JavaScript

const customersApi = require('../../api/customers')
Page({
data: {
keyword: '',
customers: []
},
onLoad() {
this.loadCustomers()
},
onSearchInput(event) {
this.setData({ keyword: event.detail.value })
clearTimeout(this._timer)
this._timer = setTimeout(() => this.loadCustomers(), 300)
},
async loadCustomers() {
const fallback = [
{ id: 1, name: '王女士', phone: '138****1201', lastTime: '2026-06-01' },
{ id: 2, name: '陈女士', phone: '136****8842', lastTime: '2026-05-29' },
{ id: 3, name: '林女士', phone: '159****6671', lastTime: '2026-05-27' }
]
try {
const data = await customersApi.list({ keyword: this.data.keyword, page: 1, size: 30 })
const list = data.list || data || []
this.setData({
customers: list.map(item => ({
id: item.id,
name: item.nickname || item.name || item.account || '客户',
phone: item.contactPhone || item.phone || '未填写',
lastTime: item.lastOrderTime || item.lastConsumeTime || '-'
}))
})
} catch (error) {
this.setData({ customers: fallback })
}
},
openDetail(event) {
wx.navigateTo({ url: `/pages/customer-detail/index?id=${event.currentTarget.dataset.id}` })
}
})