Commit 263b3b83 by 李伟康

修复

1 parent a469443b
<template> <template>
<view class="goods-list"> <view
class="goods-list"
:key="viewDataKey"
>
<template v-if="params.loadComplete"> <template v-if="params.loadComplete">
<template v-if="listData.length"> <template v-if="list.length">
<template v-for="(i, index) in listData"> <template v-for="(i, index) in list">
<view <view
:key="index" :key="`${index}_${i.key}`"
@click.stop="choose(i ,index)" @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"> <template v-if="i.goodsFlag == 1">
<view class="flex"> <view class="flex">
...@@ -45,10 +48,7 @@ ...@@ -45,10 +48,7 @@
</template> </template>
</view> </view>
<template v-if="i.multipleSpecificationsGoods.specificationList && i.multipleSpecificationsGoods.specificationList.length"> <template v-if="i.multipleSpecificationsGoods.specificationList && i.multipleSpecificationsGoods.specificationList.length">
<view <view class="package-list">
class="package-list"
:key="i.key"
>
<template v-for="(specific, specificIndex) in i.multipleSpecificationsGoods.specificationList"> <template v-for="(specific, specificIndex) in i.multipleSpecificationsGoods.specificationList">
<picker <picker
...@@ -102,6 +102,7 @@ export default { ...@@ -102,6 +102,7 @@ export default {
name: 'SkuGoodsList', name: 'SkuGoodsList',
data () { data () {
return { return {
viewDataKey: Date.now(),
} }
}, },
...@@ -126,12 +127,17 @@ export default { ...@@ -126,12 +127,17 @@ export default {
this.updateParams(params, data || []) this.updateParams(params, data || [])
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false let { list, params } = this,
ids = []
if (!searchValue) {
list.map(c => {
c.show = true
ids.push(1)
})
}
else { else {
let { list } = this, list.map(c => {
goodsList = JSON.parse(JSON.stringify(list)), c.show = false
arr = []
goodsList.map(c => {
let name = '' let name = ''
if (c.goodsFlag == 1 && c.goods) { if (c.goodsFlag == 1 && c.goods) {
name = c.goods.goodsAlias || c.goods.upgradeGoodsName || c.goods.goodsName || '' name = c.goods.goodsAlias || c.goods.upgradeGoodsName || c.goods.goodsName || ''
...@@ -140,17 +146,20 @@ export default { ...@@ -140,17 +146,20 @@ export default {
name = c.multipleSpecificationsGoods.baseGoodsName name = c.multipleSpecificationsGoods.baseGoodsName
} }
if (name.indexOf(searchValue) != -1) { 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) { initData (goodsData) {
let { data, dataKey } = this, let { data, dataKey } = this,
arr = [] arr = []
goodsData.map((val) => { goodsData.map((val) => {
val.show = true
if (val.goodsFlag == 1) { if (val.goodsFlag == 1) {
let subVal = val.goods let subVal = val.goods
subVal.positionStr = subVal.position subVal.positionStr = subVal.position
...@@ -220,18 +229,27 @@ export default { ...@@ -220,18 +229,27 @@ export default {
}, },
checkActive (i) { checkActive (i) {
let { goodsFlag, goods } = i, let { goodsFlag, goods } = i,
{ currentIds } = this, { currentIds, chooseList } = this,
active = false 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) if (currentIds.length) active = currentIds.includes(goods.goodsId)
return active return active
}, },
handlePickerChange (e, { handlePickerChange (e, {
item, list, parent, index item, list, parent, index
}) { }) {
let { searchStatus } = this
let { value } = e.detail let { value } = e.detail
item.value = list[value] item.value = list[value]
parent.key = Date.now() parent.key = Date.now()
this.$set(searchStatus ? this.searchList : this.list, index, parent)
this.watchAllChose(index) this.watchAllChose(index)
}, },
replaceItemText (item, key) { replaceItemText (item, key) {
...@@ -241,7 +259,8 @@ export default { ...@@ -241,7 +259,8 @@ export default {
}, },
async watchAllChose (index, cancel) { async watchAllChose (index, cancel) {
let { let {
listData: goodsList, list: goodsList,
searchStatus,
} = this; } = this;
let result = goodsList[index].multipleSpecificationsGoods.specificationList.every(item => item.value) let result = goodsList[index].multipleSpecificationsGoods.specificationList.every(item => item.value)
if (result) { if (result) {
...@@ -274,11 +293,8 @@ export default { ...@@ -274,11 +293,8 @@ export default {
item.specificationStr = item.specificationData.replace(/;~;/g, '/') item.specificationStr = item.specificationData.replace(/;~;/g, '/')
}) })
goodsList[index].multipleSpecificationsGoods.skuGoodsList = goodsArr goodsList[index].multipleSpecificationsGoods.skuGoodsList = goodsArr
// let chooseList = await this.getChooseList(false);
// this.$refs.skuPopupRef.open()
this.$emit('openSkuPopup', goodsList[index]) this.$emit('openSkuPopup', goodsList[index])
this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
this.list = goodsList
} }
} else { } else {
uni.showToast({ uni.showToast({
...@@ -291,14 +307,7 @@ export default { ...@@ -291,14 +307,7 @@ export default {
item.value = '' item.value = ''
}) })
} }
this.list = goodsList this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
// this.setData({
// goodsList,
// strTemp: str
// }, () => {
// //同步更新
// this.synchronousChange(goodsList[index])
// })
} else { } else {
if (goodsList[index].active) { if (goodsList[index].active) {
goodsList[index].active = false goodsList[index].active = false
...@@ -312,108 +321,14 @@ export default { ...@@ -312,108 +321,14 @@ export default {
chooseList.splice(ind, 1) chooseList.splice(ind, 1)
} }
}) })
this.list = goodsList this.$emit('choose', this.chooseList)
// this.setData({ this.$set(searchStatus ? this.searchList : this.list, index, goodsList[index])
// goodsList
// }, () => {
// this.synchronousChange(goodsList[index])
// })
} }
} }
} }
return result 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> </script>
...@@ -478,6 +393,9 @@ export default { ...@@ -478,6 +393,9 @@ export default {
} }
} }
} }
.hide {
display: none;
}
.active { .active {
border-color: #2c66f7; border-color: #2c66f7;
background: #ecf1ff; background: #ecf1ff;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!