2026-06-22 22:18:08 +08:00
|
|
|
// 模拟客户数据
|
|
|
|
|
const mockCustomers = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
name: '张三',
|
|
|
|
|
phone: '13800138001',
|
|
|
|
|
province: '广东省',
|
|
|
|
|
city: '深圳市',
|
|
|
|
|
district: '南山区',
|
|
|
|
|
address: '科技园路1号',
|
|
|
|
|
email: 'zhangsan@example.com',
|
|
|
|
|
customer_type: 'VIP',
|
|
|
|
|
create_time: '2025-01-15 10:30:00'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: '李四',
|
|
|
|
|
phone: '13800138002',
|
|
|
|
|
province: '浙江省',
|
|
|
|
|
city: '杭州市',
|
|
|
|
|
district: '西湖区',
|
|
|
|
|
address: '文三路100号',
|
|
|
|
|
email: 'lisi@example.com',
|
|
|
|
|
customer_type: 'Normal',
|
|
|
|
|
create_time: '2025-02-20 14:20:00'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
name: '王五',
|
|
|
|
|
phone: '13800138003',
|
|
|
|
|
province: '四川省',
|
|
|
|
|
city: '成都市',
|
|
|
|
|
district: '武侯区',
|
|
|
|
|
address: '天府大道200号',
|
|
|
|
|
email: 'wangwu@example.com',
|
|
|
|
|
customer_type: 'VIP',
|
|
|
|
|
create_time: '2025-03-10 09:15:00'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 4,
|
|
|
|
|
name: '赵六',
|
|
|
|
|
phone: '13800138004',
|
|
|
|
|
province: '湖南省',
|
|
|
|
|
city: '长沙市',
|
|
|
|
|
district: '岳麓区',
|
|
|
|
|
address: '麓山南路100号',
|
|
|
|
|
email: 'zhaoliu@example.com',
|
|
|
|
|
customer_type: 'Normal',
|
|
|
|
|
create_time: '2025-04-05 16:45:00'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
// 模拟网络延迟
|
|
|
|
|
const delay = (ms = 300) => new Promise(r => setTimeout(r, ms))
|
|
|
|
|
|
|
|
|
|
// Mock API
|
|
|
|
|
export const mockCustomerAPI = {
|
|
|
|
|
// 获取列表
|
|
|
|
|
async getList(params = {}) {
|
|
|
|
|
await delay()
|
|
|
|
|
let result = [...mockCustomers]
|
|
|
|
|
|
|
|
|
|
// 关键词搜索
|
|
|
|
|
if (params.keyword) {
|
|
|
|
|
const keyword = params.keyword.toLowerCase()
|
|
|
|
|
const searchField = params.searchField || '1'
|
|
|
|
|
|
|
|
|
|
if (searchField === '2') {
|
|
|
|
|
// 编号:精确匹配
|
|
|
|
|
result = result.filter(item => String(item.id) === keyword)
|
|
|
|
|
} else if (searchField === '1') {
|
|
|
|
|
// 姓名:模糊匹配
|
|
|
|
|
result = result.filter(item => item.name.includes(keyword))
|
|
|
|
|
} else if (searchField === '3') {
|
|
|
|
|
// 电话:模糊匹配
|
|
|
|
|
result = result.filter(item => item.phone.includes(keyword))
|
|
|
|
|
} else if (searchField === '4') {
|
|
|
|
|
// 邮箱:模糊匹配
|
|
|
|
|
result = result.filter(item => item.email.includes(keyword))
|
|
|
|
|
} else {
|
|
|
|
|
// 默认:模糊匹配所有字段
|
|
|
|
|
result = result.filter(item =>
|
|
|
|
|
String(item.id).includes(keyword) ||
|
|
|
|
|
item.name.includes(keyword) ||
|
|
|
|
|
item.phone.includes(keyword) ||
|
|
|
|
|
item.email.includes(keyword)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 客户类型筛选
|
|
|
|
|
if (params.customer_type) {
|
|
|
|
|
result = result.filter(item => item.customer_type === params.customer_type)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-24 16:42:13 +08:00
|
|
|
// 地区筛选(省/市/区)
|
|
|
|
|
if (params.province) {
|
|
|
|
|
result = result.filter(item => item.province === params.province)
|
|
|
|
|
}
|
|
|
|
|
if (params.city) {
|
|
|
|
|
result = result.filter(item => item.city === params.city)
|
|
|
|
|
}
|
|
|
|
|
if (params.district) {
|
|
|
|
|
result = result.filter(item => item.district === params.district)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-22 22:18:08 +08:00
|
|
|
return { code: 200, data: result, total: result.length }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取详情
|
|
|
|
|
async getDetail(id) {
|
|
|
|
|
await delay()
|
|
|
|
|
const customer = mockCustomers.find(item => item.id === id)
|
|
|
|
|
if (customer) {
|
|
|
|
|
return { code: 200, data: customer }
|
|
|
|
|
}
|
|
|
|
|
return { code: 404, message: '客户不存在' }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 新增
|
|
|
|
|
async create(data) {
|
|
|
|
|
await delay()
|
|
|
|
|
// 生成自增 ID
|
|
|
|
|
const maxId = mockCustomers.length > 0 ? Math.max(...mockCustomers.map(item => item.id)) : 0
|
|
|
|
|
const newCustomer = {
|
|
|
|
|
id: maxId + 1,
|
|
|
|
|
...data,
|
|
|
|
|
create_time: new Date().toISOString().replace('T', ' ').slice(0, 19)
|
|
|
|
|
}
|
|
|
|
|
mockCustomers.push(newCustomer)
|
|
|
|
|
return { code: 200, data: newCustomer, message: '新增成功' }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
|
async update(id, data) {
|
|
|
|
|
await delay()
|
|
|
|
|
const index = mockCustomers.findIndex(item => item.id === id)
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
mockCustomers[index] = { ...mockCustomers[index], ...data }
|
|
|
|
|
return { code: 200, data: mockCustomers[index], message: '更新成功' }
|
|
|
|
|
}
|
|
|
|
|
return { code: 404, message: '客户不存在' }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
async delete(id) {
|
|
|
|
|
await delay()
|
|
|
|
|
const index = mockCustomers.findIndex(item => item.id === id)
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
mockCustomers.splice(index, 1)
|
|
|
|
|
return { code: 200, message: '删除成功' }
|
|
|
|
|
}
|
|
|
|
|
return { code: 404, message: '客户不存在' }
|
|
|
|
|
}
|
|
|
|
|
}
|