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.

205 lines
4.4 KiB

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