From 40dc2b5d2f4c3ac20a75bd09482f65bdd18fbcf5 Mon Sep 17 00:00:00 2001 From: misworga831 Date: Thu, 8 Jan 2026 09:29:39 +0900 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=93=81=E5=8F=82=E6=95=B0):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=80=E5=94=AE=E6=A8=A1=E5=BC=8F=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=8F=8A=E5=95=86=E5=93=81=E5=8F=82=E6=95=B0=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/goods-seller/goodsOperationSec.vue | 89 ++++++++++++++++--- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/seller/src/views/goods/goods-seller/goodsOperationSec.vue b/seller/src/views/goods/goods-seller/goodsOperationSec.vue index 3b16914b..de1bf0ec 100644 --- a/seller/src/views/goods/goods-seller/goodsOperationSec.vue +++ b/seller/src/views/goods/goods-seller/goodsOperationSec.vue @@ -43,7 +43,7 @@ + button-style="solid" type="button" @on-change="handleSalesModeChange"> 零售型 批发型 @@ -394,9 +394,10 @@
- @@ -578,6 +579,8 @@ export default { /** 商品分类中文名 */ categoryName: [], goodsVideo: "", + /** 商品参数用于验证 */ + goodsParams: [], }, /** 表格头 */ skuTableColumn: [], @@ -740,10 +743,24 @@ export default { .map((i) => i.trim()) .filter((i) => i); }, - selectParams(params, value) { + selectParams(params, value, paramsIndex) { if (!Array.isArray(this.baseInfoForm.goodsParamsDTOList)) { this.$set(this.baseInfoForm, "goodsParamsDTOList", []); } + + // 确保baseInfoForm.goodsParams存在 + if (!Array.isArray(this.baseInfoForm.goodsParams)) { + this.$set(this.baseInfoForm, "goodsParams", []); + } + + // 确保对应索引的参数项存在 + if (!this.baseInfoForm.goodsParams[paramsIndex]) { + this.$set(this.baseInfoForm.goodsParams, paramsIndex, {}); + } + + // 更新baseInfoForm中的值用于验证 + this.$set(this.baseInfoForm.goodsParams[paramsIndex], 'paramValue', value || ''); + const list = this.baseInfoForm.goodsParamsDTOList; const paramId = params && params.id ? String(params.id) : ""; const index = list.findIndex((i) => String(i.paramId) === paramId); @@ -752,6 +769,8 @@ export default { if (index >= 0) { list.splice(index, 1); } + // 清空表单项的值 + this.$set(params, 'paramValue', ''); return; } const newItem = { @@ -768,6 +787,9 @@ export default { } else { list.push(newItem); } + + // 同步更新表单项的值 + this.$set(params, 'paramValue', value); }, // 编辑sku图片 editSkuPicture(row) { @@ -852,10 +874,30 @@ export default { }); } this.renderTableData(this.skuTableData); + this.syncWholesalePriceToSku(); }, handleDeleteWholesaleData(index) { this.wholesaleData.splice(index, 1); this.renderTableData(this.skuTableData); + this.syncWholesalePriceToSku(); + }, + // 同步批发价格到SKU + syncWholesalePriceToSku() { + if (this.baseInfoForm.salesModel === 'WHOLESALE' && this.wholesaleData.length > 0) { + // 使用第一个批发价格作为SKU的基础价格 + const basePrice = this.wholesaleData[0].price || 0; + this.skuTableData.forEach(sku => { + sku.price = basePrice; + }); + } + }, + // 处理销售模式切换 + handleSalesModeChange() { + this.renderTableData(this.skuTableData); + // 如果切换到批发模式,同步价格 + if (this.baseInfoForm.salesModel === 'WHOLESALE') { + this.syncWholesalePriceToSku(); + } }, checkWholesaleNum(index) { if (this.wholesaleData[index].num < 0) { @@ -875,6 +917,7 @@ export default { this.wholesaleData[index].num = this.wholesaleData[index - 1].num + 1; } this.renderTableData(this.skuTableData); + this.syncWholesalePriceToSku(); }, checkWholesalePrice(index) { if (this.wholesaleData[index].price < 0) { @@ -895,6 +938,7 @@ export default { this.wholesaleData[index - 1].price - 0.01; } this.renderTableData(this.skuTableData); + this.syncWholesalePriceToSku(); }, // 商品图片上传成功 handleSuccessGoodsPicture(res, file) { @@ -1213,10 +1257,25 @@ export default { return { ...p, paramValue: - selectedValue !== undefined ? selectedValue : p.paramValue, + selectedValue !== undefined ? selectedValue : (p.paramValue || ""), }; }) .sort((a, b) => Number(a.sort || 0) - Number(b.sort || 0)); + + // 初始化baseInfoForm.goodsParams用于表单验证 + this.$set(this.baseInfoForm, 'goodsParams', []); + this.goodsParams.forEach((param, index) => { + this.$set(this.baseInfoForm.goodsParams, index, { + paramValue: param.paramValue || '' + }); + }); + + // 确保表单验证能正确初始化 + this.$nextTick(() => { + if (this.$refs.baseInfoForm) { + this.$refs.baseInfoForm.clearValidate(); + } + }); } ); }, @@ -1686,12 +1745,20 @@ export default { sn: existingCombination.sn || "", quantity: existingCombination.quantity || "", cost: existingCombination.cost || "", - price: existingCombination.price || "", + price: existingCombination.price || (this.baseInfoForm.salesModel === 'WHOLESALE' && this.wholesaleData.length > 0 ? this.wholesaleData[0].price : ""), weight: existingCombination.weight || "" }; } else { - // 新组合使用默认值 - return combination; + // 新组合使用默认值,批发模式下设置默认价格 + return { + ...combination, + id: "", + sn: "", + quantity: "", + cost: "", + price: this.baseInfoForm.salesModel === 'WHOLESALE' && this.wholesaleData.length > 0 ? this.wholesaleData[0].price : "", + weight: "" + }; } }); } @@ -1927,6 +1994,7 @@ export default { return; } let checkFlag = false; + let missingParams = []; this.goodsParams.forEach((param) => { if (!param || !param.required) return; const check = this.baseInfoForm.goodsParamsDTOList.some((paramsItem) => { @@ -1935,10 +2003,11 @@ export default { }); if (!check) { checkFlag = true; + missingParams.push(param.paramName); } }); if (checkFlag) { - this.$Message.error("存在未填写的参数项"); + this.$Message.error(`以下参数为必填项:${missingParams.join('、')}`); return; } this.submitLoading = true;