wallet.vue 8.1 KB

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