award.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view class="content">
  3. <view class="status_bar"><!-- 这里是状态栏 --></view>
  4. <view class="content-money">
  5. <!-- <view class="body-title">
  6. <view class="goback-box" @click="toBack"><image class="goback" src="../../static/icon/fanhui.png" mode=""></image></view>
  7. <view class="header">我的糖果</view>
  8. </view> -->
  9. <view class="content-bg"><image src="../../static/img/user-award.png" mode=""></image></view>
  10. <view class="money-box">
  11. <view class="money">{{ money }}</view>
  12. </view>
  13. </view>
  14. <view class="navbar">
  15. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  16. </view>
  17. <swiper :current="tabCurrentIndex" :style="{ height: maxheight }" class="swiper-box" duration="300" @change="changeTab">
  18. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  19. <scroll-view scroll-y="true" class="list-scroll-content" @scrolltolower="loadData">
  20. <!-- 空白页 -->
  21. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  22. <!-- 订单列表 -->
  23. <view class="order-item flex" v-for="(item, index) in tabItem.orderList" :key="index">
  24. <view class="title-box">
  25. <view class="title">
  26. <text>{{ item.title }}</text>
  27. </view>
  28. <view class="time">
  29. <text>{{ item.add_time }}</text>
  30. </view>
  31. </view>
  32. <view class="money">
  33. <text>{{ (item.pm == 0 ? '-' : '+') + item.number }}</text>
  34. </view>
  35. </view>
  36. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  37. </scroll-view>
  38. </swiper-item>
  39. </swiper>
  40. <view class="btn-box" @click="navto('/pages/money/recharge')">
  41. 立即充值
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { spreadCommission, userBalance } from '@/api/wallet.js';
  47. import { mapState, mapMutations } from 'vuex';
  48. import uniLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue';
  49. import empty from '@/uview-ui/components/u-empty/u-empty.vue';
  50. export default {
  51. components: {
  52. empty,
  53. uniLoadMore
  54. },
  55. onReady(res) {
  56. var _this = this;
  57. uni.getSystemInfo({
  58. success: resu => {
  59. const query = uni.createSelectorQuery();
  60. query.select('.swiper-box').boundingClientRect();
  61. query.exec(function(res) {
  62. _this.maxheight = resu.windowHeight - res[0].top + 'px';
  63. console.log('打印页面的剩余高度', _this.height);
  64. });
  65. },
  66. fail: res => {}
  67. });
  68. },
  69. data() {
  70. return {
  71. // 头部图高度
  72. maxheight: '',
  73. tabCurrentIndex: 0,
  74. navList: [
  75. {
  76. state: 0,
  77. text: '收入',
  78. loadingType: 'more',
  79. orderList: [],
  80. page: 1, //当前页面
  81. limit: 10 //每次信息条数
  82. },
  83. {
  84. state: 1,
  85. text: '支出',
  86. loadingType: 'more',
  87. orderList: [],
  88. page: 1, //当前页面
  89. limit: 10 //每次信息条数
  90. }
  91. ],
  92. money: 0
  93. };
  94. },
  95. onLoad(options) {},
  96. onShow() {
  97. this.loadData();
  98. //获取用户余额
  99. userBalance({}).then(({ data }) => {
  100. console.log(data)
  101. this.money = data.now_money;
  102. });
  103. },
  104. methods: {
  105. navto(e) {
  106. uni.navigateTo({
  107. url: e
  108. });
  109. },
  110. // 点击返回 我的页面
  111. toBack() {
  112. uni.navigateBack({
  113. })
  114. },
  115. async loadData(source) {
  116. //这里时将订单挂载到tab列表下
  117. let index = this.tabCurrentIndex;
  118. let navItem = this.navList[index];
  119. let state = navItem.state + 3;
  120. if (source === 'tabChange' && navItem.loaded === true) {
  121. //tab切换只有第一次需要加载数据
  122. return;
  123. }
  124. if (navItem.loadingType === 'loading') {
  125. //防止重复加载
  126. return;
  127. }
  128. //修改当前对象状态为加载中
  129. navItem.loadingType = 'loading';
  130. spreadCommission(
  131. {
  132. page: navItem.page,
  133. limit: navItem.limit
  134. },
  135. state
  136. )
  137. .then(({ data }) => {
  138. if (data.length > 0) {
  139. navItem.orderList = navItem.orderList.concat(data[0].list);
  140. console.log(navItem.orderList);
  141. navItem.page++;
  142. }
  143. //判断是否还有数据, 有改为more, 没有改为noMore
  144. if (navItem.limit == data.length) {
  145. navItem.loadingType = 'more';
  146. return;
  147. } else {
  148. navItem.loadingType = 'noMore';
  149. }
  150. uni.hideLoading();
  151. this.$set(navItem, 'loaded', true);
  152. })
  153. .catch(e => {
  154. console.log(e);
  155. });
  156. },
  157. //swiper 切换
  158. changeTab(e) {
  159. this.tabCurrentIndex = e.target.current;
  160. this.loadData('tabChange');
  161. },
  162. //顶部tab点击
  163. tabClick(index) {
  164. this.tabCurrentIndex = index;
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="scss">
  170. page {
  171. background: #f1f1f1;
  172. height: 100%;
  173. }
  174. .status_bar {
  175. height: var(--status-bar-height);
  176. width: 100%;
  177. }
  178. .content-money {
  179. padding-bottom: 30rpx;
  180. position: relative;
  181. height: 400rpx;
  182. .content-bg {
  183. position: absolute;
  184. top: 0;
  185. left: 0;
  186. right: 0;
  187. width: 750rpx;
  188. height: 400rpx;
  189. image {
  190. width: 100%;
  191. height: 100%;
  192. }
  193. }
  194. .body-title {
  195. height: 80rpx;
  196. text-align: center;
  197. font-size: 35rpx;
  198. position: relative;
  199. .header {
  200. position: absolute;
  201. left: 0;
  202. top: 0;
  203. width: 100%;
  204. font-size: 36rpx;
  205. font-family: PingFang SC;
  206. font-weight: bold;
  207. color: #fffeff;
  208. height: 80rpx;
  209. font-size: 36rpx;
  210. font-weight: 700;
  211. z-index: 9;
  212. display: flex;
  213. justify-content: center;
  214. align-items: center;
  215. }
  216. .goback-box {
  217. position: absolute;
  218. left: 18rpx;
  219. top: 0;
  220. height: 80rpx;
  221. display: flex;
  222. align-items: center;
  223. }
  224. .goback {
  225. z-index: 100;
  226. width: 34rpx;
  227. height: 34rpx;
  228. }
  229. }
  230. }
  231. .money-box {
  232. position: relative;
  233. z-index: 100;
  234. padding-top: 150rpx;
  235. color: #ffffff;
  236. text-align: center;
  237. .money {
  238. font-size: 86rpx;
  239. font-family: PingFang SC;
  240. font-weight: bold;
  241. color: #FFFFFF;
  242. }
  243. }
  244. .navbar {
  245. margin-top: 20rpx;
  246. display: flex;
  247. height: 88rpx;
  248. padding: 0 5px;
  249. background: #fff;
  250. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  251. position: relative;
  252. z-index: 10;
  253. .nav-item {
  254. flex: 1;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. height: 100%;
  259. font-size: 15px;
  260. color: $font-color-dark;
  261. position: relative;
  262. &.current {
  263. color: $base-color;
  264. &:after {
  265. content: '';
  266. position: absolute;
  267. left: 50%;
  268. bottom: 0;
  269. transform: translateX(-50%);
  270. width: 44px;
  271. height: 0;
  272. border-bottom: 2px solid $base-color;
  273. }
  274. }
  275. }
  276. }
  277. //列表
  278. .swiper-box {
  279. .order-item {
  280. padding: 20rpx 30rpx;
  281. line-height: 1.5;
  282. .title-box {
  283. .title {
  284. font-size: $font-lg;
  285. color: $font-color-base;
  286. }
  287. .time {
  288. font-size: $font-base;
  289. color: $font-color-light;
  290. }
  291. }
  292. .money {
  293. color: #fd5b23;
  294. font-size: $font-lg;
  295. }
  296. }
  297. }
  298. .list-scroll-content {
  299. background: #ffffff;
  300. height: 100%;
  301. }
  302. .content {
  303. height: 100%;
  304. .empty-content {
  305. background-color: #ffffff;
  306. }
  307. }
  308. .btn-box {
  309. width: 674rpx;
  310. height: 88rpx;
  311. background: linear-gradient(0deg, #2E58FF, #32C6FF);
  312. border-radius: 44rpx;
  313. font-size: 36rpx;
  314. font-family: PingFang SC;
  315. font-weight: 500;
  316. color: #FFFFFF;
  317. text-align: center;
  318. line-height: 88rpx;
  319. position: fixed;
  320. bottom: 48rpx;
  321. left: 0;
  322. right: 0;
  323. margin: 0 auto;
  324. }
  325. </style>