consumer.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  9. <!-- 空白页 -->
  10. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  11. <!-- 订单列表 -->
  12. <view v-for="(item, index) in tabItem.orderList" :key="index" class="order-item flex">
  13. <view class="title-box">
  14. <view class="title">
  15. <text>{{ item.mark }}</text>
  16. </view>
  17. <view class="time">
  18. <text>{{ item.add_time }}</text>
  19. </view>
  20. </view>
  21. <view class="money">
  22. <text>{{ (item.pm == 0 ? '-' : '+') + item.number }}</text>
  23. </view>
  24. </view>
  25. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  26. </scroll-view>
  27. </swiper-item>
  28. </swiper>
  29. </view>
  30. </template>
  31. <script>
  32. import { consumerList } from '@/api/integral.js';
  33. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  34. import empty from '@/components/empty';
  35. export default {
  36. components: {
  37. empty,
  38. uniLoadMore
  39. },
  40. onReady() {
  41. },
  42. data() {
  43. return {
  44. tabCurrentIndex: 0,
  45. navList: [
  46. {
  47. state: 0,
  48. text: '全部',
  49. loadingType: 'more',
  50. orderList: [],
  51. page: 1, //当前页数
  52. limit: 10 //每次信息条数
  53. },
  54. ],
  55. };
  56. },
  57. onShow() {
  58. // 载入积分数据
  59. this.loadData();
  60. },
  61. methods: {
  62. // 页面跳转
  63. navto(e) {
  64. uni.navigateTo({
  65. url: e
  66. });
  67. },
  68. //获取收入支出信息
  69. async loadData(source) {
  70. //这里是将订单挂载到tab列表下
  71. let index = this.tabCurrentIndex;
  72. let navItem = this.navList[index];
  73. let state = navItem.state;
  74. if (source === 'tabChange' && navItem.loaded === true) {
  75. //tab切换只有第一次需要加载数据
  76. return;
  77. }
  78. if (navItem.loadingType === 'loading') {
  79. //防止重复加载
  80. return;
  81. }
  82. // 修改当前对象状态为加载中
  83. navItem.loadingType = 'loading';
  84. consumerList(
  85. {
  86. page: navItem.page,
  87. limit: navItem.limit
  88. }
  89. )
  90. .then(({ data }) => {
  91. if (data.length > 0) {
  92. navItem.orderList = navItem.orderList.concat(data);
  93. navItem.page++;
  94. }
  95. if (navItem.limit == data.length) {
  96. //判断是否还有数据, 有改为 more, 没有改为noMore
  97. navItem.loadingType = 'more';
  98. return;
  99. } else {
  100. //判断是否还有数据, 有改为 more, 没有改为noMore
  101. navItem.loadingType = 'noMore';
  102. }
  103. uni.hideLoading();
  104. this.$set(navItem, 'loaded', true);
  105. })
  106. .catch(e => {
  107. console.log(e);
  108. });
  109. },
  110. //swiper 切换
  111. changeTab(e) {
  112. this.tabCurrentIndex = e.target.current;
  113. this.loadData('tabChange');
  114. },
  115. //顶部tab点击
  116. tabClick(index) {
  117. this.tabCurrentIndex = index;
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. page {
  124. background: #ffffff;
  125. height: 100%;
  126. }
  127. .navbar {
  128. display: flex;
  129. height: 40px;
  130. padding: 0 5px;
  131. background: #fff;
  132. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  133. position: relative;
  134. z-index: 10;
  135. .nav-item {
  136. flex: 1;
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. height: 100%;
  141. font-size: 15px;
  142. color: $font-color-dark;
  143. position: relative;
  144. &.current {
  145. color: $base-color;
  146. &:after {
  147. content: '';
  148. position: absolute;
  149. left: 50%;
  150. bottom: 0;
  151. transform: translateX(-50%);
  152. width: 44px;
  153. height: 0;
  154. border-bottom: 2px solid $base-color;
  155. }
  156. }
  157. }
  158. }
  159. // 列表
  160. .swiper-box {
  161. height: calc(100% - 44px);
  162. padding-top: 10rpx;
  163. .order-item {
  164. padding: 20rpx 30rpx;
  165. line-height: 1.5;
  166. .title-box {
  167. .title {
  168. font-size: $font-lg;
  169. color: $font-color-base;
  170. }
  171. .time {
  172. font-size: $font-base;
  173. color: $font-color-light;
  174. }
  175. }
  176. .money {
  177. color: #fd5b23;
  178. font-size: $font-lg;
  179. }
  180. }
  181. }
  182. .list-scroll-content {
  183. height: 100%;
  184. }
  185. .content {
  186. height: 100%;
  187. .empty-content {
  188. background-color: #ffffff;
  189. }
  190. }
  191. </style>