From 5775329fac16cbb50b79ab5bb2256874e4cf8cd2 Mon Sep 17 00:00:00 2001 From: 2812875475 <2812875475@qq.com> Date: Mon, 25 Mar 2024 14:17:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/a/index.vue | 78 ++++++++++++++++++++----- src/views/product/productInfo/index.vue | 28 +++++++-- 2 files changed, 87 insertions(+), 19 deletions(-) diff --git a/src/views/a/index.vue b/src/views/a/index.vue index 39bd5a5..0f6b33e 100644 --- a/src/views/a/index.vue +++ b/src/views/a/index.vue @@ -101,16 +101,21 @@ -

{{ good.name }}

-

¥50

+

{{ good.name }}

{{combinedResults}} +

¥{{price}}

- - {{ item }} + + {{ item }} - - + + 库存{{stock}} +

总价{{sumPrice}}

加入购物车 @@ -154,7 +159,6 @@ export default { computed: {}, data() { return { - names:"", /*图片*/ imageList: [], /*品牌信息*/ @@ -171,7 +175,7 @@ export default { //规格表单 form: { ruleList: [], - selectedValue: 1 + num:1 }, ruleValueList: [], /*国歌表单*/ @@ -181,7 +185,18 @@ export default { attributeList: [] }, /*商品详情*/ - goodDetail: [] + goodDetail: [], + /*监控选中的值*/ + names:"", + // 用于存储前一个选中的 rule 和它的 value + previousRule: null, + previousValue: null, + // 用于存储组合后的结果 + combinedResults: "", + sku:[], + price:0, + stock:0, + sumPrice:0, } }, created() { @@ -189,13 +204,45 @@ export default { this.details(id) }, watch:{ - "names":{ + "form.num":{ handler(val){ - console.log(val) + this.stock=this.stock-1 + this.sumPrice=this.sumPrice+this.price } - } + }, }, methods: { + changeCheck(rule, value){ + //this.form.num=1 + //console.log(checkValue) + console.log(rule.selectedValue) + + this.combinedResults="" + if (this.previousValue !== null) { + // 组合前一个值和当前值,并添加到结果数组中 + const combined = `${this.previousValue}${value}`; + this.combinedResults+=combined + console.log(this.combinedResults); // 打印组合后的结果 + + // 重置前一个选中的 rule 和 value + this.previousRule = null; + this.previousValue = null; + } else { + // 如果没有前一个值,只存储当前选中的 rule 和 value + this.previousRule = rule; + this.previousValue = value; + } + this.sku.forEach( + sku=>{ + if(this.combinedResults===sku.sku){ + this.price=sku.price + this.sumPrice=sku.price + this.stock=sku.stock + } + } + ) + + }, /*立即购买按钮*/ onSubmit() { @@ -209,14 +256,15 @@ export default { this.good.name = res.data.product.name this.good.carouselImages = res.data.product.carouselImages this.imageList.push(res.data.product.carouselImages) + this.sku=res.data.projectSkuInfo let e1=[] + res.data.ruleList.forEach( rule=>{ - e1.push( - {id:rule.id,name:rule.name,value:rule.value} - ) + e1.push({id:rule.id,name:rule.name,value:rule.value}) } ) + console.log(e1) this.form.ruleList =e1 this.categoryCommonElement = res.data.categoryCommonElementResp diff --git a/src/views/product/productInfo/index.vue b/src/views/product/productInfo/index.vue index cc4eefa..d2be55f 100644 --- a/src/views/product/productInfo/index.vue +++ b/src/views/product/productInfo/index.vue @@ -176,7 +176,9 @@ reserve-keyword placeholder="请输入关键词" :remote-method="remoteSearchBrandList" - :loading="loading"> + :loading="loading" + clearable + > {{ scope.row[title.prop] }} +
attribute.value!=null) + console.log(e) + this.attributeCheckedList=e }) } } @@ -780,9 +788,19 @@ export default { this.reset(); const id = row.id || this.ids getInfo(id).then(response => { - console.log(this.categoryCommonElement) + // let a=[] + // response.data.specification.forEach( + // specification=>{ + // a.push( + // {image:specification.image,stock:specification.stock,price:specification.price} + // ) + // } + // ) + // this.skuList=a + // console.log(this.skuList) this.test.id=id this.form = response.data; + //this.oneSettingValue=response.data.specificationList this.oneSettingValue=response.data.specification this.changeRule(response.data.ruleId) this.onSubmit() @@ -808,10 +826,12 @@ export default { }); } else { this.selectAttribute() + console.log(this.form) addInfo(this.form).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; this.getList(); + this.skuList=[] }); } } @@ -841,7 +861,7 @@ export default { } ) this.form.sku=this.skuList1 - this.form.specification=this.oneSettingValue + this.form.specification=this.skuList this.form.groupList=this.a this.form.attributeList=this.b this.form.persionList=this.c