coupon.vue 6.6 KB

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