修复:删除种类时检查是否有商品
This commit is contained in:
@@ -121,20 +121,33 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteCategory(cat) {
|
deleteCategory(cat) {
|
||||||
uni.showModal({
|
// 先检查该分类下是否有商品
|
||||||
title: '确认删除',
|
uni.showLoading({ title: '检查中...' })
|
||||||
content: `确定要删除 "${cat.name}" 吗?`,
|
productApi.getProducts({ categoryId: cat.categoryId, page: 1, pageSize: 1 }).then(res => {
|
||||||
success: async (res) => {
|
uni.hideLoading()
|
||||||
if (res.confirm) {
|
if (res.records && res.records.length > 0) {
|
||||||
try {
|
uni.showToast({ title: '该分类下有商品,无法删除', icon: 'none' })
|
||||||
await productApi.deleteCategory(cat.categoryId)
|
return
|
||||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
}
|
||||||
this.loadCategories()
|
|
||||||
} catch (e) {
|
uni.showModal({
|
||||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
title: '确认删除',
|
||||||
|
content: `确定要删除 "${cat.name}" 吗?`,
|
||||||
|
success: async (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
try {
|
||||||
|
await productApi.deleteCategory(cat.categoryId)
|
||||||
|
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||||
|
this.loadCategories()
|
||||||
|
} catch (e) {
|
||||||
|
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user