From 3f9420d02615e8edc7a08555f1a86e0ea1ee42e0 Mon Sep 17 00:00:00 2001 From: Agent Date: Fri, 27 Mar 2026 02:10:25 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=A7=8D=E7=B1=BB=E6=97=B6=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/category/index.vue | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/pages/category/index.vue b/src/pages/category/index.vue index d794dfd..7a23c1b 100644 --- a/src/pages/category/index.vue +++ b/src/pages/category/index.vue @@ -121,20 +121,33 @@ export default { } }, deleteCategory(cat) { - uni.showModal({ - 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' }) + // 先检查该分类下是否有商品 + uni.showLoading({ title: '检查中...' }) + productApi.getProducts({ categoryId: cat.categoryId, page: 1, pageSize: 1 }).then(res => { + uni.hideLoading() + if (res.records && res.records.length > 0) { + uni.showToast({ title: '该分类下有商品,无法删除', icon: 'none' }) + return + } + + uni.showModal({ + 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' }) }) } }