Commit da845132 authored by GuanHua's avatar GuanHua

feat:商品详情图片的显示

parent 9127cbda
......@@ -80,7 +80,7 @@ const CommodityDetail = (props) => {
PublicApi.getSearchShopStoreGetCommodityDetail({ commodityId: id }).then(res => {
if (res.code === 1000) {
setCommodityDetail(res.data)
initAttributeAndValueList(res.data?.unitPriceAndPicList)
initAttributeAndValueList(res.data)
getPayWayListByMemberId(res.data?.memberId)
res.data?.isMemberPrice && getMemberCredit(res.data?.memberId, res.data?.memberRoleId)
}
......@@ -301,18 +301,26 @@ const CommodityDetail = (props) => {
* 初始化商品详情数据
* @param unitPriceAndPicList
*/
const initAttributeAndValueList = (unitPriceAndPicList: any) => {
let tempAttrList = []
let tempImgList = []
const initAttributeAndValueList = (dataInfo: any) => {
let unitPriceAndPicList = dataInfo?.unitPriceAndPicList
if (!unitPriceAndPicList) {
return
}
let tempAttrList = []
let tempImgList: any = [{
id: dataInfo.id,
commodityPic: dataInfo.mainPic
}]
for (let item of unitPriceAndPicList) {
if (item.commodityPic) {
tempImgList = [...tempImgList, {
id: item.id,
commodityPic: item.commodityPic[0]
}]
let tempCommodityPic = item.commodityPic.map((picItem, picIndex) => {
return {
id: `${item.id}-${picIndex}`,
commodityPic: picItem
}
})
tempImgList = [...tempImgList, ...tempCommodityPic]
}
for (let attrListItem of item.attributeAndValueList) {
if (judgeAttrInList(tempAttrList, attrListItem.customerAttribute.id)) {
......@@ -343,7 +351,7 @@ const CommodityDetail = (props) => {
}
}
}
console.log(tempImgList, "tempImgList")
setCurrentPriceRange(unitPriceAndPicList[0].unitPrice)
setStockCount(unitPriceAndPicList[0].stockCount || 2000)
setCommodityImgList(tempImgList)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment