Commit 263b3b83 by 李伟康

修复

1 parent a469443b
<template>
<view class="goods-list">
<view
class="goods-list"
:key="viewDataKey"
>
<template v-if="params.loadComplete">
<template v-if="listData.length">
<template v-for="(i, index) in listData">
<template v-if="list.length">
<template v-for="(i, index) in list">
<view
:key="index"
:key="`${index}_${i.key}`"
@click.stop="choose(i ,index)"
:class="['item',{active: checkActive(i) || i.active},{single:i.goodsFlag == 1}]"
:class="['item',{hide:!i.show},{active: checkActive(i)},{single:i.goodsFlag == 1}]"
>
<template v-if="i.goodsFlag == 1">
<view class="flex">
......@@ -45,10 +48,7 @@
</template>
</view>
<template v-if="i.multipleSpecificationsGoods.specificationList && i.multipleSpecificationsGoods.specificationList.length">
<view
class="package-list"
:key="i.key"
>
<view class="package-list">
<template v-for="(specific, specificIndex) in i.multipleSpecificationsGoods.specificationList">
<picker
......@@ -102,6 +102,7 @@ export default {
name: 'SkuGoodsList',
data () {
return {
viewDataKey: Date.now(),
}
},
......@@ -126,12 +127,17 @@ export default {
this.updateParams(params, data || [])
},
handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false
let { list, params } = this,
ids = []
if (!searchValue) {
list.map(c => {
c.show = true
ids.push(1)
})
}
else {
let { list } = this,
goodsList = JSON.parse(JSON.stringify(list)),
arr = []
goodsList.map(c => {
list.map(c => {
c.show = false
let name = ''
if (c.goodsFlag == 1 && c.goods) {
name = c.goods.goodsAlias || c.goods.upgradeGoodsName || c.goods.goodsName || ''
......@@ -140,17 +146,20 @@ export default {
name = c.multipleSpecificationsGoods.baseGoodsName
}
if (name.indexOf(searchValue) != -1) {
arr.push(c)
c.show = true
ids.push(1)
}
})
this.searchList = arr
this.searchStatus = true
}
params.noData = !ids.length
this.updateParams(params)
this.viewDataKey = Date.now()
},
initData (goodsData) {
let { data, dataKey } = this,
arr = []
goodsData.map((val) => {
val.show = true
if (val.goodsFlag == 1) {
let subVal = val.goods
subVal.positionStr = subVal.position
......@@ -220,18 +229,27 @@ export default {
},
checkActive (i) {
let { goodsFlag, goods } = i,
{ currentIds } = this,
{ currentIds, chooseList } = this,
active = false
if (goodsFlag == 2) return false
if (goodsFlag == 2) {
let ids = []
chooseList.map(e => {
if (e.goodsFlag == 2) ids.push(e.multipleSpecificationsGoods.id)
})
return ids.includes(i.multipleSpecificationsGoods.id)
}
if (currentIds.length) active = currentIds.includes(goods.goodsId)
return active
},
handlePickerChange (e, {
item, list, parent, index
}) {
let { searchStatus } = this
let { value } = e.detail
item.value = list[value]
parent.key = Date.now()
this.$set(searchStatus ? this.searchList : this.list, index, parent)
this.watchAllChose(index)
},
replaceItemText (item, key) {
......@@ -241,7 +259,8 @@ export default {
},
async watchAllChose (index, cancel) {
let {
listData: goodsList,
list: goodsList,
searchStatus,
} = this;
let result = goodsList[index].multipleSpecificationsGoods.specificationList.every(item => item.value)
if (result) {
......@@ -274,11 +293,8 @@ export default {
item.specificationStr = item.specificationData.replace(/;~;/g, '/')
})
goodsList[index].multipleSpecificationsGoods.skuGoodsList = goodsArr
// let chooseList = await this.getChooseList(false);
// this.$refs.skuPopupRef.open()
this.$emit('openSkuPopup', goodsList[index])
this.list = goodsList
this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
}
} else {
uni.showToast({
......@@ -291,14 +307,7 @@ export default {
item.value = ''
})
}
this.list = goodsList
// this.setData({
// goodsList,
// strTemp: str
// }, () => {
// //同步更新
// this.synchronousChange(goodsList[index])
// })
this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
} else {
if (goodsList[index].active) {
goodsList[index].active = false
......@@ -312,108 +321,14 @@ export default {
chooseList.splice(ind, 1)
}
})
this.list = goodsList
// this.setData({
// goodsList
// }, () => {
// this.synchronousChange(goodsList[index])
// })
this.$emit('choose', this.chooseList)
this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
}
}
}
return result
},
async getChooseList (isValid) {
let {
list: goodsList,
chooseList: chooseGoodsList,
} = this;
let chooseList = [];
goodsList.map((e) => {
if (e.active) {
chooseList.push(e)
}
});
if (isValid) {
if (!chooseList?.length) return uni.showToast({
title: '请勾选商品',
icon: 'none',
})
}
let arr = this.removeDuplicates(
chooseList.concat(chooseGoodsList),
"goodsId"
);
// 太阳膜下单 需保留已选的商品
arr.map(c => {
if (c.active) {
if (c.goods) {
if (!c.count) c.count = 1
c.goods.price = c.goods.sellPrice || 0
if (chooseGoodsList.length > 0) {
chooseGoodsList.map(x => {
if (x.goods && x.goods.goodsId == c.goods.goodsId) {
c.goods.price = x.goods.price || 0
}
})
}
}
if (c.multipleSpecificationsGoods) {
c.isFlag = true //初始化进来不显示标识
if (c.multipleSpecificationsGoods.goods) {
if (!c.count) c.count = 1
c.multipleSpecificationsGoods.goods.price = c.multipleSpecificationsGoods.goods.sellPrice || 0
if (chooseGoodsList.length > 0) {
chooseGoodsList.map(x => {
if (x.goodsFlag == 2) {
if (x.multipleSpecificationsGoods.goods && x.multipleSpecificationsGoods.goods.goodsId == c.multipleSpecificationsGoods.goods.goodsId) {
c.multipleSpecificationsGoods.goods.price = x.multipleSpecificationsGoods.goods.price || 0
}
}
})
}
}
}
}
})
return arr;
},
removeDuplicates (arr, property) {
var uniqueArray = [];
for (var i = 0; i < arr.length; i++) {
let goodsType = arr[i].goodsFlag == 1 ? 'goods' : 'multipleSpecificationsGoods.goods'
let value = this.circulation(arr[i], goodsType)[property]
// 兼容套餐
let result = uniqueArray.some(item => {
let key = item.goodsFlag == 1 ? 'goods' : item.goodsFlag == 2 ? 'multipleSpecificationsGoods.goods' : ''
let deepValue = this.circulation(item, key)
return deepValue ? deepValue[property] === value : false
})
if (!result) {
uniqueArray.push(arr[i]);
}
}
return uniqueArray;
},
circulation (data, str) {
if (str) {
let arr = str.split('.'),
result;
if (arr.length) {
result = arr.reduce((pre, key) => {
return pre[key] ? pre[key] : {}
}, data)
}
return result;
} else {
return false
}
},
}
}
</script>
......@@ -478,6 +393,9 @@ export default {
}
}
}
.hide {
display: none;
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!