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 || ''}` })
}
}
}