From 59e55edbd78692e25ac3e6519075d228f1174f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Fri, 18 Mar 2022 22:36:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(GoodsStock.vue):=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=9B=BE=E7=89=87=E4=B8=A2=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/pms/goods/components/GoodsStock.vue | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/views/pms/goods/components/GoodsStock.vue b/src/views/pms/goods/components/GoodsStock.vue index 313d268d..2071e36b 100644 --- a/src/views/pms/goods/components/GoodsStock.vue +++ b/src/views/pms/goods/components/GoodsStock.vue @@ -142,7 +142,7 @@ :prop="'skuList[' + scope.$index + '].skuSn'" :rules="rules.sku.skuSn" > - + @@ -253,15 +253,16 @@ const { specForm, skuForm, specTitles, rules, colors, tagInputs, loading } = watch( categoryId, - (newVal, oldVal) => { + (value) => { + // 商品编辑不加载分类下的规格 const spuId = props.modelValue.id; if (spuId) { return false; } - if (newVal) { + if (value) { // type=1 商品分类下的规格 - listAttributes({ categoryId: newVal, type: 1 }).then((response) => { + listAttributes({ categoryId: value, type: 1 }).then((response) => { const specList = response.data; if (specList && specList.length > 0) { specList.forEach((item) => { @@ -281,6 +282,12 @@ watch( } ); + + +watch(state.specForm.specList,(value)=>{ + generateSkuList() +}) + function loadData() { props.modelValue.specList.forEach((specItem) => { const specIndex = state.specForm.specList.findIndex( @@ -372,16 +379,18 @@ 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 = []; + if(state.specForm.specList.length==0){ + state.skuForm.skuList = []; return; } + + const specList = JSON.parse( + JSON.stringify( + state.specForm.specList.filter((item) => item.values&&item.values.length > 0) + ) + ); // 深拷贝,取有属性的规格项,否则笛卡尔积运算得到的SKU列表值为空 + const skuList = specList.reduce( (acc, curr) => { let result = []; @@ -447,7 +456,7 @@ function handleSpecAdd() { ElMessage.warning("最多支持3组规格"); return; } - state.specForm.specList.push({}); + state.specForm.specList.push({values:[]}); state.tagInputs.push({ value: undefined, visible: false }); handleSpecReorder(); } @@ -695,7 +704,7 @@ onMounted(() => { } } -.el-form-item--mini.el-form-item { +.el-form--inline .el-form-item{ margin-top: 18px; }