index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view>
  3. <view class="navTabBox">
  4. <!-- <view class="longTab">
  5. <view class="tab-item" :class='isUsed == 0 ? "" : "on"' @click="getUseCoupons()"><text>未使用</text></view>
  6. <view class="tab-item" :class='isUsed !== 0 ? "" : "on"' @click="getUseCoupons()"><text>已使用/已过期</text></view>
  7. </view> -->
  8. <view class="longTab">
  9. <view class="tab-item" v-for="(item,index) in tabList" :key="index" :class="{'on':index == tabIndex-1}" @click="bindTab(index)"><text>{{item.title}}</text></view>
  10. </view>
  11. </view>
  12. <view class='coupon-list' v-if="couponsList.length">
  13. <view class='item acea-row row-center-wrapper' v-for='(item,index) in couponsList' :key="index" @click="goStore(item)">
  14. <view class='money' :class='item.status == 0 ? "" : "moneyGray"'>
  15. <view>¥<text class='num'>{{item.coupon_price}}</text></view>
  16. <view class="pic-num">满{{ item.use_min_price }}元可用</view>
  17. </view>
  18. <view class='text'>
  19. <view class='condition line1'>
  20. <view class="line-title" :class="item.status === 0 ? 'bg-color-huic' : 'bg-color-check'" v-if="item.coupon && item.coupon.type === 0">店铺券</view>
  21. <view class="line-title" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'" v-else-if="item.applicable_type === 1">品类券</view>
  22. <view class="line-title" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'" v-else>商品券</view>
  23. <view>{{item.coupon_title}}</view>
  24. </view>
  25. <view class='data acea-row row-between-wrapper'>
  26. <view>{{item.start_time | timeYMD}}-{{item.end_time | timeYMD}}</view>
  27. <view v-if="item.status==0">
  28. <view class='bnt gray bg-color'>可使用</view>
  29. <!-- <view v-else class='bnt gray'>未到期</view> -->
  30. </view>
  31. <view class='bnt gray' v-if="item.status==1">已使用</view>
  32. <view class='bnt gray' v-if="item.status==2">已过期</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class='noCommodity' v-if="!couponsList.length && loading==true">
  38. <view class='pictrue'>
  39. <image src='/static/images/noCoupon.png'></image>
  40. </view>
  41. </view>
  42. <!-- #ifdef MP -->
  43. <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
  44. <!-- #endif -->
  45. </view>
  46. </template>
  47. <script>
  48. let app = getApp();
  49. import {
  50. getUserCoupons
  51. } from '@/api/api.js';
  52. import {
  53. toLogin
  54. } from '@/libs/login.js';
  55. import {
  56. mapGetters
  57. } from "vuex";
  58. // #ifdef MP
  59. import authorize from '@/components/Authorize';
  60. // #endif
  61. export default {
  62. components: {
  63. // #ifdef MP
  64. authorize
  65. // #endif
  66. },
  67. data() {
  68. return {
  69. tabIndex:1,
  70. couponsList: [],
  71. loading: false,
  72. isAuto: false, //没有授权的不会自动授权
  73. isShowAuth: false ,//是否隐藏授权
  74. isUsed: 0,
  75. hide_mer_status: app.globalData.hide_mer_status,
  76. tabList:[
  77. {
  78. title:'未使用'
  79. },
  80. {
  81. title:'已使用/已过期'
  82. }
  83. ],
  84. limit:15,
  85. page:1,
  86. isScroll:true
  87. };
  88. },
  89. computed: mapGetters(['isLogin']),
  90. filters: {
  91. timeYMD: function (value) {
  92. if(value){
  93. var newDate=/\d{4}-\d{1,2}-\d{1,2}/g.exec(value)
  94. return newDate[0]
  95. }
  96. }
  97. },
  98. onLoad() {
  99. if (this.isLogin) {
  100. this.getUseCoupons();
  101. } else {
  102. // #ifdef H5 || APP-PLUS
  103. toLogin();
  104. // #endif
  105. // #ifdef MP
  106. this.isAuto = true;
  107. this.$set(this, 'isShowAuth', true)
  108. // #endif
  109. }
  110. },
  111. mounted: function() {
  112. const app = getApp();
  113. this.$nextTick(() => {
  114. this.hide_mer_status = app.globalData.hide_mer_status
  115. });
  116. },
  117. methods: {
  118. /**
  119. * 授权回调
  120. */
  121. onLoadFun: function() {
  122. this.isShowAuth = false;
  123. // this.getUseCoupons();
  124. },
  125. // 授权关闭
  126. authColse: function(e) {
  127. this.isShowAuth = e
  128. },
  129. bindTab(index){
  130. this.tabIndex = index+1
  131. this.page =1
  132. this.isScroll = true
  133. this.couponsList = []
  134. this.getUseCoupons()
  135. },
  136. goStore(item){
  137. if(this.hide_mer_status != 1 && item.status==0){
  138. uni.navigateTo({
  139. url:`/pages/store/home/index?id=${item.mer_id}`
  140. })
  141. }
  142. },
  143. /**
  144. * 获取领取优惠券列表
  145. */
  146. getUseCoupons: function() {
  147. let that = this;
  148. if(!this.isScroll) return
  149. getUserCoupons({
  150. statusTag: this.tabIndex,
  151. page:this.page,
  152. limit:this.limit
  153. }).then(res => {
  154. that.loading = true;
  155. that.couponsList = that.couponsList.concat(res.data.list)
  156. that.isScroll = that.couponsList.length<res.data.count
  157. that.page++
  158. })
  159. }
  160. },
  161. onReachBottom() {
  162. this.getUseCoupons()
  163. }
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. .navTabBox{
  168. background: #fff;
  169. height: 90rpx;
  170. }
  171. .longTab{
  172. display: flex;
  173. text-align: center;
  174. }
  175. .tab-item{
  176. width: 50%;
  177. display: inline-block;
  178. line-height: 90rpx;
  179. text{
  180. position: relative;
  181. display: inline-block;
  182. }
  183. }
  184. .tab-item.on{
  185. color: #EA3424;
  186. text{
  187. &:after{
  188. content: "";
  189. display: inline-block;
  190. width: 90%;
  191. height: 3rpx;
  192. background: #EA3424;
  193. position: absolute;
  194. left: 5%;
  195. bottom: 0;
  196. }
  197. }
  198. }
  199. .money {
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: center;
  203. }
  204. .pic-num {
  205. color: #ffffff;
  206. font-size: 20rpx;
  207. }
  208. .coupon-list .item .text .condition {
  209. display: flex;
  210. align-items: center;
  211. }
  212. .condition .line-title {
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. width: 90rpx;
  217. height: 40rpx !important;
  218. padding: 0 10rpx;
  219. -webkit-box-sizing: border-box;
  220. box-sizing: border-box;
  221. background: rgba(255, 247, 247, 1);
  222. border: 1px solid rgba(232, 51, 35, 1);
  223. opacity: 1;
  224. border-radius: 22rpx;
  225. font-size: 20rpx !important;
  226. color: #e83323;
  227. margin-right: 12rpx;
  228. }
  229. .noCommodity{
  230. width: 100%;
  231. .pictrue{
  232. margin: 0 auto;
  233. }
  234. }
  235. </style>