index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view>
  3. <view class="acea-row row-around nav">
  4. <template v-for="item in navList">
  5. <view :key="item.type" :class="['acea-row', 'row-middle', type === item.type ? 'on' : '']"
  6. @click="setType(item.type)">{{ item.name }}</view>
  7. </template>
  8. </view>
  9. <view style="height: 106rpx;"></view>
  10. <view class='coupon-list' v-if="couponsList.length">
  11. <view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index">
  12. <view class='money' :class='item.isUse ? "moneyGray" : "" '>
  13. <view>¥<text class='num'>{{item.money?Number(item.money):''}}</text></view>
  14. <view class="pic-num">满{{item.minPrice?Number(item.minPrice):''}}元可用</view>
  15. </view>
  16. <view class='text'>
  17. <view class='condition line2'>
  18. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""'
  19. v-if='item.useType===1'>通用</span>
  20. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""'
  21. v-else-if='item.useType===3'>品类</span>
  22. <span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""' v-else>商品</span>
  23. <span>{{item.name}}</span>
  24. </view>
  25. <view class='data acea-row row-between-wrapper'>
  26. <view v-if="item.day>0">领取后{{item.day}}天内可用</view>
  27. <view v-else>
  28. {{ item.useStartTimeStr&& item.useEndTimeStr ? item.useStartTimeStr + " - " + item.useEndTimeStr : ""}}
  29. </view>
  30. <view class='bnt gray' v-if="item.isUse==true">已领取</view>
  31. <view class='bnt bg-color' v-else @click='getCoupon(item.id,index)'>立即领取</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class='loadingicon acea-row row-center-wrapper'>
  37. <text class='loading iconfont icon-jiazai'
  38. :hidden='loading==false'></text>{{couponsList.length?loadTitle:''}}
  39. </view>
  40. <view class='noCommodity' v-if="!couponsList.length && isShow && !loading">
  41. <view class='pictrue'>
  42. <image src='../../../static/images/noCoupon.png'></image>
  43. </view>
  44. </view>
  45. <!-- #ifdef MP -->
  46. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  47. <!-- #endif -->
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. getCoupons,
  53. setCouponReceive
  54. } from '@/api/api.js';
  55. import {
  56. toLogin
  57. } from '@/libs/login.js';
  58. import {
  59. mapGetters
  60. } from "vuex";
  61. // #ifdef MP
  62. import authorize from '@/components/Authorize';
  63. // #endif
  64. export default {
  65. components: {
  66. // #ifdef MP
  67. authorize
  68. // #endif
  69. },
  70. data() {
  71. return {
  72. couponsList: [],
  73. loading: false,
  74. loadend: false,
  75. loadTitle: '加载更多', //提示语
  76. page: 1,
  77. limit: 20,
  78. isAuto: false, //没有授权的不会自动授权
  79. isShowAuth: false, //是否隐藏授权
  80. type: 1,
  81. isShow: false,
  82. navList: [{
  83. type: 1,
  84. name: '通用券',
  85. count: 0
  86. },
  87. {
  88. type: 2,
  89. name: '商品券',
  90. count: 0
  91. },
  92. {
  93. type: 3,
  94. name: '品类券',
  95. count: 0
  96. },
  97. ],
  98. count: 0
  99. };
  100. },
  101. computed: mapGetters(['isLogin']),
  102. watch: {
  103. isLogin: {
  104. handler: function(newV, oldV) {
  105. if (newV) {
  106. this.getUseCoupons();
  107. }
  108. },
  109. deep: true
  110. }
  111. },
  112. onLoad() {
  113. if (this.isLogin) {
  114. this.getUseCoupons();
  115. } else {
  116. toLogin();
  117. }
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function() {
  123. this.getUseCoupons();
  124. },
  125. methods: {
  126. onLoadFun() {
  127. this.getUseCoupons();
  128. },
  129. // 授权关闭
  130. authColse: function(e) {
  131. this.isShowAuth = e
  132. },
  133. getCoupon: function(id, index) {
  134. let that = this;
  135. let list = that.couponsList;
  136. let ids = [];
  137. ids.push(id);
  138. //领取优惠券
  139. setCouponReceive(id).then(function(res) {
  140. list[index].isUse = true;
  141. that.$set(that, 'couponsList', list);
  142. that.$util.Tips({
  143. title: '领取成功'
  144. });
  145. }, function(res) {
  146. return that.$util.Tips({
  147. title: res
  148. });
  149. })
  150. },
  151. /**
  152. * 获取领取优惠券列表
  153. */
  154. getUseCoupons: function() {
  155. let that = this
  156. if (that.loadend) return false;
  157. if (that.loading) return false;
  158. that.loading = true;
  159. getCoupons({
  160. page: that.page,
  161. limit: that.limit,
  162. type: that.type
  163. }).then(res => {
  164. let list = res.data,
  165. loadend = list.length < that.limit;
  166. let couponsList = that.$util.SplitArray(list, that.couponsList);
  167. that.$set(that, 'couponsList', couponsList);
  168. that.loadend = loadend;
  169. that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  170. that.page = that.page + 1;
  171. that.loading = false;
  172. that.isShow = true;
  173. }).catch(err => {
  174. that.loading = false;
  175. that.loadTitle = '加载更多';
  176. });
  177. },
  178. setType: function(type) {
  179. if (this.type !== type) {
  180. this.type = type;
  181. this.couponsList = [];
  182. this.page = 1;
  183. this.loadend = false;
  184. this.getUseCoupons();
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style scoped>
  191. .nav {
  192. position: fixed;
  193. top: 0;
  194. left: 0;
  195. width: 100%;
  196. height: 106rpx;
  197. background-color: #FFFFFF;
  198. font-size: 30rpx;
  199. color: #999999;
  200. z-index: 9;
  201. }
  202. .nav .acea-row {
  203. border-top: 5rpx solid transparent;
  204. border-bottom: 5rpx solid transparent;
  205. cursor: pointer;
  206. }
  207. .nav .acea-row.on {
  208. border-bottom-color: #E93323;
  209. color: #E93323;
  210. }
  211. .condition .line-title {
  212. width: 90rpx;
  213. padding: 0 10rpx;
  214. box-sizing: border-box;
  215. background: rgba(255, 247, 247, 1);
  216. border: 1px solid rgba(232, 51, 35, 1);
  217. opacity: 1;
  218. border-radius: 20rpx;
  219. font-size: 20rpx;
  220. color: #E83323;
  221. margin-right: 12rpx;
  222. }
  223. .condition .line-title.gray {
  224. border-color: #BBB;
  225. color: #bbb;
  226. background-color: #F5F5F5;
  227. }
  228. .coupon-list .pic-num {
  229. color: #FFFFFF;
  230. font-size: 24rpx;
  231. }
  232. </style>