You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
5.4 KiB

3 years ago
  1. <template>
  2. <view class="app">
  3. <view class="nav-wrap">
  4. <mix-nav-bar :navs="navs" :counts="navCounts" :current="navCurrent" @onChange="onNavBarChange"></mix-nav-bar>
  5. </view>
  6. <mescroll-body
  7. ref="mescrollRef"
  8. @init="mescrollInit"
  9. :top="84"
  10. @down="downCallback"
  11. :up="upOption"
  12. @up="loadData"
  13. >
  14. <view class="coupon-item" :class="{disabled: item.state !== 1}" v-for="(item,index) in list" :key="index">
  15. <view class="con">
  16. <view class="left">
  17. <text class="title clamp">{{item.title}}</text>
  18. <text class="time">有效期至 {{ item.end_time | date('Y-m-d H:i') }}</text>
  19. </view>
  20. <view class="right">
  21. <text class="price">{{item.coupon_money}}</text>
  22. <text>{{ item.total_money }}可用</text>
  23. </view>
  24. <view class="circle l"></view>
  25. <view class="circle r"></view>
  26. </view>
  27. <view class="bot row">
  28. <text class="tips">平台所有商品可用</text>
  29. <view v-if="item.state === 1" class="btn center active" @click="toUseCoupon">
  30. <text>立即使用</text>
  31. </view>
  32. <view v-else class="btn center">
  33. <text>{{ item.state_text }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </mescroll-body>
  38. <mix-loading v-if="isLoading" :mask="true"></mix-loading>
  39. </view>
  40. </template>
  41. <script>
  42. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
  43. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  44. export default {
  45. components: {
  46. MescrollBody
  47. },
  48. mixins: [MescrollMixin],
  49. data() {
  50. return {
  51. navCounts: [], //订单数量
  52. navs: [{name: '全部'}, {name: '已使用'}, {name: '已过期'}],
  53. navCurrent: 0, //当前tab
  54. upOption:{
  55. page: {
  56. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  57. size: 10 // 每页数据的数量
  58. },
  59. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  60. },
  61. list: [] //订单列表
  62. }
  63. },
  64. onLoad() {
  65. },
  66. methods: {
  67. async loadData(e){
  68. this.mescroll && this.mescroll.removeEmpty();
  69. const sendData = {
  70. state: this.navCurrent,
  71. offset: (e.num - 1) * e.size,
  72. limit: e.size
  73. }
  74. const res = await this.$request('coupon', 'getUserCouponList', sendData);
  75. const curList = res.data;
  76. if(e.num === 1){
  77. //第一页清空数据重载
  78. this.list = [];
  79. this.loaded && curList.forEach(item=> {item.loaded = true})
  80. if(curList.length > 0){
  81. uni.pageScrollTo({
  82. scrollTop: 0,
  83. duration: 0
  84. })
  85. }
  86. }
  87. this.list = this.list.concat(curList); //追加新数据
  88. this.mescroll.endSuccess(curList.length); //结束加载状态
  89. },
  90. //刷新列表
  91. refreshList(showLoading){
  92. this.mescroll && this.mescroll.resetUpScroll(false)
  93. if(showLoading !== false){
  94. this.isLoading = true;
  95. }
  96. this.$store.dispatch('getOrderCount');
  97. },
  98. mescrollInit(mescroll){
  99. this.mescroll = mescroll;
  100. setTimeout(()=>{
  101. this.refreshList();
  102. }, 10)
  103. },
  104. //tab切换
  105. onNavBarChange(current){
  106. if(this.navCurrent === current){
  107. return;
  108. }
  109. this.navCurrent = current;
  110. this.refreshList();
  111. },
  112. toUseCoupon(){
  113. uni.switchTab({
  114. url: '/pages/tabbar/home'
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. page{
  122. background-color: #f7f7f7;
  123. }
  124. </style>
  125. <style scoped lang="scss">
  126. .coupon-item{
  127. display: flex;
  128. flex-direction: column;
  129. margin: 20rpx 24rpx;
  130. background: #fff;
  131. &.disabled{
  132. .title{
  133. color: #999;
  134. }
  135. .price{
  136. color: #bbb;
  137. }
  138. }
  139. .con{
  140. display: flex;
  141. align-items: center;
  142. position: relative;
  143. height: 140rpx;
  144. padding: 0 30rpx;
  145. &:after{
  146. position: absolute;
  147. left: 0;
  148. bottom: 0;
  149. content: '';
  150. width: 100%;
  151. height: 0;
  152. border-bottom: 1px dashed #e5e5e5;
  153. transform: scaleY(50%);
  154. }
  155. }
  156. .left{
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: center;
  160. flex: 1;
  161. overflow: hidden;
  162. height: 100rpx;
  163. }
  164. .title{
  165. font-size: 32rpx;
  166. color: #333;
  167. margin-bottom: 24rpx;
  168. }
  169. .time{
  170. font-size: 24rpx;
  171. color: #999;
  172. }
  173. .right{
  174. display: flex;
  175. flex-direction: column;
  176. justify-content: center;
  177. align-items: center;
  178. margin-left: 30rpx;
  179. font-size: 24rpx;
  180. color: #666;
  181. height: 100rpx;
  182. }
  183. .price{
  184. margin-bottom: 14rpx;
  185. font-size: 50rpx;
  186. color: $base-color;
  187. font-weight: 700;
  188. &:before{
  189. content: '¥';
  190. font-size: 34rpx;
  191. }
  192. }
  193. .bot{
  194. height: 80rpx;
  195. padding: 0 20rpx 0 30rpx;
  196. .tips{
  197. flex: 1;
  198. font-size: 24rpx;
  199. color: #999;
  200. }
  201. .btn{
  202. min-width: 140rpx;
  203. height: 54rpx;
  204. padding: 0 26rpx;
  205. font-size: 22rpx;
  206. color: #999;
  207. background-color: #eee;
  208. border-radius: 100rpx;
  209. &.active{
  210. color: #fff;
  211. background-color: $base-color;
  212. }
  213. }
  214. }
  215. .circle{
  216. position: absolute;
  217. left: -6rpx;
  218. bottom: -10rpx;
  219. z-index: 10;
  220. width: 20rpx;
  221. height: 20rpx;
  222. background: #f3f3f3;
  223. border-radius: 100px;
  224. &.r{
  225. left: auto;
  226. right: -6rpx;
  227. }
  228. }
  229. }
  230. </style>