list.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <!-- 余额明细页面 -->
  2. <template>
  3. <view class="content">
  4. <view class="navbar">
  5. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current: tabCurrentIndex === index}"
  6. @click="tabClick(index)">
  7. {{item.text}}
  8. </view>
  9. </view>
  10. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  11. <swiper-item class="tab-content" v-for="(tabItem,tabIndex) in navList" :key="tabIndex">
  12. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  13. <view v-if="tabItem.loadingState != 'first_loading'&&tabItem.balanceList.length == 0" class="empty_part flex_column_start_center">
  14. <image :src="imgUrl+'empty_goods.png'" />
  15. <text>{{$L('还没有数据哦')}}~</text>
  16. </view>
  17. <!-- 余额列表 -->
  18. <template v-if="tabItem.balanceList.length > 0">
  19. <view v-for="(item,index) in tabItem.balanceList" :key="index" class="log-item flex_row_between_center b_b">
  20. <view class="left flex_column_start_start">
  21. <text class="type">{{item.stateValue}}</text>
  22. <text class="desc">{{item.description}}</text>
  23. <text class="time">{{item.createTime}}</text>
  24. </view>
  25. <view class="right flex_row_end_center">
  26. <text :class="{amount:true,add:item.state==1,flag:true}">{{(item.state==1?'+':'-')}}</text>
  27. <text :class="{amount:true,add:item.state==1}"> ¥{{item.changeValue}}</text>
  28. </view>
  29. </view>
  30. </template>
  31. <loadingState v-if="tabItem.loadingState == 'first_loading'||tabItem.balanceList.length > 0" :state='tabItem.loadingState' />
  32. </scroll-view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. import loadingState from "@/components/loading-state.vue";
  39. import {
  40. mapState
  41. } from 'vuex';
  42. export default {
  43. components: {
  44. loadingState
  45. },
  46. data() {
  47. return {
  48. imgUrl: getApp().globalData.imgUrl,
  49. tabCurrentIndex: 0,
  50. navList: [{
  51. state: 0,
  52. text: '全部',
  53. loadingState: 'first_loading',
  54. balanceList: [],
  55. current: 1, //分页
  56. },
  57. {
  58. state: 1,
  59. text: '收入',
  60. loadingState: 'first_loading',
  61. balanceList: [],
  62. current: 1, //分页
  63. },
  64. {
  65. state: 2,
  66. text: '支出',
  67. loadingState: 'first_loading',
  68. balanceList: [],
  69. current: 1, //分页
  70. },
  71. ],
  72. stopPullDownRefresh: false, //是否下拉刷新中
  73. };
  74. },
  75. onLoad(options) {
  76. /**
  77. * 修复app端点击除全部订单外的按钮进入时不加载数据的问题
  78. * 替换onLoad下代码即可
  79. */
  80. // #ifndef MP
  81. this.loadData()
  82. // #endif
  83. // #ifdef MP
  84. this.loadData()
  85. // #endif
  86. },
  87. computed: {
  88. ...mapState(['userInfo'])
  89. },
  90. //下拉刷新
  91. onPullDownRefresh() {
  92. let index = this.tabCurrentIndex;
  93. let navItem = this.navList[index];
  94. navItem.loadingState = 'first_loading';
  95. navItem.balanceList = [];
  96. navItem.current = 1;
  97. this.stopPullDownRefresh = true; //下拉刷新状态
  98. this.loadData();
  99. },
  100. methods: {
  101. //获取订单列表
  102. loadData(source) {
  103. //将订单挂载到tab列表下,起到缓存的效果,避免多次请求
  104. let index = this.tabCurrentIndex;
  105. let navItem = this.navList.filter(item => item.state == index)[0];
  106. let state = navItem.state;
  107. if (source === 'tabChange' && navItem.loadingState !== 'first_loading') {
  108. //tab切换只有第一次需要加载数据
  109. return;
  110. }
  111. if (navItem.loadingState === 'loading') {
  112. //防止重复加载
  113. return;
  114. }
  115. if (navItem.loadingState == 'no_more_data') {
  116. //已经没有数据,无需再请求
  117. return;
  118. }
  119. let param = {};
  120. param.url = 'v3/member/front/balanceLog/list';
  121. param.data = {};
  122. param.data.pageSize = 10;
  123. param.data.current = navItem.current;
  124. navItem.loadingState = navItem.loadingState == 'first_loading' ? navItem.loadingState : 'loading';
  125. param.data.state = navItem.state;
  126. this.$request(param).then(res => {
  127. if (res.state == 200) {
  128. navItem.balanceList = navItem.balanceList.concat(res.data.list);
  129. let hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  130. if (hasMore) {
  131. navItem.current++;
  132. navItem.loadingState = 'allow_loading_more';
  133. } else {
  134. navItem.loadingState = 'no_more_data';
  135. }
  136. } else {
  137. this.$api.msg(res.msg);
  138. }
  139. if (this.stopPullDownRefresh) {
  140. this.stopPullDownRefresh = false;
  141. uni.stopPullDownRefresh();
  142. }
  143. }).catch((e) => {
  144. //异常处理
  145. })
  146. },
  147. //swiper 切换
  148. changeTab(e) {
  149. this.tabCurrentIndex = e.target.current;
  150. this.loadData('tabChange');
  151. },
  152. //顶部tab点击
  153. tabClick(index) {
  154. this.tabCurrentIndex = index;
  155. },
  156. },
  157. }
  158. </script>
  159. <style lang="scss">
  160. page,
  161. .content {
  162. background: $bg-color-split;
  163. height: 100%;
  164. width: 750rpx;
  165. margin: 0 auto;
  166. }
  167. .swiper-box {
  168. height: calc(100% - 40px);
  169. }
  170. .list-scroll-content {
  171. height: 100%;
  172. }
  173. .navbar {
  174. display: flex;
  175. height: 80rpx;
  176. padding: 0 5px;
  177. background: #fff;
  178. position: relative;
  179. z-index: 10;
  180. .nav-item {
  181. flex: 1;
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. height: 100%;
  186. font-size: 28rpx;
  187. color: $main-font-color;
  188. position: relative;
  189. &.current {
  190. color: $main-color;
  191. font-size: 32rpx;
  192. &:after {
  193. content: '';
  194. position: absolute;
  195. left: 50%;
  196. bottom: 0;
  197. transform: translateX(-50%);
  198. width: 35rpx;
  199. height: 8rpx;
  200. background-color: $main-color;
  201. border-radius: 4rpx;
  202. }
  203. }
  204. }
  205. }
  206. .uni-swiper-item {
  207. height: auto;
  208. }
  209. .log-item {
  210. padding: 30rpx;
  211. background: #fff;
  212. position: relative;
  213. &:first-child {
  214. margin-top: 20rpx;
  215. }
  216. &.b_b:after {
  217. left: 30rpx;
  218. right: 30rpx;
  219. }
  220. .left {
  221. margin-right: 40rpx;
  222. .type {
  223. color: $main-font-color;
  224. font-size: 30rpx;
  225. font-weight: bold;
  226. }
  227. .desc {
  228. color: $main-second-color;
  229. font-size: 26rpx;
  230. margin: 10rpx 0;
  231. }
  232. .time {
  233. color: $main-third-color;
  234. font-size: 22rpx;
  235. }
  236. }
  237. .right {
  238. .amount {
  239. color: #949494;
  240. font-size: 32rpx;
  241. &.add {
  242. color: $main-color;
  243. }
  244. &.flag {
  245. margin-top: -5rpx;
  246. margin-right: 2rpx;
  247. }
  248. }
  249. .iconfont {
  250. color: #949494;
  251. font-size: 20rpx;
  252. margin-left: 19rpx;
  253. }
  254. }
  255. }
  256. .empty_part {
  257. padding-top: 160rpx;
  258. image {
  259. width: 210rpx;
  260. height: 210rpx;
  261. }
  262. text {
  263. color: $main-third-color;
  264. font-size: 26rpx;
  265. margin-top: 57rpx;
  266. }
  267. button {
  268. width: 245rpx;
  269. height: 66rpx;
  270. background: rgba(252, 28, 28, .05);
  271. border-radius: 33rpx;
  272. color: $main-color;
  273. font-size: 30rpx;
  274. font-weight: bold;
  275. margin-top: 29rpx;
  276. }
  277. uni-button:after {
  278. border-radius: 200rpx;
  279. border-color: #fff;
  280. }
  281. }
  282. </style>