mycoupon.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. title="我的优惠券"
  5. :placeholder="true"
  6. :autoBack="false"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="tabs-wrap">
  12. <u-tabs
  13. :list="tabsList"
  14. lineColor="#3B49BF"
  15. :activeStyle="{color:'#333','font-weight': '600','font-size':'30rpx'}"
  16. :inactiveStyle="{color:'#999'}"
  17. :itemStyle="{width:'28%','padding-bottom':'20rpx'}"
  18. @click="tabsClick"></u-tabs>
  19. </view>
  20. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  21. <view class="page-wrap">
  22. <view class="coupon-activity u-flex u-row-right" @click="$u.route('/center/couponlist',{})" :style="{backgroundImage:`url(${staticUrl}/img/coupon-activity.png)`}">
  23. <view class="u-flex">
  24. 活动中心
  25. <u-icon name="arrow-right" color="#fff" size="30rpx"></u-icon>
  26. </view>
  27. </view>
  28. <view class="coupon-list">
  29. <view class="item"
  30. :class="{disable:item.status==2}"
  31. :style="{backgroundImage:`url(${staticUrl}/img/coupon-active-bg.png)`,filter:item.status!=1?'grayscale(100%)':''}" v-for="item in dataList" :key="item.id">
  32. <view class="content u-flex">
  33. <view class="left">
  34. <view class="quota">
  35. <text v-if="item.type == 1">¥</text>
  36. <text class="number" :class="{'small': String(item.quota).length>=3}">{{item.quota}}</text>
  37. <text v-if="item.type == 2">%</text>
  38. </view>
  39. <view class="condition" v-if="item.useThresholdType == 2">
  40. 消费满{{item.useThresholdAmount}}可用
  41. </view>
  42. </view>
  43. <view class="center">
  44. <view class="name" :class="{'small': String(item.couponName).length>=9}">{{item.couponName}}</view>
  45. <view class="tip">
  46. 有效期至 {{item.endTime||''}}
  47. </view>
  48. </view>
  49. <view class="right">
  50. <text class="btn" @click="couponClick(item)" v-if="item.status == 1">去使用</text>
  51. <text class="btn" @click="couponClick(item)" v-if="item.status == 2">已使用</text>
  52. <text class="btn" @click="couponClick(item)" v-if="item.status == 3">已过期</text>
  53. <text class="btn" @click="couponClick(item)" v-if="item.status == 4">已作废</text>
  54. <!-- <view class="time">
  55. <view class="">{{item.startTime}}</view>
  56. <view class="">{{item.endTime}}</view>
  57. </view> -->
  58. </view>
  59. </view>
  60. <view class="type" v-if="item.type == 1">满减券</view>
  61. <view class="type" v-else-if="item.type == 2">折扣卷</view>
  62. <image class="status-img" :src="staticUrl+'/img/coupon-status-shiyong.png'" v-if="item.status == 2"></image>
  63. <image class="status-img" :src="staticUrl+'/img/coupon-status-guoqi.png'" v-if="item.status == 3"></image>
  64. <image class="status-img" :src="staticUrl+'/img/coupon-status-guoqi.png'" v-if="item.status == 4"></image>
  65. </view>
  66. </view>
  67. </view>
  68. </mescroll-body>
  69. </view>
  70. </template>
  71. <script>
  72. // 引入mescroll-mixins.js
  73. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  74. export default {
  75. mixins: [MescrollMixin], // 使用mixin
  76. data() {
  77. return {
  78. staticUrl:this.$commonConfig.staticUrl,
  79. downOption: {},
  80. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  81. upOption: {
  82. page: {
  83. size: 10 // 每页数据的数量,默认10
  84. },
  85. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  86. empty: {
  87. tip: '暂无相关数据'
  88. }
  89. },
  90. tabsList:[{name:'待使用',recordType:1},{name:'已使用',recordType:2},{name:'已过期',recordType:3}],
  91. params:{
  92. status:''
  93. },
  94. activeIndex:0,
  95. dataList: []
  96. }
  97. },
  98. onShow() {
  99. },
  100. onLoad() {
  101. this.params.status = this.tabsList[this.activeIndex].recordType;
  102. // console.log('1111', this.tabsList[this.activeIndex]);
  103. },
  104. methods: {
  105. leftClick(e){
  106. let pages = getCurrentPages();
  107. if(pages.length==1){
  108. uni.$u.route('/pages/index/index')
  109. }else{
  110. uni.navigateBack()
  111. };
  112. },
  113. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  114. downCallback(){
  115. this.mescroll.resetUpScroll();
  116. },
  117. /*上拉加载的回调*/
  118. upCallback(page) {
  119. // 此处可以继续请求其他接口
  120. // if(page.num == 1){
  121. // // 请求其他接口...
  122. // }
  123. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  124. // if(!this.params.id){
  125. // this.mescroll.endErr()
  126. // return // 此处return,先获取xx
  127. // }
  128. let pageNum = page.num; // 页码, 默认从1开始
  129. let pageSize = page.size; // 页长, 默认每页10条isAsc:0//时间排序 0:降序 1:升序 (默认星级降序排序)
  130. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  131. this.$u.api.myCouponList(this.params).then(data => {
  132. console.log('data',JSON.parse(JSON.stringify(data)));
  133. // 接口返回的当前页数据列表 (数组)
  134. let curPageData = data.data.rows;
  135. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  136. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  137. let curPageLen = curPageData.length;
  138. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  139. // let totalPage = data.data.data.totalPage;
  140. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  141. let totalSize = data.data.total;
  142. // 接口返回的是否有下一页 (true/false)
  143. // let hasNext = data.xxx;
  144. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  145. //设置列表数据
  146. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  147. this.dataList = this.dataList.concat(curPageData); //追加新数据
  148. // 请求成功,隐藏加载状态
  149. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  150. // this.mescroll.endByPage(curPageLen, totalPage);
  151. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  152. this.mescroll.endBySize(curPageLen, totalSize);
  153. }).catch(err => {
  154. this.mescroll.endErr()
  155. console.log(err)
  156. });
  157. },
  158. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  159. reloadList() {
  160. this.mescroll.resetUpScroll();
  161. },
  162. tabsClick(item){
  163. this.params.status = item.recordType;
  164. this.reloadList()
  165. // console.log('item',item);
  166. },
  167. couponClick(item){
  168. if(item.status==1){
  169. uni.$u.route('/pages/index/index');
  170. }
  171. }
  172. }
  173. }
  174. </script>
  175. <style>
  176. page{
  177. background-color: #f5f5f5;
  178. }
  179. </style>
  180. <style lang="scss" scoped>
  181. .tabs-wrap{
  182. background-color: #fff;
  183. margin-bottom: 10rpx;
  184. }
  185. .coupon-activity{
  186. height: 120rpx;
  187. background-size: 100%;
  188. color: #fff;
  189. font-weight: 500;
  190. font-size: 24rpx;
  191. padding-right: 15rpx;
  192. margin-bottom: 14rpx;
  193. }
  194. </style>