From 1915394b278d23b151ff10849c5b6c5360e16afe Mon Sep 17 00:00:00 2001 From: lifizer <913626195@qq.com> Date: Tue, 24 Sep 2024 15:20:31 +0800 Subject: [PATCH] =?UTF-8?q?Refactor(=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85):?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=E6=98=AF=E5=90=A6=E6=97=A0=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/store.js | 9 + components/ProductWindow.vue | 56 ++- pages/shop/GoodsCon/index.vue | 678 ++++++++++++++++++---------------- 3 files changed, 387 insertions(+), 356 deletions(-) diff --git a/api/store.js b/api/store.js index cc981d5..55a6e35 100644 --- a/api/store.js +++ b/api/store.js @@ -25,6 +25,15 @@ export function getProductDetail(id, data) { }); } +/* + * 商品规格选中 + * */ +export function getProductSkuBySelected(id, data) { + return request.get("api/product/getSkuBySelected/" + id, data, { + login: true + }); +} + /* * 商品分销二维码 * */ diff --git a/components/ProductWindow.vue b/components/ProductWindow.vue index 7726c75..a4b50ef 100644 --- a/components/ProductWindow.vue +++ b/components/ProductWindow.vue @@ -19,21 +19,25 @@ - + {{ item.attrName }} - {{ itemn.attr }} - 缺货 + {{ subItem.attr }} + 缺货 @@ -88,56 +92,42 @@ export default { } }, methods: { - previewImg:function(imgUrl){ + previewImg(imgUrl) { uni.previewImage({ urls:[imgUrl] }) }, - closeAttr: function() { + closeAttr() { this.$emit("changeFun", { action: "changeattr", value: false }) }, - CartNumDes: function() { + CartNumDes() { this.$emit("changeFun", { action: "ChangeCartNum", value: false }) }, - CartNumAdd: function() { + CartNumAdd() { this.$emit("changeFun", { action: "ChangeCartNum", value: 1 }) }, - getAttrItemData(attr) { - let result = { - stock: 0 - } - if (this.attr.productAttr.length === 1) { - this.productValueArr.map(item => { - if (item.attrItemkey === attr) { - result = item - } - }) - } else { - result.stock = 1 - } - return result - }, - tapAttr: function(indexw, indexn, itemn) { - if (this.getAttrItemData(itemn.attr).stock === 0) { + tapAttr(index, subIndex, subItem) { + // 缺货的点击了没效果 + if (!subItem.canUsed) { return } // 修改商品规格不生效的原因: // H5端下面写法,attr更新,但是除H5外其他端不支持, // 尽量避免下面的骚写法,不要在子组件内更新props // 这里修改是为了能获取到被选中的属性 - this.attr.productAttr[indexw].index = indexn + this.attr.productAttr[index].index = subIndex const value = this.getCheckedValue().sort().join(",") this.$emit("changeFun", { action: "ChangeAttr", value: { value, - indexw, - indexn + index, + subIndex } }) }, // 获取被选中属性 - getCheckedValue: function() { + getCheckedValue() { const productAttr = this.attr.productAttr const value = [] for (let i = 0; i < productAttr.length; i++) { diff --git a/pages/shop/GoodsCon/index.vue b/pages/shop/GoodsCon/index.vue index 5227a94..cda6184 100644 --- a/pages/shop/GoodsCon/index.vue +++ b/pages/shop/GoodsCon/index.vue @@ -451,10 +451,11 @@