c6206787da
项目结构: - backend/ Python FastAPI 后端 - uni-app/ uni-app跨端前端 - docs/ 设计文档 - docker-compose.yml Docker编排 - nginx/scripts/systemd 运维配置 已完成功能: - 用户认证 (JWT) - 智能翻译 + 回复建议 - 营销素材生成 - 客户管理 + 沉默检测 - 报价单管理 - 产品库管理 - 汇率换算 - 推送通知 (uni-push) - WhatsApp Webhook框架 - Celery定时任务
121 lines
2.8 KiB
JavaScript
121 lines
2.8 KiB
JavaScript
const { customerApi } = require('../../utils/api');
|
|
|
|
Page({
|
|
data: {
|
|
customers: [],
|
|
page: 1,
|
|
hasMore: true,
|
|
loading: false,
|
|
showAddModal: false,
|
|
newCustomer: {
|
|
name: '',
|
|
company: '',
|
|
country: '',
|
|
phone: '',
|
|
whatsapp_id: '',
|
|
email: '',
|
|
},
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadCustomers();
|
|
},
|
|
|
|
onReachBottom() {
|
|
if (this.data.hasMore && !this.data.loading) {
|
|
this.setData({ page: this.data.page + 1 });
|
|
this.loadCustomers(true);
|
|
}
|
|
},
|
|
|
|
async loadCustomers(isAppend = false) {
|
|
if (this.data.loading) return;
|
|
|
|
this.setData({ loading: true });
|
|
try {
|
|
const result = await customerApi.list(this.data.page);
|
|
this.setData({
|
|
customers: isAppend ? [...this.data.customers, ...result.items] : result.items,
|
|
hasMore: result.items.length >= result.size,
|
|
loading: false,
|
|
});
|
|
} catch (err) {
|
|
wx.showToast({ title: err.message || '加载失败', icon: 'none' });
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
|
|
showAdd() {
|
|
this.setData({ showAddModal: true });
|
|
},
|
|
|
|
hideAdd() {
|
|
this.setData({ showAddModal: false });
|
|
},
|
|
|
|
onInput(e) {
|
|
const field = e.currentTarget.dataset.field;
|
|
const value = e.detail.value;
|
|
this.setData({
|
|
[`newCustomer.${field}`]: value,
|
|
});
|
|
},
|
|
|
|
async addCustomer() {
|
|
const { newCustomer } = this.data;
|
|
if (!newCustomer.name) {
|
|
wx.showToast({ title: '请输入客户名称', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await customerApi.create(newCustomer);
|
|
wx.showToast({ title: '添加成功', icon: 'success' });
|
|
this.hideAdd();
|
|
this.setData({ page: 1, customers: [] });
|
|
this.loadCustomers();
|
|
} catch (err) {
|
|
wx.showToast({ title: err.message || '添加失败', icon: 'none' });
|
|
}
|
|
},
|
|
|
|
async deleteCustomer(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
wx.showModal({
|
|
title: '确认删除',
|
|
content: '确定要删除该客户吗?',
|
|
success: async (res) => {
|
|
if (res.confirm) {
|
|
try {
|
|
await customerApi.delete(id);
|
|
wx.showToast({ title: '已删除', icon: 'success' });
|
|
this.setData({ page: 1, customers: [] });
|
|
this.loadCustomers();
|
|
} catch (err) {
|
|
wx.showToast({ title: '删除失败', icon: 'none' });
|
|
}
|
|
}
|
|
},
|
|
});
|
|
},
|
|
|
|
viewDetail(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
wx.navigateTo({ url: `/pages/customers/detail?id=${id}` });
|
|
},
|
|
|
|
getStatusClass(status) {
|
|
const map = {
|
|
lead: 'text-primary',
|
|
negotiating: 'text-warning',
|
|
closed: 'text-success',
|
|
};
|
|
return map[status] || '';
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.setData({ page: 1, customers: [] });
|
|
this.loadCustomers();
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
}); |