couponList.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="container">
  3. <view class="coupon-tab">
  4. <u-tabs :list="tabList" :is-scroll="false" :current="tabIndex" @change="changeTabs" font-size="30" active-color="#52A63A"
  5. inactive-color="#666666" :bold="false" height="90" bar-width="120"></u-tabs>
  6. </view>
  7. <view class="coupon-box" v-if="tabIndex == 0">
  8. <view class="coupon-row" v-for="(site, index2) in couponList1" :key="index2">
  9. <view class="coupon-mask" v-if="site.status == 0"></view>
  10. <view class="coupon-left">
  11. <view class="coupon-left-price"><text style="font-size: 16px;">¥</text>{{site.discountAmount}}</view>
  12. <view class="coupon-left-text">满减金额</view>
  13. </view>
  14. <view class="coupon-info">
  15. <view class="coupon-text1">{{site.couponName}}</view>
  16. <view class="coupon-text1" style="margin-bottom: 4px;">满{{site.fullAmount}}减{{site.discountAmount}}</view>
  17. <view class="coupon-text2">{{site.couponType == 1 ? '仅限用于' + site.name + '的店铺' : '通用优惠券'}}</view>
  18. <view class="coupon-text2" style="color: #999999;">有效期:{{site.termDate}}</view>
  19. </view>
  20. </view>
  21. <u-divider :color="isOver ? '#909399' : '#51A539'" :border-color="isOver ? '#909399' : '#51A539'" @click="handleLoadMore()">
  22. <u-loading mode="circle" v-if="loadingData"></u-loading>{{loadingData ? '加载中' : (isOver ? '没有更多了' : '点击加载更多')}}
  23. </u-divider>
  24. </view>
  25. <view class="coupon-box" v-if="tabIndex == 1">
  26. <view class="coupon-row" v-for="(site, index2) in couponList2" :key="index2">
  27. <view class="coupon-left">
  28. <view class="coupon-left-price"><text style="font-size: 16px;">¥</text>{{site.discountAmount}}</view>
  29. <view class="coupon-left-text">满减金额</view>
  30. </view>
  31. <view class="coupon-info">
  32. <view class="coupon-text1">{{site.couponName}}</view>
  33. <view class="coupon-text1" style="margin-bottom: 4px;">满{{site.fullAmount}}减{{site.discountAmount}}</view>
  34. <view class="coupon-text2">{{site.couponType == 1 ? '仅限用于' + site.name + '的店铺' : ''}}</view>
  35. <view class="coupon-text2" style="color: #999999;">有效期:{{site.term}}</view>
  36. </view>
  37. </view>
  38. <u-divider :color="isOver ? '#909399' : '#51A539'" :border-color="isOver ? '#909399' : '#51A539'" @click="handleLoadMore()">
  39. <u-loading mode="circle" v-if="loadingData"></u-loading>{{loadingData ? '加载中' : (isOver ? '没有更多了' : '点击加载更多')}}
  40. </u-divider>
  41. </view>
  42. <view class="coupon-box" v-if="tabIndex == 2">
  43. <view class="coupon-row" v-for="(site, index2) in couponList3" :key="index2">
  44. <view class="coupon-mask"></view>
  45. <view class="coupon-left">
  46. <view class="coupon-left-price"><text style="font-size: 16px;">¥</text>{{site.discountAmount}}</view>
  47. <view class="coupon-left-text">满减金额</view>
  48. </view>
  49. <view class="coupon-info">
  50. <view class="coupon-text1">{{site.couponName}}</view>
  51. <view class="coupon-text1" style="margin-bottom: 4px;">满{{site.fullAmount}}减{{site.discountAmount}}</view>
  52. <view class="coupon-text2">{{site.couponType == 1 ? '仅限用于' + site.name + '的店铺' : ''}}</view>
  53. <view class="coupon-text2" style="color: #999999;">有效期:{{site.term}}</view>
  54. </view>
  55. </view>
  56. <u-divider :color="isOver ? '#909399' : '#51A539'" :border-color="isOver ? '#909399' : '#51A539'" @click="handleLoadMore()">
  57. <u-loading mode="circle" v-if="loadingData"></u-loading>{{loadingData ? '加载中' : (isOver ? '没有更多了' : '点击加载更多')}}
  58. </u-divider>
  59. </view>
  60. <u-top-tips ref="uTips"></u-top-tips>
  61. </view>
  62. </template>
  63. <script>
  64. const NET = require('@/utils/request')
  65. const API = require('@/config/api')
  66. export default {
  67. data() {
  68. return {
  69. tabIndex: 0,
  70. tabList: [{
  71. name: '我的券'
  72. },
  73. {
  74. name: '未使用'
  75. },
  76. {
  77. name: '已使用'
  78. }
  79. ],
  80. loadingData: false,
  81. isOver: false,
  82. pageIndex1: 1,
  83. couponList1: [],
  84. pageIndex2: 1,
  85. couponList2: [],
  86. pageIndex3: 1,
  87. couponList3: [],
  88. }
  89. },
  90. onLoad() {
  91. this.getList()
  92. },
  93. onPullDownRefresh() {
  94. this['pageIndex' + (this.tabIndex + 1)] = 1
  95. this['couponList' + (this.tabIndex + 1)] = []
  96. this.getList('refresh')
  97. },
  98. methods: {
  99. // 切换tab
  100. changeTabs(index) {
  101. this.tabIndex = index
  102. this['pageIndex' + (index + 1)] = 1
  103. this['couponList' + (index + 1)] = []
  104. this.isOver = false
  105. this.loadingData = false
  106. this.getList()
  107. },
  108. // 懒加载
  109. handleLoadMore() {
  110. if (!this.isOver) {
  111. this['pageIndex' + (this.tabIndex + 1)]++
  112. this.getList()
  113. }
  114. },
  115. // 获取列表数据
  116. getList(refresh) {
  117. this.loadingData = true
  118. NET.request(API.getCouponList, {
  119. isUse: this.tabIndex == 0 ? null : (this.tabIndex == 1 ? 0 : 1),
  120. pageIndex: this['pageIndex' + (this.tabIndex + 1)],
  121. pageSize: 10,
  122. }, 'POST').then(res => {
  123. if (refresh == 'refresh') {
  124. uni.stopPullDownRefresh();
  125. }
  126. if (res.isSuccess) {
  127. if (res.data.list.length) {
  128. this.loadingData = false
  129. this.isOver = res.data.list.length != 10
  130. this['couponList' + (this.tabIndex + 1)] = this['couponList' + (this.tabIndex + 1)].concat(res.data.list)
  131. }
  132. }
  133. }).catch(error => {
  134. this.loadingData = false
  135. this.$refs.uTips.show({
  136. title: error.data.msg,
  137. type: 'warning',
  138. })
  139. })
  140. },
  141. },
  142. }
  143. </script>
  144. <style>
  145. page {
  146. background-color: #f7f7f7;
  147. }
  148. </style>
  149. <style lang="less" scoped>
  150. page {
  151. width: 100%;
  152. height: 100%;
  153. }
  154. .container {
  155. width: 100%;
  156. height: 100%;
  157. float: left;
  158. background-color: #f7f7f7;
  159. overflow-y: auto;
  160. .coupon-tab {
  161. width: 100%;
  162. height: 45px;
  163. float: left;
  164. background-color: #FFFFFF;
  165. margin-bottom: 16px;
  166. }
  167. .coupon-row {
  168. width: calc(100% - 32px);
  169. height: 105px;
  170. float: left;
  171. margin: 0 16px 10px 16px;
  172. border-radius: 10px;
  173. background: #FFFFFF;
  174. box-shadow: 0px 0px 10px 0px rgba(103, 103, 103, 0.3);
  175. overflow: hidden;
  176. position: relative;
  177. .coupon-mask {
  178. width: 100%;
  179. height: 100%;
  180. position: absolute;
  181. background-color: rgba(0, 0, 0, 0.3);
  182. }
  183. .coupon-left {
  184. width: 107px;
  185. height: 105px;
  186. box-sizing: border-box;
  187. padding-right: 10px;
  188. float: left;
  189. background-size: 107px 105px;
  190. background-position: center;
  191. background-repeat: no-repeat;
  192. background-image: url(@/static/images/couponHead.png);
  193. .coupon-left-price {
  194. width: 100%;
  195. height: 24px;
  196. float: left;
  197. margin: 28px 0 12px 0;
  198. font-size: 24px;
  199. font-family: PingFang SC;
  200. color: #FFFFFF;
  201. line-height: 24px;
  202. text-align: center;
  203. }
  204. .coupon-left-text {
  205. width: 100%;
  206. height: 20px;
  207. float: left;
  208. color: #FFFFFF;
  209. font-size: 12px;
  210. font-family: PingFang SC;
  211. line-height: 20px;
  212. text-align: center;
  213. }
  214. }
  215. .coupon-info {
  216. width: calc(100% - 115px);
  217. height: 100%;
  218. float: right;
  219. box-sizing: border-box;
  220. padding: 16px 0 12px 0;
  221. .coupon-text1 {
  222. width: 100%;
  223. height: 20px;
  224. float: right;
  225. font-size: 15px;
  226. font-family: PingFang SC;
  227. color: #333333;
  228. line-height: 20px;
  229. white-space: nowrap;
  230. text-overflow: ellipsis;
  231. overflow: hidden;
  232. }
  233. .coupon-text2 {
  234. width: 100%;
  235. height: 18px;
  236. float: right;
  237. font-size: 13px;
  238. font-family: PingFang SC;
  239. color: #EB5F2F;
  240. line-height: 18px;
  241. white-space: nowrap;
  242. text-overflow: ellipsis;
  243. overflow: hidden;
  244. }
  245. }
  246. }
  247. }
  248. /deep/.u-divider {
  249. background-color: transparent !important;
  250. }
  251. </style>