敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.7 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="优惠券" leftClick @leftClick="$utils.navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- 标签页 -->
  6. <uv-sticky bgColor="#fff" v-if="!usein">
  7. <uv-tabs :list="tabs" @change="changeTab" :scrollable="false" lineColor="#019245"
  8. :activeStyle="{color: '#019245' }" lineWidth="80" lineHeight="6" :inactiveStyle="{color: '#333'}"
  9. :itemStyle="{height: '90rpx'}" />
  10. </uv-sticky>
  11. <!-- 优惠券列表 -->
  12. <view class="coupon-list">
  13. <template v-if="currentTab === 0">
  14. <coupon-item v-for="coupon in unusedCoupons" :key="coupon.id" :coupon="coupon" @use="useCoupon" />
  15. <view v-if="unusedCoupons.length == 0" style="padding-top: 200rpx;">
  16. <uv-empty text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  17. style="padding-top: 200rpx;" icon="list" />
  18. </view>
  19. </template>
  20. <template v-if="currentTab === 1">
  21. <coupon-item v-for="coupon in usedCoupons" :key="coupon.id" :coupon="coupon" />
  22. <view v-if="usedCoupons.length == 0" style="padding-top: 200rpx;">
  23. <uv-empty text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  24. style="padding-top: 200rpx;" icon="list" />
  25. </view>
  26. </template>
  27. <template v-if="currentTab === 2">
  28. <coupon-item v-for="coupon in expiredCoupons" :key="coupon.id" :coupon="coupon" />
  29. <view v-if="expiredCoupons.length == 0" style="padding-top: 200rpx;">
  30. <uv-empty text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  31. style="padding-top: 200rpx;" icon="list" />
  32. </view>
  33. </template>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import navbar from '@/components/base/navbar.vue'
  39. import CouponItem from '@/components/coupon/CouponItem.vue'
  40. import { mapState } from 'vuex'
  41. export default {
  42. components: {
  43. navbar,
  44. CouponItem
  45. },
  46. data() {
  47. return {
  48. tabs: [
  49. { name: '未使用' },
  50. { name: '已使用' },
  51. { name: '已过期' }
  52. ],
  53. currentTab: 0,
  54. allCoupons: [],
  55. usein: false // 是否是跳进来选择使用的情况
  56. }
  57. },
  58. computed: {
  59. ...mapState(['couponData']),
  60. unusedCoupons() {
  61. return (this.allCoupons || []).filter(coupon => coupon.status === "0")
  62. },
  63. usedCoupons() {
  64. return (this.allCoupons || []).filter(coupon => coupon.status === "1")
  65. },
  66. expiredCoupons() {
  67. return (this.allCoupons || []).filter(coupon => coupon.status === "2")
  68. }
  69. },
  70. onLoad(args) {
  71. this.getCoupon()
  72. if (args.usein === '1') {
  73. this.usein = true
  74. }
  75. },
  76. methods: {
  77. // 切换标签页
  78. changeTab(item) {
  79. this.currentTab = item.index
  80. this.getCoupon()
  81. },
  82. // 使用优惠券
  83. useCoupon(coupon) {
  84. if (this.usein) {
  85. uni.showModal({
  86. title: '提示',
  87. content: `确定使用面值${coupon.discount}元的优惠券吗?`,
  88. confirmColor: '#019245',
  89. success: (res) => {
  90. // 模拟使用优惠券
  91. uni.showLoading({
  92. title: '使用中...'
  93. })
  94. setTimeout(() => {
  95. uni.hideLoading()
  96. if (res.confirm) {
  97. uni.showToast({
  98. title: '使用成功',
  99. icon: 'success'
  100. })
  101. this.$store.commit('setCouponData', coupon)
  102. this.$utils.navigateBack()
  103. }
  104. }, 300)
  105. },
  106. fail: (err) => {
  107. console.log('err', err)
  108. }
  109. })
  110. }else {
  111. this.$utils.navigateTo('/pages/index/category')
  112. }
  113. },
  114. // 获取优惠卷
  115. getCoupon() {
  116. this.$api('queryCouponList', {
  117. pageNo: 1,
  118. pageSize: 10000,
  119. status: this.currentTab
  120. }, res => {
  121. if (res.code === 200){
  122. this.allCoupons = res.result.records
  123. }
  124. })
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .page {
  131. .tabs-container {
  132. .coupon-list {
  133. padding: 30rpx;
  134. }
  135. .empty-tip {
  136. text-align: center;
  137. color: $uni-color-third;
  138. padding: 100rpx 0;
  139. font-size: 28rpx;
  140. }
  141. }
  142. }
  143. </style>