wallet.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view class="content">
  3. <view class="content-money">
  4. <view class="money-box">
  5. <view class="money">
  6. <text class="money-icon">¥</text>
  7. {{ userInfo.now_money | getMoneyStyle }}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="navbar">
  12. <view
  13. v-for="(item, index) in navList"
  14. :key="index"
  15. class="nav-item"
  16. :class="{ current: tabCurrentIndex === index }"
  17. @click="tabClick(index)"
  18. v-if="item.text !== '全部'"
  19. >
  20. {{ item.text }}
  21. </view>
  22. </view>
  23. <swiper :current="tabCurrentIndex" :style="{ height: maxheight + 'px' }" class="swiper-box" duration="300" @change="changeTab">
  24. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  25. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  26. <!-- 空白页 -->
  27. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  28. <!-- 订单列表 -->
  29. <view v-for="(item, index) in tabItem.orderList" :key="index" class="order-item flex">
  30. <view class="title-box">
  31. <view class="title">
  32. <text>{{ item.title }}</text>
  33. </view>
  34. <view class="time">
  35. <text>{{ item.add_time }}</text>
  36. </view>
  37. </view>
  38. <view class="money">
  39. <text>{{ (item.pm == 0 ? '-' : '+') + item.number }}</text>
  40. </view>
  41. <view class="jg"></view>
  42. </view>
  43. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  44. </scroll-view>
  45. </swiper-item>
  46. </swiper>
  47. <view class="add-btn" @click="addmoney">立刻充值</view>
  48. </view>
  49. </template>
  50. <script>
  51. import { mapState, mapMutations } from 'vuex';
  52. import { spreadCommission, userBalance } from '@/api/wallet.js';
  53. import { getMoneyStyle } from '@/utils/rocessor.js';
  54. import { getUserInfo } from '@/api/user.js';
  55. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  56. import empty from '@/components/empty';
  57. export default {
  58. filters: {
  59. getMoneyStyle
  60. },
  61. components: {
  62. empty,
  63. uniLoadMore
  64. },
  65. onReady() {
  66. // 初始化获取页面宽度
  67. uni.createSelectorQuery()
  68. .select('.content')
  69. .fields(
  70. {
  71. size: true
  72. },
  73. data => {
  74. console.log(data);
  75. console.log(Math.floor((data.width / 750) * 300));
  76. // 保存头部高度
  77. this.maxheight = data.height - Math.floor((data.width / 750) * 570);
  78. console.log(this.maxheight);
  79. }
  80. )
  81. .exec();
  82. },
  83. data() {
  84. return {
  85. // 头部图高度
  86. maxheight: '',
  87. tabCurrentIndex: 0,
  88. navList: [
  89. {
  90. state: 2,
  91. text: '收入',
  92. loadingType: 'more',
  93. orderList: [],
  94. page: 1, //当前页数
  95. limit: 10 //每次信息条数
  96. },
  97. {
  98. state: 1,
  99. text: '支出',
  100. loadingType: 'more',
  101. orderList: [],
  102. page: 1, //当前页数
  103. limit: 10 //每次信息条数
  104. }
  105. ],
  106. money: ''
  107. };
  108. },
  109. computed: {
  110. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  111. },
  112. onLoad(options) {},
  113. onShow() {
  114. this.loadData();
  115. // 获取用户余额
  116. getUserInfo({})
  117. .then(({ data }) => {
  118. this.setUserInfo(data);
  119. // 获取用户数据完毕后在获取订单数据防止多次跳转到登录页
  120. })
  121. .catch(e => {
  122. console.log(e);
  123. });
  124. },
  125. methods: {
  126. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  127. // 页面跳转
  128. navto(e) {
  129. uni.navigateTo({
  130. url: e
  131. });
  132. },
  133. //获取收入支出信息
  134. async loadData(source) {
  135. //这里是将订单挂载到tab列表下
  136. let index = this.tabCurrentIndex;
  137. let navItem = this.navList[index];
  138. let state = navItem.state;
  139. if (source === 'tabChange' && navItem.loaded === true) {
  140. //tab切换只有第一次需要加载数据
  141. return;
  142. }
  143. if (navItem.loadingType === 'loading') {
  144. //防止重复加载
  145. return;
  146. }
  147. // 修改当前对象状态为加载中
  148. navItem.loadingType = 'loading';
  149. spreadCommission(
  150. {
  151. page: navItem.page,
  152. limit: navItem.limit
  153. },
  154. state
  155. )
  156. .then(({ data }) => {
  157. console.log(data, '获取数据');
  158. // if (data.count > 0) {
  159. // navItem.orderList = navItem.orderList.concat(data.list);
  160. // console.log(navItem.orderList);
  161. // navItem.page++;
  162. // }
  163. if (data.length > 0) {
  164. data.forEach(item => {
  165. console.log(item.list, '内部列表');
  166. navItem.orderList = navItem.orderList.concat(item.list);
  167. });
  168. // navItem.orderList = navItem.orderList.concat(data[0].list);
  169. console.log(navItem.orderList);
  170. navItem.page++;
  171. }
  172. if (navItem.limit == data.length) {
  173. //判断是否还有数据, 有改为 more, 没有改为noMore
  174. navItem.loadingType = 'more';
  175. return;
  176. } else {
  177. //判断是否还有数据, 有改为 more, 没有改为noMore
  178. navItem.loadingType = 'noMore';
  179. }
  180. uni.hideLoading();
  181. this.$set(navItem, 'loaded', true);
  182. })
  183. .catch(e => {
  184. console.log(e);
  185. });
  186. },
  187. //swiper 切换
  188. changeTab(e) {
  189. this.tabCurrentIndex = e.target.current;
  190. this.loadData('tabChange');
  191. },
  192. //顶部tab点击
  193. tabClick(index) {
  194. this.tabCurrentIndex = index;
  195. },
  196. addmoney() {
  197. uni.navigateTo({
  198. url: '/pages/money/recharge'
  199. });
  200. }
  201. }
  202. };
  203. </script>
  204. <style lang="scss">
  205. page {
  206. background: #ffffff;
  207. height: 100%;
  208. }
  209. .content-money {
  210. padding-bottom: 30rpx;
  211. background: $page-color-base;
  212. .moneyTx {
  213. position: absolute;
  214. top: 150rpx;
  215. right: 0rpx;
  216. width: 150rpx;
  217. padding: 10rpx 30rpx;
  218. border: 2px solid #ffffff;
  219. border-top-left-radius: 99rpx;
  220. border-bottom-left-radius: 99rpx;
  221. color: #ffffff;
  222. line-height: 1;
  223. font-size: $font-base;
  224. }
  225. .buttom-box {
  226. background-color: #ffffff;
  227. text-align: center;
  228. margin: 0 30rpx;
  229. padding: 20rpx 0;
  230. border-radius: $border-radius-sm;
  231. margin-top: -60rpx;
  232. .buttom {
  233. font-size: $font-lg;
  234. flex-grow: 1;
  235. }
  236. .interval {
  237. width: 2px;
  238. height: 60rpx;
  239. background-color: #eeeeee;
  240. }
  241. .icon {
  242. height: 50rpx;
  243. width: 48rpx;
  244. margin: 0 auto;
  245. .icon-img {
  246. width: 100%;
  247. height: 100%;
  248. }
  249. }
  250. }
  251. }
  252. .money-box {
  253. background-color: $base-color;
  254. height: 265rpx;
  255. color: #ffffff;
  256. text-align: center;
  257. .text {
  258. padding-top: 147rpx;
  259. font-size: $font-sm;
  260. }
  261. .money {
  262. padding-top: 100rpx;
  263. // margin: auto 0;
  264. font-size: 56rpx;
  265. font-weight: bold;
  266. color: #ffffff;
  267. .money-icon {
  268. font-size: 38rpx;
  269. font-weight: bold;
  270. color: #ffffff;
  271. }
  272. }
  273. }
  274. .navbar {
  275. display: flex;
  276. height: 40px;
  277. padding: 0 5px;
  278. background: #fff;
  279. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  280. position: relative;
  281. z-index: 10;
  282. .nav-item {
  283. flex: 1;
  284. display: flex;
  285. justify-content: center;
  286. align-items: center;
  287. height: 100%;
  288. font-size: 15px;
  289. color: #999999;
  290. position: relative;
  291. &.current {
  292. color: $base-color;
  293. &:after {
  294. content: '';
  295. position: absolute;
  296. left: 50%;
  297. bottom: 0;
  298. transform: translateX(-50%);
  299. width: 44px;
  300. height: 0;
  301. border-bottom: 2px solid $base-color;
  302. }
  303. }
  304. }
  305. }
  306. // 列表
  307. .swiper-box {
  308. padding-top: 10rpx;
  309. .order-item {
  310. padding: 20rpx 30rpx;
  311. line-height: 1.5;
  312. position: relative;
  313. // border-bottom: 1rpx black solid;
  314. .title-box {
  315. .title {
  316. font-size: $font-lg;
  317. color: $font-color-base;
  318. }
  319. .time {
  320. font-size: $font-base;
  321. color: $font-color-light;
  322. }
  323. }
  324. .money {
  325. // color: #fd5b23;
  326. color: #901b21;
  327. font-size: $font-lg;
  328. }
  329. .jg {
  330. width: 701rpx;
  331. height: 2rpx;
  332. background: #f0f4f8;
  333. margin: 0 auto;
  334. position: absolute;
  335. bottom: 0;
  336. }
  337. }
  338. }
  339. .list-scroll-content {
  340. height: 100%;
  341. }
  342. .content {
  343. height: 100%;
  344. .empty-content {
  345. background-color: #ffffff;
  346. }
  347. }
  348. .add-btn {
  349. position: fixed;
  350. bottom: 51rpx;
  351. right: 39rpx;
  352. width: 674rpx;
  353. height: 88rpx;
  354. background: #ee2f72;
  355. border-radius: 44rpx;
  356. color: #fff;
  357. text-align: center;
  358. line-height: 88rpx;
  359. font-size: 34rpx;
  360. }
  361. </style>