feat: 客户列表点击进入编辑模式,支持删除客户
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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 {
|
||||
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>
|
||||
@@ -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 || ''}` })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user