mycard.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!-- 我的优惠券(我的卡包) -->
  2. <template>
  3. <view class="wanl-order-list">
  4. <!-- 顶部Tab:未使用/已使用/已过期 -->
  5. <view class="navbar">
  6. <view class="nav-item text-df" v-for="(item, index) in navList" :key="item.state"
  7. :class="{ current: tabCurrentIndex === index }" @tap="tabClick(index)">
  8. {{ item.text }}
  9. </view>
  10. </view>
  11. <!-- 滑动切换 -->
  12. <swiper :current="tabCurrentIndex" style="height: calc(100% - 60rpx)" duration="300" @change="changeTab">
  13. <swiper-item class="tab-content" v-for="(tag, key) in navList" :key="tag.state">
  14. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  15. <!-- 空白页 -->
  16. <wanl-empty :text="$t('coupon.noCoupons')" src="ticket_default3x" v-if="tag.loaded === true && tag.cardList.length === 0" />
  17. <!-- 优惠券列表 -->
  18. <view class="wanl-coupon">
  19. <view v-for="(coupon, seat) in tag.cardList" :key="coupon.id"
  20. :class="[coupon.state == 1 ? coupon.type : 'wanl-gray']" class="item margin-bj radius-bock"
  21. @tap="onDetails(coupon)">
  22. <image :src="couponBg" class="coupon-bg"></image>
  23. <image v-if="coupon.state == 2" :src="couponUsed" class="coupon-sign"></image>
  24. <image v-if="coupon.state == 3" :src="couponExpired" class="coupon-sign"></image>
  25. <!-- 左侧:金额/折扣 -->
  26. <view class="item-left">
  27. <block v-if="coupon.type == 'reduction' || (coupon.type == 'vip' && coupon.usertype == 'reduction')">
  28. <view class="colour">
  29. <text class="text-price"></text>
  30. <text class="price">{{ Number(coupon.price) }}</text>
  31. </view>
  32. <view class="cu-tag wanl-gray-dark radius text-sm">
  33. {{ $t('mall.fullReduction', [Number(coupon.limit), Number(coupon.price)]) }}
  34. </view>
  35. </block>
  36. <block v-if="coupon.type == 'discount' || (coupon.type == 'vip' && coupon.usertype == 'discount')">
  37. <view class="colour">
  38. <text class="price">{{ Number(coupon.discount) }}</text>
  39. <text class="discount">{{ $t('mall.discountSuffix') }}</text>
  40. </view>
  41. <view class="cu-tag wanl-gray-dark radius text-sm">
  42. {{ $t('mall.fullDiscount', [Number(coupon.limit), Number(coupon.discount)]) }}
  43. </view>
  44. </block>
  45. <block v-if="coupon.type == 'shipping'">
  46. <view class="colour">
  47. <text class="price">{{ $t('mall.freeShipping') }}</text>
  48. </view>
  49. <view class="cu-tag wanl-gray-dark radius text-sm">
  50. {{ $t('mall.freeShippingFull', [Number(coupon.limit)]) }}
  51. </view>
  52. </block>
  53. </view>
  54. <!-- 右侧:店铺+名称+有效期+操作 -->
  55. <view class="item-right padding-bj">
  56. <view class="shop" @tap="onShop(coupon.shop_id)">
  57. <view class="name">
  58. <text class="wlIcon-dianpu margin-right-xs"></text> {{ coupon.shop.shopname }}
  59. </view>
  60. <view><text class="wlIcon-fanhui2"></text></view>
  61. </view>
  62. <view class="title">
  63. <view class="cu-tag sm radius margin-right-xs tagstyle">{{ coupon.type_text }}</view>
  64. <text class="text-cut wanl-gray text-min">{{ coupon.name }}</text>
  65. </view>
  66. <view class="content text-min">
  67. <view class="wanl-gray">
  68. <view v-if="coupon.pretype == 'fixed'">
  69. <text class="wlIcon-dot"></text>{{ $t('coupon.validUntil', [coupon.enddate]) }}
  70. </view>
  71. <view v-else-if="coupon.pretype == 'appoint' && coupon.validity != 0">
  72. <text class="wlIcon-dot"></text>{{ $t('coupon.validDays', [coupon.validity]) }}
  73. </view>
  74. <view v-else>
  75. <text class="wlIcon-dot"></text>{{ $t('coupon.permanent') }}
  76. </view>
  77. </view>
  78. <view class="cu-btn sm round line-colour" v-if="coupon.state == 1" @tap.stop="onApply(coupon.id)">
  79. {{ $t('coupon.useNow') }}
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. <uni-load-more :status="tag.loadingType" />
  86. <view class="edgeInsetBottom"></view>
  87. </scroll-view>
  88. </swiper-item>
  89. </swiper>
  90. </view>
  91. </template>
  92. <script>
  93. import { pullCouponMyList } from '@/features/mall/mall-gateway'
  94. export default {
  95. data() {
  96. return {
  97. tabCurrentIndex: 0,
  98. navList: [
  99. { state: 1, text: this.$t('coupon.unused'), loadingType: 'more', current_page: 1, cardList: [] },
  100. { state: 2, text: this.$t('coupon.used'), loadingType: 'more', current_page: 1, cardList: [] },
  101. { state: 3, text: this.$t('coupon.expired'), loadingType: 'more', current_page: 1, cardList: [] }
  102. ],
  103. couponBg: '/static/coupon/bg_coupon_3x.png',
  104. couponUsed: '/static/coupon/img_coupon_beused_3x.png',
  105. couponExpired: '/static/coupon/img_coupon_failure_3x.png'
  106. }
  107. },
  108. onLoad() {
  109. this.loadData()
  110. },
  111. methods: {
  112. /** swiper切换 */
  113. changeTab(e) {
  114. this.tabCurrentIndex = e.target.current
  115. this.loadData('tabChange')
  116. },
  117. /** 顶部tab点击 */
  118. tabClick(index) {
  119. this.tabCurrentIndex = index
  120. },
  121. /** 加载优惠券列表 */
  122. async loadData(source) {
  123. let index = this.tabCurrentIndex
  124. let navItem = this.navList[index]
  125. let state = navItem.state
  126. if (navItem.loadingType == 'noMore') return
  127. if (source === 'tabChange' && navItem.loaded === true) return
  128. if (navItem.loadingType === 'loading') return
  129. navItem.loadingType = 'loading'
  130. try {
  131. const res = await pullCouponMyList({ state, page: navItem.current_page })
  132. navItem.current_page = res.currentPage
  133. if (res.lastPage === res.currentPage) {
  134. navItem.loadingType = 'noMore'
  135. } else {
  136. navItem.loadingType = 'more'
  137. navItem.current_page++
  138. }
  139. res.rows.forEach(item => {
  140. navItem.cardList.push(item)
  141. })
  142. this.$set(navItem, 'loaded', true)
  143. } catch (e) {
  144. console.error('[coupon mycard] loadData', e)
  145. navItem.loadingType = 'more'
  146. }
  147. },
  148. /** 去使用优惠券 */
  149. onApply(id) {
  150. uni.navigateTo({ url: `/pages/user/coupon/apply?id=${id}&state=true` })
  151. },
  152. /** 查看优惠券详情 */
  153. onDetails(data) {
  154. // 预留详情页跳转
  155. },
  156. /** 跳转店铺 */
  157. onShop(id) {
  158. uni.navigateTo({ url: `/pages/shop/index?id=${id}` })
  159. }
  160. }
  161. }
  162. </script>
  163. <style>
  164. page {
  165. height: 100%;
  166. }
  167. </style>