Initial commit: TradeMate 外贸小助手 MVP
项目结构: - backend/ Python FastAPI 后端 - uni-app/ uni-app跨端前端 - docs/ 设计文档 - docker-compose.yml Docker编排 - nginx/scripts/systemd 运维配置 已完成功能: - 用户认证 (JWT) - 智能翻译 + 回复建议 - 营销素材生成 - 客户管理 + 沉默检测 - 报价单管理 - 产品库管理 - 汇率换算 - 推送通知 (uni-push) - WhatsApp Webhook框架 - Celery定时任务
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
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();
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"navigationBarTitleText": "客户管理",
|
||||
"enablePullDownRefresh": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<text class="section-title">客户列表</text>
|
||||
<button class="add-btn" bindtap="showAdd">+ 添加客户</button>
|
||||
</view>
|
||||
|
||||
<view class="customer-list">
|
||||
<view class="customer-item" wx:for="{{customers}}" wx:key="id" bindtap="viewDetail" data-id="{{item.id}}">
|
||||
<view class="customer-info">
|
||||
<view class="customer-name">{{item.name}}</view>
|
||||
<view class="customer-meta">
|
||||
{{item.company}} {{item.country ? '· ' + item.country : ''}}
|
||||
</view>
|
||||
<view class="customer-meta" wx:if="{{item.last_contact_at}}">
|
||||
最后联系: {{item.last_contact_at}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="customer-status status-{{item.status}}">
|
||||
{{item.status === 'lead' ? '潜在' : item.status === 'negotiating' ? '谈判中' : '已成交'}}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="empty" wx:if="{{customers.length === 0 && !loading}}">
|
||||
<text>暂无客户,点击上方添加</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="modal" wx:if="{{showAddModal}}" bindtap="hideAdd">
|
||||
<view class="modal-content" catchtap>
|
||||
<view class="modal-title">添加客户</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">姓名 *</text>
|
||||
<input class="form-input" placeholder="客户姓名" data-field="name" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">公司</text>
|
||||
<input class="form-input" placeholder="公司名称" data-field="company" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">国家</text>
|
||||
<input class="form-input" placeholder="如:美国、德国" data-field="country" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">电话</text>
|
||||
<input class="form-input" placeholder="手机号" data-field="phone" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">WhatsApp</text>
|
||||
<input class="form-input" placeholder="WhatsApp ID" data-field="whatsapp_id" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="form-group">
|
||||
<text class="form-label">邮箱</text>
|
||||
<input class="form-input" placeholder="邮箱地址" data-field="email" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="modal-btns">
|
||||
<view class="modal-btn btn-cancel" bindtap="hideAdd">取消</view>
|
||||
<view class="modal-btn btn-confirm" bindtap="addCustomer">确定</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,160 @@
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
font-size: 28rpx;
|
||||
padding: 15rpx 30rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.customer-list {
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
|
||||
.customer-item {
|
||||
background: #fff;
|
||||
border-radius: 12rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.customer-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.customer-meta {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.customer-status {
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.status-lead {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.status-negotiating {
|
||||
background: #fffbe6;
|
||||
color: #faad14;
|
||||
}
|
||||
|
||||
.status-closed {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.customer-actions {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 100rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: #fff;
|
||||
border-radius: 12rpx;
|
||||
padding: 40rpx;
|
||||
width: 80%;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 30rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 10rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
border: 1rpx solid #d9d9d9;
|
||||
border-radius: 8rpx;
|
||||
padding: 20rpx;
|
||||
font-size: 28rpx;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.modal-btns {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.btn-confirm {
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
}
|
||||
Reference in New Issue
Block a user