coupon.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="coupon">
  3. <u-tabs
  4. class="coupon-tabs"
  5. lineColor="#F39800"
  6. :activeStyle="{
  7. color: '#F39800',
  8. fontWeight: 'bold',
  9. }"
  10. :current="currentTab"
  11. :list="tabs"
  12. @click="handleTabs"
  13. />
  14. <view class="list">
  15. <couponItem
  16. v-for="item in list"
  17. :key="item.id"
  18. :data="item"
  19. :config="itemConfig"
  20. @on-click="handleItem(item)"
  21. />
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import couponItem from "./couponItem.vue";
  27. import { getCouponList, getCoupon } from "@/common/api/coupon";
  28. export default {
  29. components: {
  30. couponItem,
  31. },
  32. data() {
  33. const tabs = [
  34. {
  35. name: "未使用",
  36. type: "myUses",
  37. itemConfig: {
  38. btnText: "选择使用",
  39. disabled: false,
  40. btnPlain: true,
  41. },
  42. },
  43. {
  44. name: "已使用",
  45. type: "myUsed",
  46. itemConfig: {
  47. btnText: "已使用",
  48. disabled: true,
  49. btnPlain: false,
  50. },
  51. },
  52. {
  53. name: "已过期",
  54. type: "myExpired",
  55. itemConfig: {
  56. btnText: "已过期",
  57. disabled: true,
  58. btnPlain: false,
  59. },
  60. },
  61. {
  62. name: "可领取",
  63. type: "index",
  64. itemConfig: {
  65. btnText: "立即领取",
  66. disabled: false,
  67. btnPlain: false,
  68. },
  69. },
  70. ];
  71. return {
  72. currentTab: 0,
  73. tabs,
  74. list: [],
  75. };
  76. },
  77. computed: {
  78. activeTabItem() {
  79. return this.tabs[this.currentTab];
  80. },
  81. itemConfig() {
  82. return this.activeTabItem.itemConfig;
  83. },
  84. },
  85. onShow() {
  86. this._getCouponList();
  87. },
  88. methods: {
  89. _getCouponList() {
  90. console.log("this.activeTabItem", this.activeTabItem);
  91. getCouponList(this.activeTabItem.type, {
  92. page: 1,
  93. pageSize: 100,
  94. }).then(({ data = {} }) => {
  95. console.log("data=>getCouponList", data);
  96. this.list = data.list || [];
  97. });
  98. },
  99. handleTabs({ index }) {
  100. console.log("item", index);
  101. this.list = [];
  102. this.currentTab = index;
  103. this._getCouponList();
  104. },
  105. handleItem(data) {
  106. if (this.activeTabItem.type === "index") {
  107. getCoupon({ id: data.id }).then(({ data }) => {
  108. console.log("data=>getCoupon", data);
  109. uni.$u.toast("领取成功");
  110. this._getCouponList();
  111. });
  112. }else if(this.activeTabItem.type === "myUses") {
  113. uni.navigateTo({
  114. url: '/pages/productCenter/productCenter',
  115. })
  116. }
  117. },
  118. },
  119. };
  120. </script>
  121. <style lang="scss" scoped>
  122. .coupon {
  123. display: flex;
  124. flex-direction: column;
  125. height: 100%;
  126. overflow: hidden;
  127. ::v-deep {
  128. .u-tabs {
  129. height: 94rpx;
  130. background-color: #fff;
  131. .u-tabs__wrapper__nav {
  132. height: 94rpx;
  133. }
  134. .u-tabs__wrapper__nav__line {
  135. border-radius: 0;
  136. }
  137. .vue-ref-in-for {
  138. flex: 1 !important;
  139. }
  140. }
  141. }
  142. .list {
  143. flex: 1;
  144. padding: 20rpx 20rpx 0;
  145. overflow-y: auto;
  146. }
  147. }
  148. </style>