diff --git a/api/store.js b/api/store.js index cc981d5..423461f 100644 --- a/api/store.js +++ b/api/store.js @@ -25,6 +25,15 @@ export function getProductDetail(id, data) { }); } +/* + * 商品规格选中 + * */ +export function getProductSkuBySelected(data) { + return request.post("/product/getSkuBySelected", data, { + login: true + }); +} + /* * 商品分销二维码 * */ diff --git a/components/ProductWindow.vue b/components/ProductWindow.vue index 7726c75..c6a0f0f 100644 --- a/components/ProductWindow.vue +++ b/components/ProductWindow.vue @@ -2,38 +2,42 @@ - - + + ¥ - {{ attr.productSelect.price }} + {{ attrObj.productSelect.price }} - {{ attr.productSelect.otPrice }} + {{ attrObj.productSelect.otPrice }} 会员价 - + - {{ attr.productSelect.store_name }} + {{ attrObj.productSelect.store_name }} - + {{ item.attrName }} - {{ itemn.attr }} - 缺货 + {{ subItem.attr }} + 缺货 @@ -47,7 +51,7 @@ style="border-radius:0 40rpx 40rpx 0" class="item plus v12-font-bold v12-white-text v12-primary v12-primary-border v12-font-36 cart-btn" :class=" - cartNum >= attr.productSelect.stock + cartNum >= attrObj.productSelect.stock ? 'on' : '' " @@ -71,82 +75,75 @@ export default { } } }, - // 使用字符串再转成对象的原因是,当key='2.5g'时,会变成key='2',导致数据丢失 - productValueStr: { - type: String, - default: '{}' - }, - productValueArr: { - type: Array, - default: () => { - return [] - } - }, cartNum: { type: Number, default: () => 1 } }, + data() { + return { + attrObj: { + productSelect: {}, + productAttr: [] + } + } + }, + created() { + this.$set(this, 'attrObj', JSON.parse(JSON.stringify(this.attr))) + console.log(this.attrObj) + }, methods: { - previewImg:function(imgUrl){ + reRender(data) { + this.$set(this, 'attrObj', JSON.parse(JSON.stringify(data))) + // console.log(this.attrObj.productAttr) + this.$forceUpdate() + }, + 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 || subItem.check) { return } - // 修改商品规格不生效的原因: - // H5端下面写法,attr更新,但是除H5外其他端不支持, - // 尽量避免下面的骚写法,不要在子组件内更新props - // 这里修改是为了能获取到被选中的属性 - this.attr.productAttr[indexw].index = indexn + this.attrObj.productAttr[index].attrValue.map((subItem, subIdx) => { + subItem.check= false + if (subIndex === subIdx) { + subItem.check = true + } + }) const value = this.getCheckedValue().sort().join(",") this.$emit("changeFun", { action: "ChangeAttr", value: { value, - indexw, - indexn + index, + subIndex } }) }, // 获取被选中属性 - getCheckedValue: function() { - const productAttr = this.attr.productAttr + getCheckedValue() { + const productAttr = this.attrObj.productAttr const value = [] - for (let i = 0; i < productAttr.length; i++) { - for (let j = 0; j < productAttr[i].attrValueArr.length; j++) { - if (productAttr[i].index === j) { - value.push(productAttr[i].attrValueArr[j]) + productAttr.map(item => { + item.attrValue.map(subItem => { + if (subItem.check) { + value.push(subItem.attr) } - } - } + }) + }) return value } } diff --git a/manifest.json b/manifest.json index dd0ef38..aad82ac 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "地标文化特产", - "appid" : "__UNI__7880B21", + "appid" : "__UNI__281C173", "description" : "", "versionName" : "4.0.0", "versionCode" : 4, diff --git a/pages/cart.vue b/pages/cart.vue index d773819..db6339a 100644 --- a/pages/cart.vue +++ b/pages/cart.vue @@ -19,7 +19,11 @@ - {{ isEdit ? '完成' : '管理' }} + {{ isEdit ? '完成' : '管理' }} - - - + + + - + + 预计获得{{ attr.productSelect.earnPoints }}积分 + + 更多优惠 @@ -451,10 +458,11 @@