From 6c3fd0fb313a0124e8b0bee5710e7c433e8508bd Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 29 Mar 2026 05:23:32 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E8=BF=9B=E5=85=A5=E7=BC=96=E8=BE=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=A0=E9=99=A4=E5=AE=A2?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/customer/create.vue | 55 ++++++++++++++++++++++++++++++++--- src/pages/customer/list.vue | 6 +--- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/pages/customer/create.vue b/src/pages/customer/create.vue index 2113cc4..192e9b6 100644 --- a/src/pages/customer/create.vue +++ b/src/pages/customer/create.vue @@ -15,7 +15,8 @@ - + + @@ -25,6 +26,7 @@ import customerApi from '@/api/customer' export default { data() { return { + customerId: '', form: { phone: '', name: '', @@ -32,6 +34,19 @@ export default { } } }, + computed: { + isEdit() { + return !!this.customerId + } + }, + onLoad(options) { + if (options.id) { + this.customerId = options.id + this.form.phone = options.phone || '' + this.form.name = options.name || '' + this.form.wechat = options.wechat || '' + } + }, methods: { async submit() { if (!this.form.phone) { @@ -44,12 +59,34 @@ export default { } try { - await customerApi.createCustomer(this.form) - uni.showToast({ title: '添加成功', icon: 'success' }) + if (this.isEdit) { + await customerApi.updateCustomer(this.customerId, this.form) + uni.showToast({ title: '修改成功', icon: 'success' }) + } else { + await customerApi.createCustomer(this.form) + uni.showToast({ title: '添加成功', icon: 'success' }) + } setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500) } catch (e) { - uni.showToast({ title: e.message || '添加失败', icon: 'none' }) + uni.showToast({ title: e.message || '操作失败', icon: 'none' }) } + }, + deleteCustomer() { + uni.showModal({ + title: '确认删除', + content: '确定要删除该客户吗?', + success: async (res) => { + if (res.confirm) { + try { + await customerApi.deleteCustomer(this.customerId) + uni.showToast({ title: '删除成功', icon: 'success' }) + setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500) + } catch (e) { + uni.showToast({ title: e.message || '删除失败', icon: 'none' }) + } + } + } + }) } } } @@ -98,4 +135,14 @@ export default { font-size: 30rpx; border: none; } + +.delete-btn { + margin-top: 20rpx; + height: 88rpx; + background: #fff; + color: #ff4d4f; + border-radius: 44rpx; + font-size: 30rpx; + border: 2rpx solid #ff4d4f; +} \ No newline at end of file diff --git a/src/pages/customer/list.vue b/src/pages/customer/list.vue index 60c6b90..963721a 100644 --- a/src/pages/customer/list.vue +++ b/src/pages/customer/list.vue @@ -49,11 +49,7 @@ export default { this.loadCustomers() }, viewDetail(item) { - uni.showModal({ - title: '客户详情', - content: `姓名: ${item.name}\n手机: ${item.phone}\n微信: ${item.wechat || '-'}`, - showCancel: false - }) + uni.navigateTo({ url: `/pages/customer/create?id=${item.customerId}&name=${item.name}&phone=${item.phone}&wechat=${item.wechat || ''}` }) } } }