feat: 客户列表点击进入编辑模式,支持删除客户
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Agent
2026-03-29 05:23:32 +00:00
parent c1477d973f
commit 6c3fd0fb31
2 changed files with 52 additions and 9 deletions

View File

@@ -15,7 +15,8 @@
</view>
</view>
<button class="submit-btn" @click="submit">保存</button>
<button class="submit-btn" @click="submit">{{ isEdit ? '保存修改' : '保存' }}</button>
<button class="delete-btn" v-if="isEdit" @click="deleteCustomer">删除客户</button>
</view>
</template>
@@ -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;
}
</style>

View File

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