Commit 8779623d by wangzhihui

修复多规格商品x

1 parent 151aef6f
...@@ -71,58 +71,76 @@ Component({ ...@@ -71,58 +71,76 @@ Component({
[target]: selectValue [target]: selectValue
}, () => { }, () => {
//监听规格是否全部选中 //监听规格是否全部选中
this.watchAllChose(index, true) this.watchAllChose(index)
}) })
}, },
watchAllChose(index, type) { /*
index:索引
cancel:点击选择按钮的操作;只有选中后,取消才可以触发
*/
watchAllChose(index, cancel) {
let { let {
goodsList, goodsList,
strTemp strTemp
} = this.data; } = this.data;
let result = goodsList[index].multipleSpecificationsGoods.specificationList.every(item => item.value) let result = goodsList[index].multipleSpecificationsGoods.specificationList.every(item => item.value)
let active = goodsList[index].active //取消选中时,情况规格的选中值 console.log(result, goodsList[index],1)
if (!active) {
if (result) { if (result) {
if (!cancel) {
let arr = [] let arr = []
goodsList[index].multipleSpecificationsGoods.specificationList.forEach(spec => { goodsList[index].multipleSpecificationsGoods.specificationList.forEach(spec => {
arr.push(spec.value) arr.push(spec.value)
}) })
let str = arr.join(';~;') let str = arr.join(';~;')
goodsList[index].active = true
// strTemp用来存储上一次选中的值,判断规格是否重新选择 ,避免页面交互闪烁 // strTemp用来存储上一次选中的值,判断规格是否重新选择 ,避免页面交互闪烁
// if (type && str != strTemp) { // if (type && str != strTemp) {
//获取该规格的商品是否存在
console.log(str)
if( goodsList[index].multipleSpecificationsGoods.specificationGoodsMap[str]){ if( goodsList[index].multipleSpecificationsGoods.specificationGoodsMap[str]){
goodsList[index].active = true
console.log(goodsList[index].multipleSpecificationsGoods.specificationGoodsMap[str],'str')
goodsList[index].multipleSpecificationsGoods.goods = goodsList[index].multipleSpecificationsGoods.specificationGoodsMap[str] goodsList[index].multipleSpecificationsGoods.goods = goodsList[index].multipleSpecificationsGoods.specificationGoodsMap[str]
goodsList[index].multipleSpecificationsGoods.goods.goodsId = goodsList[index].multipleSpecificationsGoods.goods.merchantGoodsId goodsList[index].multipleSpecificationsGoods.goods.goodsId = goodsList[index].multipleSpecificationsGoods.goods.merchantGoodsId
goodsList[index].multipleSpecificationsGoods.goods.specificationStr = goodsList[index].multipleSpecificationsGoods.goods.specificationData.replace(';~;', '/') goodsList[index].multipleSpecificationsGoods.goods.specificationStr = goodsList[index].multipleSpecificationsGoods.goods.specificationData.replace(';~;', '/')
}else{ }else{
console.log(88888)
wx.$util.showToast('暂无该规格商品') wx.$util.showToast('暂无该规格商品')
goodsList[index].active=false goodsList[index].active=false
goodsList[index].multipleSpecificationsGoods.goods = '' goodsList[index].multipleSpecificationsGoods.goods = ''
goodsList[index].multipleSpecificationsGoods.specificationList.forEach(item => { goodsList[index].multipleSpecificationsGoods.specificationList.forEach(item => {
item.value = '' item.value = ''
}) })
} }
this.setData({ this.setData({
goodsList, goodsList,
strTemp: !active ? str : '' strTemp: str
}, () => { }, () => {
this.synchronousChange(goodsList[index]) //同步更新
}) this.synchronousChange(goodsList[index])
})
}else{
if(goodsList[index].active){
goodsList[index].active=false
goodsList[index].multipleSpecificationsGoods.goods = ''
goodsList[index].multipleSpecificationsGoods.specificationList.forEach(item => {
item.value = ''
})
console.log(33333, goodsList)
this.setData({
goodsList
},()=>{
this.synchronousChange(goodsList[index])
})
}
}
} }
} else {
goodsList[index].multipleSpecificationsGoods.goods = ''
goodsList[index].multipleSpecificationsGoods.specificationList.forEach(item => {
item.value = ''
})
console.log(33333, goodsList)
this.setData({
goodsList
})
}
//规格全部选中逻辑处理
return result return result
}, },
setGoodsActive(isFlag) { setGoodsActive(isFlag) {
if (this.data.show) { if (this.data.show) {
...@@ -341,7 +359,7 @@ Component({ ...@@ -341,7 +359,7 @@ Component({
} = this.data; } = this.data;
//单独处理多规格商品点击事件 //单独处理多规格商品点击事件
if (item.goodsFlag == 2) { if (item.goodsFlag == 2) {
if (!this.watchAllChose(ind)) { if (!this.watchAllChose(ind,true)) {
wx.$util.showToast('请先选择该商品规格') wx.$util.showToast('请先选择该商品规格')
return return
} }
...@@ -376,6 +394,13 @@ Component({ ...@@ -376,6 +394,13 @@ Component({
i.active = item.active i.active = item.active
i.count = item.count i.count = item.count
i.multipleSpecificationsGoods=item.multipleSpecificationsGoods i.multipleSpecificationsGoods=item.multipleSpecificationsGoods
if(!item.active){
i.multipleSpecificationsGoods.goods=''
i.multipleSpecificationsGoods.specificationList.forEach(m=>{
m.value=''
})
}
} }
} }
}) })
...@@ -398,8 +423,10 @@ Component({ ...@@ -398,8 +423,10 @@ Component({
console.log(target) console.log(target)
this.setData({ this.setData({
[target]: item.count, [target]: item.count,
},()=>{
this.synchronousChange(this.data.goodsList[ind])
}); });
console.log(this.data.goodsList[ind])
}, },
input(e) { input(e) {
let { let {
...@@ -415,7 +442,11 @@ Component({ ...@@ -415,7 +442,11 @@ Component({
if (value > 999) value = 999; if (value > 999) value = 999;
this.setData({ this.setData({
[target]: Number(value), [target]: Number(value),
}); },
()=>{
this.synchronousChange(this.data.goodsList[ind])
}
);
}, },
searchGoods(e) { searchGoods(e) {
let { let {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!