wallet.vue 8.3 KB

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