coupon.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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/img03.png' : '/static/img/img02.png'" mode="scaleToFill"></image>
  13. <view class="list-money-text">
  14. <view class="tit" :class="{ action: item._type == 2 }">
  15. <text>{{ item.coupon_price }}</text>
  16. </view>
  17. <view class="price">
  18. <text>满{{ item.use_min_price }}元</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/order.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. let da = data.map(e => {
  122. e.coupon_price = +e.coupon_price.replace(',', '');
  123. e.use_min_price = +e.use_min_price.replace(',', '');
  124. return e;
  125. });
  126. navItem.orderList = navItem.orderList.concat(da);
  127. console.log(navItem.orderList);
  128. navItem.page++;
  129. if (navItem.limit == data.length) {
  130. //判断是否还有数据, 有改为 more, 没有改为noMore
  131. navItem.loadingType = 'more';
  132. return;
  133. } else {
  134. //判断是否还有数据, 有改为 more, 没有改为noMore
  135. navItem.loadingType = 'noMore';
  136. }
  137. uni.hideLoading();
  138. this.$set(navItem, 'loaded', true);
  139. })
  140. .catch(e => {
  141. console.log(e);
  142. });
  143. },
  144. //swiper 切换
  145. changeTab(e) {
  146. this.tabCurrentIndex = e.target.current;
  147. this.loadData('tabChange');
  148. },
  149. //顶部tab点击
  150. tabClick(index) {
  151. this.tabCurrentIndex = index;
  152. }
  153. }
  154. };
  155. </script>
  156. <style lang="scss">
  157. // 卡卷可用时颜色
  158. $card-color-action: #fc4141;
  159. .swiper-box {
  160. height: calc(100% - 40px);
  161. .tab-content {
  162. padding: 25rpx 0px;
  163. font-size: 28rpx;
  164. color: #1b1b1b;
  165. }
  166. }
  167. .row {
  168. border-radius: 15rpx;
  169. margin: 0 25rpx;
  170. margin-bottom: 25rpx;
  171. height: 200rpx;
  172. overflow: hidden;
  173. background-color: #ffffff;
  174. .list-interval {
  175. border: 1px dashed $border-color-light;
  176. height: 100%;
  177. .top,
  178. .bottom {
  179. border-radius: 100rpx;
  180. width: 30rpx;
  181. height: 30rpx;
  182. position: absolute;
  183. background-color: $page-color-base;
  184. right: -15rpx;
  185. }
  186. .top {
  187. top: -18rpx;
  188. }
  189. .bottom {
  190. bottom: -18rpx;
  191. }
  192. }
  193. .list-money {
  194. height: 100%;
  195. image {
  196. height: 100%;
  197. width: 20rpx;
  198. }
  199. .list-money-text {
  200. width: 220rpx;
  201. padding: 0 25rpx;
  202. text-align: center;
  203. color: $font-color-light;
  204. .tit {
  205. padding: 15rpx 0rpx;
  206. font-size: 55rpx;
  207. font-weight: bold;
  208. &.action {
  209. color: $card-color-action;
  210. }
  211. }
  212. .price {
  213. padding-bottom: 25rpx;
  214. }
  215. }
  216. }
  217. .row_list_right {
  218. flex-grow: 1;
  219. padding-left: 25rpx;
  220. line-height: 1;
  221. .right_time {
  222. color: $font-color-light;
  223. font-size: $font-sm;
  224. }
  225. .right_use {
  226. margin: 15rpx 0;
  227. padding: 10rpx;
  228. width: 140rpx;
  229. text-align: center;
  230. border-radius: 50rpx;
  231. color: #fff;
  232. font-size: $font-sm - 4rpx;
  233. &.action {
  234. background-color: $card-color-action;
  235. }
  236. &.noAction {
  237. background-color: $color-gray;
  238. }
  239. }
  240. .right_top {
  241. margin: 15rpx 0;
  242. font-size: $font-lg;
  243. height: 50rpx;
  244. color: $font-color-light;
  245. .right_name {
  246. font-weight: bold;
  247. }
  248. .right_title {
  249. font-weight: bold;
  250. &.action {
  251. color: $font-color-base;
  252. }
  253. }
  254. }
  255. }
  256. .iconlocation {
  257. font-size: 36rpx;
  258. color: $font-color-light;
  259. }
  260. }
  261. page,
  262. .content {
  263. background: $page-color-base;
  264. height: 100%;
  265. }
  266. .navbar {
  267. display: flex;
  268. height: 40px;
  269. padding: 0 5px;
  270. background: #fff;
  271. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  272. position: relative;
  273. z-index: 10;
  274. .nav-item {
  275. flex: 1;
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. height: 100%;
  280. font-size: 15px;
  281. color: $font-color-dark;
  282. position: relative;
  283. &.current {
  284. color: #bc253a;
  285. &:after {
  286. content: '';
  287. position: absolute;
  288. left: 50%;
  289. bottom: 0;
  290. transform: translateX(-50%);
  291. width: 44px;
  292. height: 0;
  293. border-bottom: 2px solid #bc253a;
  294. }
  295. }
  296. }
  297. }
  298. /* load-more */
  299. .uni-load-more {
  300. display: flex;
  301. flex-direction: row;
  302. height: 80rpx;
  303. align-items: center;
  304. justify-content: center;
  305. }
  306. </style>