diff --git a/pkg_user/views/giftList.vue b/pkg_user/views/giftList.vue index 6e2f5e3..180ca54 100644 --- a/pkg_user/views/giftList.vue +++ b/pkg_user/views/giftList.vue @@ -138,7 +138,7 @@ class="gift-item" > - {{ cart.productInfo.storeName }} + {{ cart._displayName }} - - {{ cart.productInfo.attrInfo.sku }} + + {{ cart._displaySku }} - + - {{ cart.productInfo.attrInfo.price }} + {{ cart._displayPrice }} @@ -442,7 +442,8 @@ export default { const { success, data } = res if (success) { const { list, hasMore } = this.getListResult(data, page) - this.receiveList = page === 1 ? list : this.receiveList.concat(list) + const formatList = list.map(item => this.normalizeReceiveGiftItem(item)) + this.receiveList = page === 1 ? formatList : this.receiveList.concat(formatList) this.receiveHasMore = hasMore this.receivePage = page + 1 this.receiveInited = true @@ -526,6 +527,51 @@ export default { } return status }, + normalizeReceiveGiftItem(item = {}) { + return { + ...item, + _renderGiftInfos: this.getReceiveGiftInfos(item) + } + }, + getReceiveGiftInfos(item = {}) { + if (item.customGiftInfo && typeof item.customGiftInfo === 'object') { + const customGift = this.formatCustomGiftInfo(item.customGiftInfo) + if (customGift) { + return [customGift] + } + } + const giftInfos = Array.isArray(item.giftInfos) ? item.giftInfos : [] + return giftInfos.map(gift => this.formatDefaultGiftInfo(gift)) + }, + formatCustomGiftInfo(customGiftInfo = {}) { + const giftImage = typeof customGiftInfo.giftImage === 'string' + ? customGiftInfo.giftImage.trim() + : '' + const giftValue = customGiftInfo.giftValue + const hasGiftValue = giftValue !== '' && giftValue !== null && giftValue !== undefined + return { + ...customGiftInfo, + _isCustomGift: true, + _displayImage: giftImage, + _displayName: customGiftInfo.giftName || '', + _displaySku: customGiftInfo.specName || '', + _displayPrice: hasGiftValue ? giftValue : '', + _showPrice: Number(customGiftInfo.isShowValue) === 1 && hasGiftValue + } + }, + formatDefaultGiftInfo(gift = {}) { + const productInfo = gift.productInfo || {} + const attrInfo = productInfo.attrInfo || {} + const price = attrInfo.price + return { + ...gift, + _displayImage: productInfo.image || '', + _displayName: productInfo.storeName || '', + _displaySku: attrInfo.sku || '', + _displayPrice: price, + _showPrice: price !== '' && price !== null && price !== undefined + } + }, showTips() { this.$refs.giftTips.showTips = true },