|
|
@@ -234,8 +234,10 @@
|
|
|
<text class="picker-close" @click="closeCouponPicker">关闭</text>
|
|
|
</view>
|
|
|
<scroll-view scroll-y class="picker-list">
|
|
|
+ <!-- 已拥有优惠券 -->
|
|
|
+ <view class="picker-section-title" v-if="ownedCoupons.length > 0">已拥有优惠券</view>
|
|
|
<view
|
|
|
- v-for="coupon in availableCoupons"
|
|
|
+ v-for="coupon in ownedCoupons"
|
|
|
:key="coupon.id"
|
|
|
class="picker-item"
|
|
|
:class="selectedCoupon && selectedCoupon.id === coupon.id ? 'picker-item-active' : ''"
|
|
|
@@ -252,7 +254,31 @@
|
|
|
<text class="check-icon">✓</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view class="picker-empty" v-if="availableCoupons.length === 0">
|
|
|
+ <!-- 可兑换优惠券(需CF值) -->
|
|
|
+ <view class="picker-section-title" v-if="exchangeableCoupons.length > 0">
|
|
|
+ 可用CF值兑换(当前余额 {{ cfBalance }} CF)
|
|
|
+ </view>
|
|
|
+ <view
|
|
|
+ v-for="coupon in exchangeableCoupons"
|
|
|
+ :key="coupon.id"
|
|
|
+ class="picker-item picker-item-exchange"
|
|
|
+ >
|
|
|
+ <view class="picker-item-left">
|
|
|
+ <text class="picker-item-value">{{ formatPriceWithSymbol(coupon.value) }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="picker-item-right">
|
|
|
+ <text class="picker-item-name">{{ coupon.name }}</text>
|
|
|
+ <text class="picker-item-condition">{{ getConditionText(coupon.minSpend) }}</text>
|
|
|
+ </view>
|
|
|
+ <button
|
|
|
+ class="exchange-btn"
|
|
|
+ :disabled="coupon.exchanging"
|
|
|
+ @click.stop="doExchangeCoupon(coupon)"
|
|
|
+ >
|
|
|
+ {{ coupon.exchanging ? '兑换中...' : '兑换' }}
|
|
|
+ </button>
|
|
|
+ </view>
|
|
|
+ <view class="picker-empty" v-if="ownedCoupons.length === 0 && exchangeableCoupons.length === 0">
|
|
|
<text>暂无可用优惠券</text>
|
|
|
</view>
|
|
|
</scroll-view>
|
|
|
@@ -386,7 +412,7 @@
|
|
|
|
|
|
<script>
|
|
|
import config from '@/config.js'
|
|
|
-import { getCouponList, addressList, getProductRequiredFields, getMyMembership, productDetail } from '../../../utils/api.js'
|
|
|
+import { getCouponList, getCouponCheckoutList, addressList, getProductRequiredFields, getMyMembership, productDetail, getFamilyPlatformBalance, exchangeCouponByCf } from '../../../utils/api.js'
|
|
|
import { parseDate } from '@/utils/format.js'
|
|
|
|
|
|
export default {
|
|
|
@@ -403,6 +429,8 @@ export default {
|
|
|
submitting: false,
|
|
|
actualAmount: 0,
|
|
|
coupons: [],
|
|
|
+ exchangeableCoupons: [],
|
|
|
+ cfBalance: 0,
|
|
|
selectedCoupon: null,
|
|
|
showCouponPicker: false,
|
|
|
pointsUsed: 0,
|
|
|
@@ -449,6 +477,15 @@ export default {
|
|
|
pointsYuanEquivalent() {
|
|
|
return (this.pointsUsed / 100).toFixed(2)
|
|
|
},
|
|
|
+ ownedCoupons() {
|
|
|
+ var self = this
|
|
|
+ return this.coupons.filter(function(c) {
|
|
|
+ if (c.status && c.status !== 'AVAILABLE') return false
|
|
|
+ if (c.applicableTo && c.applicableTo !== 'ALL') return false
|
|
|
+ if (c.minSpend && c.minSpend > self.actualAmount) return false
|
|
|
+ return true
|
|
|
+ })
|
|
|
+ },
|
|
|
availableCoupons() {
|
|
|
var self = this
|
|
|
return this.coupons.filter(function(c) {
|
|
|
@@ -493,6 +530,8 @@ export default {
|
|
|
this.loadDefaultAddress()
|
|
|
this.loadRequiredFields()
|
|
|
this.loadCoupons()
|
|
|
+ this.loadExchangeableCoupons()
|
|
|
+ this.loadCfBalance()
|
|
|
this.loadUserPoints()
|
|
|
this.loadDeliveryConfig()
|
|
|
},
|
|
|
@@ -516,6 +555,58 @@ export default {
|
|
|
this.coupons = []
|
|
|
}
|
|
|
},
|
|
|
+ async loadExchangeableCoupons() {
|
|
|
+ try {
|
|
|
+ var productId = null
|
|
|
+ if (this.items && this.items.length > 0) {
|
|
|
+ productId = this.items[0].productId
|
|
|
+ }
|
|
|
+ var res = await getCouponCheckoutList({ productId: productId })
|
|
|
+ this.exchangeableCoupons = res.data || []
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载可兑换优惠券失败', e)
|
|
|
+ this.exchangeableCoupons = []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async loadCfBalance() {
|
|
|
+ try {
|
|
|
+ var res = await getFamilyPlatformBalance()
|
|
|
+ if (res.code === 200 && res.data) {
|
|
|
+ this.cfBalance = res.data.available || 0
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载CF余额失败', e)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async doExchangeCoupon(coupon) {
|
|
|
+ if (coupon.pointsPrice > this.cfBalance) {
|
|
|
+ uni.showToast({ title: 'CF值不足,当前可用 ' + this.cfBalance + ' CF值', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uni.showLoading({ title: '兑换中...' })
|
|
|
+ try {
|
|
|
+ var res = await exchangeCouponByCf({ couponId: coupon.id })
|
|
|
+ uni.hideLoading()
|
|
|
+ if (res.code === 200) {
|
|
|
+ uni.showToast({ title: '兑换成功', icon: 'success' })
|
|
|
+ // 从可兑换列表移除,加入已拥有列表
|
|
|
+ var idx = this.exchangeableCoupons.findIndex(function(c) { return c.id === coupon.id })
|
|
|
+ if (idx >= 0) {
|
|
|
+ this.exchangeableCoupons.splice(idx, 1)
|
|
|
+ }
|
|
|
+ coupon.isExchangeable = false
|
|
|
+ coupon.status = 'AVAILABLE'
|
|
|
+ this.coupons.push(coupon)
|
|
|
+ // 刷新余额
|
|
|
+ this.loadCfBalance()
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: res.message || '兑换失败', icon: 'none' })
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ uni.hideLoading()
|
|
|
+ uni.showToast({ title: '兑换失败', icon: 'none' })
|
|
|
+ }
|
|
|
+ },
|
|
|
openCouponPicker() {
|
|
|
if (this.availableCoupons.length === 0 && !this.selectedCoupon) {
|
|
|
uni.showToast({ title: '暂无可用优惠券', icon: 'none' })
|