敢为人鲜小程序前端代码仓库
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.

130 lines
3.1 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 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">
  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. <uv-empty v-if="unusedCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  16. style="padding-top: 100rpx;" icon="list" />
  17. </template>
  18. <template v-if="currentTab === 1">
  19. <coupon-item v-for="coupon in usedCoupons" :key="coupon.id" :coupon="coupon" />
  20. <uv-empty v-if="usedCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  21. style="padding-top: 100rpx;" icon="list" />
  22. </template>
  23. <template v-if="currentTab === 2">
  24. <coupon-item v-for="coupon in expiredCoupons" :key="coupon.id" :coupon="coupon" />
  25. <uv-empty v-if="expiredCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  26. style="padding-top: 100rpx;" icon="list" />
  27. </template>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import navbar from '@/components/base/navbar.vue'
  33. import CouponItem from '@/components/coupon/CouponItem.vue'
  34. import { unusedCoupons, usedCoupons, expiredCoupons } from '@/static/js/mockCoupon.js'
  35. export default {
  36. components: {
  37. navbar,
  38. CouponItem
  39. },
  40. data() {
  41. return {
  42. tabs: [
  43. { name: '未使用' },
  44. { name: '已使用' },
  45. { name: '已过期' }
  46. ],
  47. currentTab: 0,
  48. unusedCoupons: [],
  49. usedCoupons: [],
  50. expiredCoupons: []
  51. }
  52. },
  53. onLoad() {
  54. // 从mock数据获取优惠券列表
  55. this.unusedCoupons = unusedCoupons
  56. this.usedCoupons = usedCoupons
  57. // 暂时 没有已过期的优惠卷
  58. // this.expiredCoupons = expiredCoupons
  59. this.getCoupon()
  60. },
  61. methods: {
  62. // 切换标签页
  63. changeTab(item) {
  64. this.currentTab = item.index
  65. },
  66. // 使用优惠券
  67. useCoupon(coupon) {
  68. uni.showModal({
  69. title: '提示',
  70. content: `确定使用面值${coupon.amount}元的优惠券吗?`,
  71. success: (res) => {
  72. // 模拟使用优惠券
  73. uni.showLoading({
  74. title: '使用中...'
  75. })
  76. setTimeout(() => {
  77. uni.hideLoading()
  78. uni.showToast({
  79. title: '使用成功',
  80. icon: 'success'
  81. })
  82. setTimeout(() => {
  83. if (res.confirm) {
  84. this.$utils.navigateTo('/pages/order/index')
  85. }
  86. }, 1000)
  87. }, 1000)
  88. }
  89. })
  90. },
  91. // 获取优惠卷
  92. getCoupon() {
  93. this.$api('queryCouponList', {
  94. pageNo: 1,
  95. pageSize: 10000
  96. }, res => {
  97. if (res.code === 200){
  98. console.log(res);
  99. }
  100. })
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .page {
  107. .tabs-container {
  108. .coupon-list {
  109. padding: 30rpx;
  110. }
  111. .empty-tip {
  112. text-align: center;
  113. color: $uni-color-third;
  114. padding: 100rpx 0;
  115. font-size: 28rpx;
  116. }
  117. }
  118. }
  119. </style>