barter.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="content">
  3. <view class="content-money">
  4. <view class="money-box">
  5. <view class="text">我的钱</view>
  6. <view class="money">{{ userInfo.barter_integral | getMoneyStyle }}</view>
  7. </view>
  8. </view>
  9. <view class="navbar">
  10. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  11. </view>
  12. <swiper :current="tabCurrentIndex" :style="{ height: maxheight }" class="swiper-box" duration="300" @change="changeTab">
  13. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  14. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  15. <!-- 空白页 -->
  16. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  17. <!-- 订单列表 -->
  18. <template>
  19. <view v-for="(item, i) in tabItem.orderList" class="order-item flex">
  20. <view class="title-box">
  21. <view class="title">
  22. <text>{{ item.mark }}</text>
  23. </view>
  24. <view class="time">
  25. <text>{{ item.add_time }}</text>
  26. </view>
  27. </view>
  28. <view class="money">
  29. <text>{{ (item.pm == 0 ? '-' : '+') + item.number }}</text>
  30. </view>
  31. </view>
  32. </template>
  33. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  34. </scroll-view>
  35. </swiper-item>
  36. </swiper>
  37. </view>
  38. </template>
  39. <script>
  40. import { barter_integral, userBalance } from '@/api/wallet.js';
  41. import { mapState, mapMutations } from 'vuex';
  42. import { getMoneyStyle } from '@/utils/rocessor.js';
  43. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  44. import empty from '@/components/empty';
  45. export default {
  46. filters: {
  47. getMoneyStyle
  48. },
  49. components: {
  50. empty,
  51. uniLoadMore
  52. },
  53. onReady(res) {
  54. // 初始化获取页面宽度
  55. var _this = this;
  56. uni.getSystemInfo({
  57. success: resu => {
  58. const query = uni.createSelectorQuery();
  59. query.select('.swiper-box').boundingClientRect();
  60. query.exec(function(res) {
  61. _this.maxheight = resu.windowHeight - res[0].top + 'px';
  62. console.log('打印页面的剩余高度', _this.height);
  63. });
  64. },
  65. fail: res => {}
  66. });
  67. },
  68. data() {
  69. return {
  70. // 头部图高度
  71. maxheight: '',
  72. tabCurrentIndex: 0,
  73. navList: [
  74. {
  75. state: 1,
  76. text: '明细',
  77. loadingType: 'more',
  78. orderList: [],
  79. page: 1, //当前页数
  80. limit: 10 //每次信息条数
  81. }
  82. ],
  83. money: ''
  84. };
  85. },
  86. onLoad(options) {
  87. this.loadData();
  88. },
  89. computed: {
  90. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  91. },
  92. methods: {
  93. // 页面跳转
  94. navto(e) {
  95. uni.navigateTo({
  96. url: e
  97. });
  98. },
  99. //获取收入支出信息
  100. async loadData(source) {
  101. //这里是将订单挂载到tab列表下
  102. let index = this.tabCurrentIndex;
  103. let navItem = this.navList[index];
  104. let state = navItem.state;
  105. if (source === 'tabChange' && navItem.loaded === true) {
  106. //tab切换只有第一次需要加载数据
  107. return;
  108. }
  109. if (navItem.loadingType === 'noMore') {
  110. //防止重复加载
  111. return;
  112. }
  113. // 修改当前对象状态为加载中
  114. navItem.loadingType = 'loading';
  115. barter_integral({
  116. page: navItem.page,
  117. limit: navItem.limit,
  118. pm: state
  119. })
  120. .then(({ data }) => {
  121. console.log(data);
  122. navItem.orderList = navItem.orderList.concat(data);
  123. console.log(navItem.orderList, '123465');
  124. navItem.page++;
  125. if (navItem.limit == data.length) {
  126. //判断是否还有数据, 有改为 more, 没有改为noMore
  127. navItem.loadingType = 'more';
  128. return;
  129. } else {
  130. //判断是否还有数据, 有改为 more, 没有改为noMore
  131. navItem.loadingType = 'noMore';
  132. }
  133. uni.hideLoading();
  134. this.$set(navItem, 'loaded', true);
  135. })
  136. .catch(e => {
  137. console.log(e);
  138. });
  139. },
  140. //swiper 切换
  141. changeTab(e) {
  142. this.tabCurrentIndex = e.target.current;
  143. this.loadData('tabChange');
  144. },
  145. //顶部tab点击
  146. tabClick(index) {
  147. this.tabCurrentIndex = index;
  148. },
  149. // 点击返回 我的页面
  150. toBack() {
  151. uni.switchTab({
  152. url: '/pages/user/user'
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. page {
  160. background: #ffffff;
  161. height: 100%;
  162. }
  163. .content-money {
  164. padding-bottom: 30rpx;
  165. background: $page-color-base;
  166. // border: 2px solid #ffffff;
  167. // padding-top: var(--status-bar-height);
  168. .money-box {
  169. background-color: $base-color;
  170. padding-top: var(--status-bar-height);
  171. height: 368rpx;
  172. color: #ffffff;
  173. text-align: center;
  174. .text {
  175. padding-top: 147rpx;
  176. font-size: $font-sm;
  177. }
  178. .money {
  179. font-size: 56rpx;
  180. }
  181. }
  182. }
  183. .navbar {
  184. display: flex;
  185. height: 40px;
  186. padding: 0 5px;
  187. background: #fff;
  188. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  189. position: relative;
  190. z-index: 10;
  191. .nav-item {
  192. flex: 1;
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. height: 100%;
  197. font-size: 15px;
  198. color: #999999;
  199. position: relative;
  200. &.current {
  201. color: #5dbc7c;
  202. &:after {
  203. content: '';
  204. position: absolute;
  205. left: 50%;
  206. bottom: 0;
  207. transform: translateX(-50%);
  208. width: 44px;
  209. height: 0;
  210. border-bottom: 2px solid #5dbc7c;
  211. }
  212. }
  213. }
  214. }
  215. // 列表
  216. .swiper-box {
  217. padding-top: 10rpx;
  218. .order-item {
  219. padding: 20rpx 30rpx;
  220. line-height: 1.5;
  221. .title-box {
  222. .title {
  223. font-size: $font-lg;
  224. color: $font-color-base;
  225. }
  226. .time {
  227. font-size: $font-base;
  228. color: $font-color-light;
  229. }
  230. }
  231. .money {
  232. color: #ff0000;
  233. font-size: $font-lg;
  234. }
  235. }
  236. }
  237. .list-scroll-content {
  238. height: 100%;
  239. }
  240. .wallet-btn {
  241. width: 674rpx;
  242. height: 88rpx;
  243. background: linear-gradient(90deg, #08c4e6, #50ead2);
  244. border-radius: 44rpx;
  245. font-size: $font-lg;
  246. font-family: PingFang SC;
  247. font-weight: 500;
  248. color: #ffffff;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. position: fixed;
  253. left: 38rpx;
  254. bottom: 50rpx;
  255. }
  256. .content {
  257. height: 100%;
  258. .empty-content {
  259. background-color: #ffffff;
  260. }
  261. }
  262. </style>