index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="coupon_list">
  6. <view class="coupon_item" :style="'background-image: url(' + couponBg + ')'" v-for="(item, index) in dataList" :key="index">
  7. <view class="item_l" v-if="item.coupon.type == 1">
  8. <view class="price">
  9. <text class="unit">¥</text>
  10. {{ item.coupon.price }}
  11. </view>
  12. <view class="tips">满{{ item.coupon.base_price }}元可用</view>
  13. </view>
  14. <view class="item_l" v-if="item.coupon.type == 2">
  15. <view class="price">
  16. <text class="unit">¥</text>
  17. {{ item.coupon.price }}
  18. </view>
  19. <view class="tips">无门槛</view>
  20. </view>
  21. <view class="item_l" v-if="item.coupon.type == 3">
  22. <view class="price">{{ item.coupon.discount }}折</view>
  23. </view>
  24. <view class="item_r">
  25. <view class="item_r_l">
  26. <view class="quan_name">{{ item.coupon.title }}</view>
  27. <!-- <view class="quan_time">有效期至2021-12-31</view> -->
  28. </view>
  29. </view>
  30. <view class="item_status" @tap="onTakeCoupon" :data-id="item.id">领取</view>
  31. </view>
  32. <!-- <view class="coupon_item unable" style="background-image: url({{ couponBg }})">
  33. <view class="item_l">
  34. <view class="price"><text class="unit">¥</text>15</view>
  35. <view class="tips">无门槛</view>
  36. </view>
  37. <view class="item_r">
  38. <view class="item_r_l">
  39. <view class="quan_name">金额优惠券</view>
  40. <view class="quan_time">有效期至2021-12-31</view>
  41. </view>
  42. </view>
  43. <view class="item_status">已使用</view>
  44. </view> -->
  45. </view>
  46. </view>
  47. <!-- loading -->
  48. <!-- <van-overlay show="{{ loading }}" z-index="100">
  49. <van-loading custom-class="custom_loading" />
  50. </van-overlay> -->
  51. </view>
  52. </template>
  53. <script>
  54. // index.js
  55. let myPro = require('../../utils/wxRequest.js');
  56. let util = require('../../utils/util.js');
  57. export default {
  58. data() {
  59. return {
  60. couponBg: '/static/statics/img/quan_bg_tu.png',
  61. loading: false,
  62. // 全局loading
  63. dataList: []
  64. };
  65. },
  66. onLoad: function (options) {
  67. // Do some initialize when page load.
  68. let that = this;
  69. that.setData({
  70. couponBg: 'data:image/png;base64,' + uni.getFileSystemManager().readFileSync(that.couponBg, 'base64')
  71. });
  72. },
  73. onShow: function () {
  74. // Do something when page show.
  75. let that = this;
  76. that.getData();
  77. },
  78. onReady: function () {
  79. // Do something when page ready.
  80. },
  81. onHide: function () {
  82. // Do something when page hide.
  83. },
  84. onUnload: function () {
  85. // Do something when page close.
  86. },
  87. onPullDownRefresh: function () {
  88. // Do something when pull down.
  89. },
  90. onReachBottom: function () {
  91. // Do something when page reach bottom.
  92. },
  93. onPageScroll: function () {
  94. // Do something when page scroll
  95. },
  96. onResize: function () {
  97. // Do something when page resize
  98. },
  99. methods: {
  100. // 获取领券列表
  101. getData() {
  102. let that = this;
  103. myPro
  104. .wxRequest('user/v2/coupon/list', 'GET', {})
  105. .then((res) => {
  106. let list = res.result; // 无数据
  107. if (list.length == 0) {
  108. uni.showToast({
  109. title: '暂无更多数据',
  110. icon: 'none'
  111. });
  112. that.setData({
  113. dataList: []
  114. });
  115. } else {
  116. that.setData({
  117. dataList: list
  118. });
  119. }
  120. })
  121. .catch((err) => {
  122. console.log('报错信息', err);
  123. uni.showToast({
  124. title: err,
  125. icon: 'none'
  126. });
  127. });
  128. },
  129. // 领取优惠券
  130. onTakeCoupon(event) {
  131. let that = this;
  132. let id = event.currentTarget.dataset.id;
  133. let params = {
  134. coupon_rule_id: id
  135. };
  136. myPro
  137. .wxRequest('user/v2/coupon/receive', 'POST', params)
  138. .then((res) => {
  139. uni.showToast({
  140. title: res.msg,
  141. icon: 'none'
  142. });
  143. that.getData();
  144. })
  145. .catch((err) => {
  146. console.log('报错信息', err);
  147. uni.showToast({
  148. title: err,
  149. icon: 'none'
  150. });
  151. });
  152. }
  153. }
  154. };
  155. </script>
  156. <style>
  157. /**index.wxss**/
  158. .wrap {
  159. min-height: 100vh;
  160. background: #f6f6f6;
  161. }
  162. .coupon_item {
  163. padding-right: 30rpx;
  164. }
  165. </style>