coupon.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  5. </view>
  6. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  7. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  8. <!-- 空白页 -->
  9. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  10. <view v-for="(item, index) in tabItem.orderList" :key="index" class="row flex">
  11. <view class="list-money flex">
  12. <image :src="item._type == 2 ? '/static/img/img08.png' : '/static/img/img07.png'" mode="scaleToFill"></image>
  13. <view class="list-money-text">
  14. <view class="tit" :class="{ action: item._type == 2 }">
  15. <text>{{ +item.coupon_price.replace(',', '') }}</text>
  16. </view>
  17. <view class="price">
  18. <text>满{{ +item.use_min_price.replace(',', '') }}元</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="list-interval position-relative">
  23. <view class="bottom"></view>
  24. <view class="top"></view>
  25. </view>
  26. <view class="row_list_right">
  27. <view class="right_top">
  28. <!-- <text class="right_name">【满减券】</text> -->
  29. <text class="right_title" :class="{ action: item._type == 2 }">{{ item.coupon_title }}</text>
  30. </view>
  31. <view class="right_time">
  32. <text>{{ item._add_time }}-{{ item._end_time }}</text>
  33. </view>
  34. <view class="right_use action" v-if="item._type == 2">
  35. <text>{{ item._msg }}</text>
  36. </view>
  37. <view class="right_use noAction" v-if="item._type == 0">
  38. <text>{{ item._msg }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  43. </swiper-item>
  44. </swiper>
  45. </view>
  46. </template>
  47. <script>
  48. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  49. import empty from '@/components/empty';
  50. import { getCouponsList } from '@/api/coupon.js';
  51. export default {
  52. components: {
  53. uniLoadMore,
  54. empty
  55. },
  56. data() {
  57. return {
  58. tabCurrentIndex: 0,
  59. navList: [
  60. {
  61. state: 0,
  62. text: '全部',
  63. loadingType: 'more',
  64. orderList: [],
  65. page: 1, //当前页数
  66. limit: 10 //每次信息条数
  67. },
  68. {
  69. state: 1,
  70. text: '未使用',
  71. loadingType: 'more',
  72. orderList: [],
  73. page: 1, //当前页数
  74. limit: 10 //每次信息条数
  75. },
  76. {
  77. state: 2,
  78. text: '已使用',
  79. loadingType: 'more',
  80. orderList: [],
  81. page: 1, //当前页数
  82. limit: 10 //每次信息条数
  83. }
  84. ]
  85. };
  86. },
  87. onLoad(options) {
  88. this.loadData();
  89. },
  90. methods: {
  91. // 返回首页
  92. navTo() {
  93. uni.switchTab({
  94. url: '/pages/index/index'
  95. });
  96. },
  97. //获取订单列表
  98. loadData(source) {
  99. //这里是将订单挂载到tab列表下
  100. let index = this.tabCurrentIndex;
  101. let navItem = this.navList[index];
  102. let state = navItem.state;
  103. if (source === 'tabChange' && navItem.loaded === true) {
  104. //tab切换只有第一次需要加载数据
  105. return;
  106. }
  107. if (navItem.loadingType === 'loading') {
  108. //防止重复加载
  109. return;
  110. }
  111. // 修改当前对象状态为加载中
  112. navItem.loadingType = 'loading';
  113. getCouponsList(
  114. {
  115. page: navItem.page,
  116. limit: navItem.limit
  117. },
  118. index
  119. )
  120. .then(({ data }) => {
  121. navItem.orderList = navItem.orderList.concat(data);
  122. console.log(navItem.orderList);
  123. navItem.page++;
  124. if (navItem.limit == data.length) {
  125. //判断是否还有数据, 有改为 more, 没有改为noMore
  126. navItem.loadingType = 'more';
  127. return;
  128. } else {
  129. //判断是否还有数据, 有改为 more, 没有改为noMore
  130. navItem.loadingType = 'noMore';
  131. }
  132. uni.hideLoading();
  133. this.$set(navItem, 'loaded', true);
  134. })
  135. .catch(e => {
  136. console.log(e);
  137. });
  138. },
  139. //swiper 切换
  140. changeTab(e) {
  141. this.tabCurrentIndex = e.target.current;
  142. this.loadData('tabChange');
  143. },
  144. //顶部tab点击
  145. tabClick(index) {
  146. this.tabCurrentIndex = index;
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss">
  152. // 卡卷可用时颜色
  153. $card-color-action: #fc4141;
  154. .swiper-box {
  155. height: calc(100% - 40px);
  156. .tab-content {
  157. padding: 25rpx 0px;
  158. font-size: 28rpx;
  159. color: #1b1b1b;
  160. }
  161. }
  162. .row {
  163. border-radius: 15rpx;
  164. margin: 0 25rpx;
  165. margin-bottom: 25rpx;
  166. height: 200rpx;
  167. overflow: hidden;
  168. background-color: #ffffff;
  169. .list-interval {
  170. border: 1px dashed $border-color-light;
  171. height: 100%;
  172. .top,
  173. .bottom {
  174. border-radius: 100rpx;
  175. width: 30rpx;
  176. height: 30rpx;
  177. position: absolute;
  178. background-color: $page-color-base;
  179. right: -15rpx;
  180. }
  181. .top {
  182. top: -18rpx;
  183. }
  184. .bottom {
  185. bottom: -18rpx;
  186. }
  187. }
  188. .list-money {
  189. height: 100%;
  190. image {
  191. height: 100%;
  192. width: 20rpx;
  193. }
  194. .list-money-text {
  195. width: 220rpx;
  196. padding: 0 25rpx;
  197. text-align: center;
  198. color: $font-color-light;
  199. .tit {
  200. padding: 15rpx 0rpx;
  201. font-size: 55rpx;
  202. font-weight: bold;
  203. &.action {
  204. color: $card-color-action;
  205. }
  206. }
  207. .price {
  208. padding-bottom: 25rpx;
  209. }
  210. }
  211. }
  212. .row_list_right {
  213. flex-grow: 1;
  214. padding-left: 25rpx;
  215. line-height: 1;
  216. .right_time {
  217. color: $font-color-light;
  218. font-size: $font-sm;
  219. }
  220. .right_use {
  221. margin: 15rpx 0;
  222. padding: 10rpx;
  223. width: 140rpx;
  224. text-align: center;
  225. border-radius: 50rpx;
  226. color: #fff;
  227. font-size: $font-sm - 4rpx;
  228. &.action {
  229. background-color: $card-color-action;
  230. }
  231. &.noAction {
  232. background-color: $color-gray;
  233. }
  234. }
  235. .right_top {
  236. margin: 15rpx 0;
  237. font-size: $font-lg;
  238. height: 50rpx;
  239. color: $font-color-light;
  240. .right_name {
  241. font-weight: bold;
  242. }
  243. .right_title {
  244. font-weight: bold;
  245. &.action {
  246. color: $font-color-base;
  247. }
  248. }
  249. }
  250. }
  251. .iconlocation {
  252. font-size: 36rpx;
  253. color: $font-color-light;
  254. }
  255. }
  256. page,
  257. .content {
  258. background: $page-color-base;
  259. height: 100%;
  260. }
  261. .navbar {
  262. display: flex;
  263. height: 40px;
  264. padding: 0 5px;
  265. background: #fff;
  266. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  267. position: relative;
  268. z-index: 10;
  269. .nav-item {
  270. flex: 1;
  271. display: flex;
  272. justify-content: center;
  273. align-items: center;
  274. height: 100%;
  275. font-size: 15px;
  276. color: $font-color-dark;
  277. position: relative;
  278. &.current {
  279. color: #bc253a;
  280. &:after {
  281. content: '';
  282. position: absolute;
  283. left: 50%;
  284. bottom: 0;
  285. transform: translateX(-50%);
  286. width: 44px;
  287. height: 0;
  288. border-bottom: 2px solid #bc253a;
  289. }
  290. }
  291. }
  292. }
  293. /* load-more */
  294. .uni-load-more {
  295. display: flex;
  296. flex-direction: row;
  297. height: 80rpx;
  298. align-items: center;
  299. justify-content: center;
  300. }
  301. </style>