|
|
@@ -99,19 +99,6 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 积分兑换优惠券 -->
|
|
|
- <view class="coupon-exchange-section" v-if="productCoupons.length > 0">
|
|
|
- <text class="section-title">积分兑换优惠券</text>
|
|
|
- <view class="coupon-item" v-for="(item, index) in productCoupons" :key="getCouponKey(item, index)">
|
|
|
- <view class="coupon-info">
|
|
|
- <text class="coupon-name">{{ item.name }}</text>
|
|
|
- <text class="coupon-desc">{{ getCouponDesc(item) }}</text>
|
|
|
- </view>
|
|
|
- <view class="coupon-price">{{ item.pointsPrice }}积分</view>
|
|
|
- <button class="coupon-exchange-btn" @click="doExchangeCoupon(item)">兑换</button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
-
|
|
|
<view class="intro-section" v-if="product.intro">
|
|
|
<text class="section-title">商品介绍</text>
|
|
|
<mp-html :content="product.intro" :domain="apiBaseUrl" />
|
|
|
@@ -160,7 +147,7 @@
|
|
|
|
|
|
<script>
|
|
|
import config from '@/config.js'
|
|
|
-import { productDetail, productOrderCreate, productOrderPay, cartAdd, getShareQrCode, productSpecMap, getProductCoupons, exchangeCoupon, getMyMembership } from '@/utils/api.js'
|
|
|
+import { productDetail, productOrderCreate, productOrderPay, cartAdd, getShareQrCode, productSpecMap, getMyMembership } from '@/utils/api.js'
|
|
|
import MpHtml from '@/components/mp-html/mp-html.vue'
|
|
|
import ContentSharePoster from '@/components/ContentSharePoster.vue'
|
|
|
import shareMixin from '../../../components/share-mixin.js'
|
|
|
@@ -180,7 +167,6 @@ export default {
|
|
|
specGroups: [],
|
|
|
selectedSpecs: {},
|
|
|
selectedSku: null,
|
|
|
- productCoupons: [],
|
|
|
cfEarnedValue: 0,
|
|
|
// 会员身份(实时调 getMyMembership,FREE=非会员)
|
|
|
isMember: false,
|
|
|
@@ -379,6 +365,10 @@ export default {
|
|
|
if (res.code === 200 && res.data) {
|
|
|
that.product = res.data
|
|
|
that.bundleItems = (res.data && res.data.bundleItems) || []
|
|
|
+ // 计算可得CF值:floor(原价/100) × pointsMultiplier
|
|
|
+ if (res.data.price && res.data.pointsMultiplier) {
|
|
|
+ that.cfEarnedValue = Math.floor(res.data.price / 100) * res.data.pointsMultiplier;
|
|
|
+ }
|
|
|
// 赠品项初始化选择状态(响应式)
|
|
|
var cfgList = res.data.giftConfigs
|
|
|
if (cfgList && cfgList.length > 0) {
|
|
|
@@ -394,7 +384,6 @@ export default {
|
|
|
'/pages/discover-detail/product-detail/product-detail?id=' + that.product.id
|
|
|
)
|
|
|
that.loadSkuData(id)
|
|
|
- that.loadProductCoupons(parseInt(id))
|
|
|
}
|
|
|
}).catch(function() {
|
|
|
that.loading = false
|
|
|
@@ -418,60 +407,10 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- loadProductCoupons: function(productId) {
|
|
|
- if (!productId) return
|
|
|
- var that = this
|
|
|
- // 计算可得CF值:floor(原价/100) × pointsMultiplier
|
|
|
- if (that.product && that.product.price && that.product.pointsMultiplier) {
|
|
|
- that.cfEarnedValue = Math.floor(that.product.price / 100) * that.product.pointsMultiplier;
|
|
|
- }
|
|
|
- // 未登录(如从分享链接进入)时跳过优惠券查询,避免 /api/coupon/product 返回 401
|
|
|
- // 触发"登录已过期"并强制跳登录页;优惠券兑换是登录用户功能,未登录无需展示
|
|
|
- if (!uni.getStorageSync('token')) return
|
|
|
- getProductCoupons({ productId: productId }).then(function(res) {
|
|
|
- if (res.code === 200) {
|
|
|
- that.productCoupons = res.data || []
|
|
|
- }
|
|
|
- }).catch(function() {
|
|
|
- // 兑换券加载失败不阻塞页面
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- getCouponKey: function(item, index) {
|
|
|
- return item.id + '-' + index
|
|
|
- },
|
|
|
getBundleKey: function(item, idx) {
|
|
|
return item ? (item.childProductId || idx) : idx
|
|
|
},
|
|
|
|
|
|
- getCouponDesc: function(item) {
|
|
|
- if (item.type === 'DISCOUNT') {
|
|
|
- return '折扣券 ' + (item.discountRate / 100).toFixed(1) + '折'
|
|
|
- }
|
|
|
- return '立减 ' + (item.value / 100).toFixed(2) + '元'
|
|
|
- },
|
|
|
-
|
|
|
- doExchangeCoupon: function(item) {
|
|
|
- var that = this
|
|
|
- uni.showModal({
|
|
|
- title: '确认兑换',
|
|
|
- content: '消耗 ' + item.pointsPrice + ' 积分兑换「' + item.name + '」?',
|
|
|
- success: function(r) {
|
|
|
- if (!r.confirm) return
|
|
|
- exchangeCoupon({ couponId: item.id }).then(function(res) {
|
|
|
- if (res.code === 200) {
|
|
|
- uni.showToast({ title: '兑换成功', icon: 'success' })
|
|
|
- that.loadProductCoupons(that.product.id)
|
|
|
- } else {
|
|
|
- uni.showToast({ title: res.message || '兑换失败', icon: 'none' })
|
|
|
- }
|
|
|
- }).catch(function(e) {
|
|
|
- uni.showToast({ title: e.message || '兑换失败', icon: 'none' })
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
selectSpec: function(groupId, option) {
|
|
|
if (this.selectedSpecs[groupId] === option.id) {
|
|
|
this.$delete(this.selectedSpecs, groupId)
|