From 52e5c9314a7ece37886175e279b97ebbf60f1b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Sun, 23 Jan 2022 13:52:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(GoodsStock.vue):=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B7=BB=E5=8A=A0SKU=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E7=A9=BA=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/pms/goods/components/GoodsStock.vue | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/views/pms/goods/components/GoodsStock.vue b/src/views/pms/goods/components/GoodsStock.vue index 5348f3b0..75075d78 100644 --- a/src/views/pms/goods/components/GoodsStock.vue +++ b/src/views/pms/goods/components/GoodsStock.vue @@ -118,7 +118,6 @@ :inline="true" > { + // 商品编辑不加载分类下的规格 + const spuId = props.modelValue.id + if (spuId) { + return false; + } if (newVal) { - // type=1 商品规格(销售属性) + // type=1 商品分类下的规格 listAttributes({categoryId: newVal, type: 1}).then(response => { const specList = response.data if (specList && specList.length > 0) { @@ -255,8 +259,6 @@ watch(categoryId, (newVal, oldVal) => { function loadData() { - const goodsId = props.modelValue.id - props.modelValue.specList.forEach((specItem) => { const specIndex = state.specForm.specList.findIndex(item => item.name == specItem.name) if (specIndex > -1) { @@ -344,6 +346,11 @@ function handleSpecReorder() { */ function generateSkuList() { const specList = JSON.parse(JSON.stringify(state.specForm.specList.filter(item => item.values.length > 0))) // 深拷贝,取有属性的规格项,否则笛卡尔积运算得到的SKU列表值为空 + // 如果规格为空,生成SKU列表为空 + if (specList.length === 0) { + state.skuForm.skuList = [] + return + } const skuList = specList.reduce((acc, curr) => { let result = [] acc.forEach((item) => { @@ -515,6 +522,12 @@ const objectSpanMethod = ({ * 商品表单提交 */ function submitForm() { + // 判断商品SKU列表是否为空 + if (!state.skuForm.skuList || state.skuForm.skuList.length === 0) { + ElMessage.warning("未添加商品库存") + return false; + } + const specForm = unref(specFormRef) specForm.validate((specValid) => { if (specValid) { @@ -522,6 +535,8 @@ function submitForm() { skuForm.validate((skuValid) => { if (skuValid) { // openFullScreen() + + // 重组商品的规格和SKU列表 let submitsData = Object.assign({}, props.modelValue) delete submitsData.specList delete submitsData.skuList @@ -550,8 +565,8 @@ function submitForm() { updateGoods(goodsId, submitsData).then((res) => { router.push({path: '/pms/goods'}) ElNotification({ - title: 'Success', - message: '新增商品成功', + title: '提示', + message: '编辑商品成功', type: 'success', }) //closeFullScreen() @@ -563,7 +578,7 @@ function submitForm() { addGoods(submitsData).then(response => { router.push({path: '/pms/goods'}) ElNotification({ - title: 'Success', + title: '提示', message: '新增商品成功', type: 'success', })