|
|
@@ -20,7 +20,33 @@
|
|
|
:refresher-triggered="refreshing"
|
|
|
@refresherrefresh="onRefresh"
|
|
|
>
|
|
|
- <view v-if="loading" class="loading-wrap">
|
|
|
+ <view v-if="tabIndex === 3" class="coupon-list">
|
|
|
+ <view
|
|
|
+ v-for="(item, index) in exchangeableList"
|
|
|
+ :key="getCouponKey(item, index)"
|
|
|
+ class="coupon-card"
|
|
|
+ >
|
|
|
+ <view class="card-left">
|
|
|
+ <text class="card-value">{{ item.pointsPrice }}</text>
|
|
|
+ <text class="card-type-label">积分</text>
|
|
|
+ </view>
|
|
|
+ <view class="card-right">
|
|
|
+ <view class="card-header">
|
|
|
+ <text class="card-name">{{ item.name }}</text>
|
|
|
+ </view>
|
|
|
+ <text class="card-condition">{{ getCouponDesc(item) }}</text>
|
|
|
+ <text class="card-scope">{{ getScopeText(item.applicableTo) }}</text>
|
|
|
+ <text class="card-expiry">有效期至 {{ formatDate(item.validUntil) }}</text>
|
|
|
+ <button class="claim-btn" @click="doExchange(item)">兑换</button>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view v-if="!loading && exchangeableList.length === 0" class="empty-state">
|
|
|
+ <text class="empty-icon">🎫</text>
|
|
|
+ <text class="empty-text">暂无可用兑换的优惠券</text>
|
|
|
+ <text class="empty-hint">积分可以在商城中兑换优惠券</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view v-else-if="loading" class="loading-wrap">
|
|
|
<text class="loading-text">加载中...</text>
|
|
|
</view>
|
|
|
<view v-else-if="filteredList.length === 0" class="empty-state">
|
|
|
@@ -60,7 +86,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getCouponList, claimCoupon } from '../../utils/api.js'
|
|
|
+import { getCouponList, claimCoupon, getExchangeableCoupons, exchangeCoupon } from '../../utils/api.js'
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -68,10 +94,12 @@ export default {
|
|
|
tabs: [
|
|
|
{ name: '可使用', status: 'AVAILABLE' },
|
|
|
{ name: '已使用', status: 'USED' },
|
|
|
- { name: '已过期', status: 'EXPIRED' }
|
|
|
+ { name: '已过期', status: 'EXPIRED' },
|
|
|
+ { name: '可兑换' }
|
|
|
],
|
|
|
tabIndex: 0,
|
|
|
coupons: [],
|
|
|
+ exchangeableList: [],
|
|
|
loading: false,
|
|
|
refreshing: false
|
|
|
}
|
|
|
@@ -107,10 +135,12 @@ export default {
|
|
|
},
|
|
|
onShow() {
|
|
|
this.loadCoupons()
|
|
|
+ this.loadExchangeable()
|
|
|
},
|
|
|
onPullDownRefresh() {
|
|
|
this.refreshing = true
|
|
|
this.loadCoupons()
|
|
|
+ this.loadExchangeable()
|
|
|
},
|
|
|
methods: {
|
|
|
async loadCoupons() {
|
|
|
@@ -133,6 +163,49 @@ export default {
|
|
|
onScrollToLower() {},
|
|
|
switchTab(idx) {
|
|
|
this.tabIndex = idx
|
|
|
+ if (idx === 3) {
|
|
|
+ this.loadExchangeable()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ loadExchangeable() {
|
|
|
+ getExchangeableCoupons().then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.exchangeableList = res.data || []
|
|
|
+ }
|
|
|
+ }).catch(e => {
|
|
|
+ console.error('加载可兑换优惠券失败', e)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getCouponKey(item, index) {
|
|
|
+ return item.id + '-' + index
|
|
|
+ },
|
|
|
+ getCouponDesc(item) {
|
|
|
+ if (item.type === 'DISCOUNT') {
|
|
|
+ return '折扣券 ' + (item.discountRate / 100).toFixed(1) + '折'
|
|
|
+ }
|
|
|
+ return '立减 ' + (item.value / 100).toFixed(2) + '元'
|
|
|
+ },
|
|
|
+ doExchange(item) {
|
|
|
+ var self = this
|
|
|
+ uni.showModal({
|
|
|
+ title: '确认兑换',
|
|
|
+ content: '消耗 ' + item.pointsPrice + ' 积分兑换「' + item.name + '」?',
|
|
|
+ success: (r) => {
|
|
|
+ if (r.confirm) {
|
|
|
+ exchangeCoupon({ couponId: item.id }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ uni.showToast({ title: '兑换成功', icon: 'success' })
|
|
|
+ self.loadExchangeable()
|
|
|
+ self.loadCoupons()
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: res.message || '兑换失败', icon: 'none' })
|
|
|
+ }
|
|
|
+ }).catch(e => {
|
|
|
+ uni.showToast({ title: e.message || '兑换失败', icon: 'none' })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
canClaim(coupon) {
|
|
|
return this.tabIndex === 0 && (!coupon.status || coupon.status === 'AVAILABLE')
|