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>
|
||||||
</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>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ import customerApi from '@/api/customer'
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
customerId: '',
|
||||||
form: {
|
form: {
|
||||||
phone: '',
|
phone: '',
|
||||||
name: '',
|
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: {
|
methods: {
|
||||||
async submit() {
|
async submit() {
|
||||||
if (!this.form.phone) {
|
if (!this.form.phone) {
|
||||||
@@ -44,12 +59,34 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (this.isEdit) {
|
||||||
|
await customerApi.updateCustomer(this.customerId, this.form)
|
||||||
|
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||||
|
} else {
|
||||||
await customerApi.createCustomer(this.form)
|
await customerApi.createCustomer(this.form)
|
||||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||||
|
}
|
||||||
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
|
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
|
||||||
} catch (e) {
|
} 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;
|
font-size: 30rpx;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
height: 88rpx;
|
||||||
|
background: #fff;
|
||||||
|
color: #ff4d4f;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
border: 2rpx solid #ff4d4f;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -49,11 +49,7 @@ export default {
|
|||||||
this.loadCustomers()
|
this.loadCustomers()
|
||||||
},
|
},
|
||||||
viewDetail(item) {
|
viewDetail(item) {
|
||||||
uni.showModal({
|
uni.navigateTo({ url: `/pages/customer/create?id=${item.customerId}&name=${item.name}&phone=${item.phone}&wechat=${item.wechat || ''}` })
|
||||||
title: '客户详情',
|
|
||||||
content: `姓名: ${item.name}\n手机: ${item.phone}\n微信: ${item.wechat || '-'}`,
|
|
||||||
showCancel: false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user