|
@@ -32,7 +32,7 @@
|
|
|
<view
|
|
<view
|
|
|
v-for="item in giftItems"
|
|
v-for="item in giftItems"
|
|
|
:key="getGiftItemKey(item)"
|
|
:key="getGiftItemKey(item)"
|
|
|
- :class="isGiftSelected(item) ? 'gift-select-item gift-select-item-active' : 'gift-select-item'"
|
|
|
|
|
|
|
+ :class="item._selected ? 'gift-select-item gift-select-item-active' : 'gift-select-item'"
|
|
|
@click="toggleGift(item)"
|
|
@click="toggleGift(item)"
|
|
|
>
|
|
>
|
|
|
<image v-if="item.giftType === 'product' && item.giftProductImage" class="gift-select-img" :src="getImageUrl(item.giftProductImage)" mode="aspectFill" />
|
|
<image v-if="item.giftType === 'product' && item.giftProductImage" class="gift-select-img" :src="getImageUrl(item.giftProductImage)" mode="aspectFill" />
|
|
@@ -41,7 +41,7 @@
|
|
|
<text class="gift-select-name">{{ item.giftType === 'product' ? item.giftProductName : (item.cfValue + ' CF值') }}</text>
|
|
<text class="gift-select-name">{{ item.giftType === 'product' ? item.giftProductName : (item.cfValue + ' CF值') }}</text>
|
|
|
<text class="gift-select-type">{{ item.giftType === 'product' ? '赠品商品' : 'CF值赠品' }}</text>
|
|
<text class="gift-select-type">{{ item.giftType === 'product' ? '赠品商品' : 'CF值赠品' }}</text>
|
|
|
</view>
|
|
</view>
|
|
|
- <view v-if="isGiftSelected(item)" class="gift-select-check">✓</view>
|
|
|
|
|
|
|
+ <view v-if="item._selected" class="gift-select-check">✓</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -186,8 +186,6 @@ export default {
|
|
|
isMember: false,
|
|
isMember: false,
|
|
|
memberLevel: 'FREE',
|
|
memberLevel: 'FREE',
|
|
|
bundleItems: []
|
|
bundleItems: []
|
|
|
- // 赠品选择(giftConfigs 来自商品详情,当前用户等级匹配)
|
|
|
|
|
- , selectedGiftIds: []
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
@@ -374,6 +372,16 @@ export default {
|
|
|
if (res.code === 200 && res.data) {
|
|
if (res.code === 200 && res.data) {
|
|
|
that.product = res.data
|
|
that.product = res.data
|
|
|
that.bundleItems = (res.data && res.data.bundleItems) || []
|
|
that.bundleItems = (res.data && res.data.bundleItems) || []
|
|
|
|
|
+ // 赠品项初始化选择状态(响应式)
|
|
|
|
|
+ var cfgList = res.data.giftConfigs
|
|
|
|
|
+ if (cfgList && cfgList.length > 0) {
|
|
|
|
|
+ for (var gi = 0; gi < cfgList.length; gi++) {
|
|
|
|
|
+ var itemsArr = cfgList[gi].items || []
|
|
|
|
|
+ for (var gj = 0; gj < itemsArr.length; gj++) {
|
|
|
|
|
+ that.$set(itemsArr[gj], '_selected', false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
that.setShareInfo(
|
|
that.setShareInfo(
|
|
|
that.product.name,
|
|
that.product.name,
|
|
|
'/pages/discover-detail/product-detail/product-detail?id=' + that.product.id
|
|
'/pages/discover-detail/product-detail/product-detail?id=' + that.product.id
|
|
@@ -576,16 +584,8 @@ export default {
|
|
|
return item.id
|
|
return item.id
|
|
|
},
|
|
},
|
|
|
toggleGift: function(item) {
|
|
toggleGift: function(item) {
|
|
|
- var idx = this.selectedGiftIds.indexOf(item.id)
|
|
|
|
|
- if (idx > -1) {
|
|
|
|
|
- this.selectedGiftIds.splice(idx, 1)
|
|
|
|
|
- } else {
|
|
|
|
|
- this.selectedGiftIds.push(item.id)
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- isGiftSelected: function(item) {
|
|
|
|
|
- return this.selectedGiftIds.indexOf(item.id) > -1
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ this.$set(item, '_selected', !item._selected)
|
|
|
|
|
+ },,
|
|
|
|
|
|
|
|
onBuy: function() {
|
|
onBuy: function() {
|
|
|
var userId = uni.getStorageSync('userId')
|
|
var userId = uni.getStorageSync('userId')
|
|
@@ -611,8 +611,20 @@ export default {
|
|
|
productData.specDesc = this.buildSpecDesc()
|
|
productData.specDesc = this.buildSpecDesc()
|
|
|
}
|
|
}
|
|
|
uni.setStorageSync('checkoutItems', [productData])
|
|
uni.setStorageSync('checkoutItems', [productData])
|
|
|
- // 透传赠品选择到 checkout
|
|
|
|
|
- uni.setStorageSync('checkoutGiftItemIds', this.selectedGiftIds)
|
|
|
|
|
|
|
+ // 透传赠品选择到 checkout(收集所有 _selected=true 的赠品项ID)
|
|
|
|
|
+ var selectedGiftIds = []
|
|
|
|
|
+ var cfgList = this.product.giftConfigs
|
|
|
|
|
+ if (cfgList && cfgList.length > 0) {
|
|
|
|
|
+ for (var gi = 0; gi < cfgList.length; gi++) {
|
|
|
|
|
+ var itemsArr = cfgList[gi].items || []
|
|
|
|
|
+ for (var gj = 0; gj < itemsArr.length; gj++) {
|
|
|
|
|
+ if (itemsArr[gj]._selected) {
|
|
|
|
|
+ selectedGiftIds.push(itemsArr[gj].id)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.setStorageSync('checkoutGiftItemIds', selectedGiftIds)
|
|
|
var deliveryMethod = this.product.deliveryMethod || 1
|
|
var deliveryMethod = this.product.deliveryMethod || 1
|
|
|
if (deliveryMethod > 1 && this.product.deliveryConfig) {
|
|
if (deliveryMethod > 1 && this.product.deliveryConfig) {
|
|
|
productData.deliveryMethod = deliveryMethod
|
|
productData.deliveryMethod = deliveryMethod
|