consumer.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="content">
  3. <view class="content-money">
  4. <view class="money-box">
  5. <view class="bg"><image src="../../static/img/consumer.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>
  47. </template>
  48. <script>
  49. import { getUserInfo } from '@/api/login.js';
  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: 6,
  104. text: '支出',
  105. loadingType: 'more',
  106. orderList: [],
  107. page: 1, //当前页数
  108. limit: 10 //每次信息条数
  109. },
  110. {
  111. state: 5,
  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. getUserInfo().then(({data}) => {
  136. this.money = data.consumer;
  137. })
  138. },
  139. methods: {
  140. // ToChangeInto() {
  141. // // #ifdef H5
  142. // this.weichatObj.scanQRCode({
  143. // needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  144. // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  145. // success: function(res) {
  146. // let result = JSON.parse(res.resultStr);
  147. // rechargemoneys({
  148. // id: result.id,
  149. // money: result.money
  150. // })
  151. // .then(({ data }) => {
  152. // uni.showModal({
  153. // title: '标题',
  154. // content: '成功',
  155. // showCancel: false
  156. // });
  157. // })
  158. // .catch(e => {
  159. // console.log(e);
  160. // });
  161. // }
  162. // });
  163. // // #endif
  164. // },
  165. // 页面跳转
  166. navto(e) {
  167. uni.navigateTo({
  168. url: e
  169. });
  170. },
  171. //获取收入支出信息
  172. async loadData(source) {
  173. //这里是将订单挂载到tab列表下
  174. let index = this.tabCurrentIndex;
  175. let navItem = this.navList[index];
  176. let state = navItem.state;
  177. if (source === 'tabChange' && navItem.loaded === true) {
  178. //tab切换只有第一次需要加载数据
  179. return;
  180. }
  181. if (navItem.loadingType === 'loading') {
  182. //防止重复加载
  183. return;
  184. }
  185. // 修改当前对象状态为加载中
  186. navItem.loadingType = 'loading';
  187. spreadCommission(
  188. {
  189. page: navItem.page,
  190. limit: navItem.limit
  191. },
  192. state
  193. )
  194. .then(({ data }) => {
  195. if (data.length > 0) {
  196. navItem.orderList = navItem.orderList.concat(data);
  197. console.log(navItem.orderList);
  198. navItem.page++;
  199. }
  200. if (navItem.limit == data.length) {
  201. //判断是否还有数据, 有改为 more, 没有改为noMore
  202. navItem.loadingType = 'more';
  203. return;
  204. } else {
  205. //判断是否还有数据, 有改为 more, 没有改为noMore
  206. navItem.loadingType = 'noMore';
  207. }
  208. uni.hideLoading();
  209. this.$set(navItem, 'loaded', true);
  210. })
  211. .catch(e => {
  212. console.log(e);
  213. });
  214. },
  215. //返回上一页面
  216. toBack() {
  217. console.log(111);
  218. uni.navigateBack({});
  219. },
  220. //swiper 切换
  221. changeTab(e) {
  222. this.tabCurrentIndex = e.target.current;
  223. this.loadData('tabChange');
  224. },
  225. //顶部tab点击
  226. tabClick(index) {
  227. this.tabCurrentIndex = index;
  228. }
  229. }
  230. };
  231. </script>
  232. <style lang="scss">
  233. page {
  234. background: #ffffff;
  235. height: 100%;
  236. padding: 0;
  237. }
  238. .content-money {
  239. padding-bottom: 30rpx;
  240. background: $page-color-base;
  241. }
  242. .money-box {
  243. background-color: $base-color;
  244. padding-top: var(--status-bar-height);
  245. height: 468rpx;
  246. color: #ffffff;
  247. text-align: center;
  248. justify-content: center;
  249. position: relative;
  250. .body-title {
  251. height: 80rpx;
  252. text-align: center;
  253. font-size: 35rpx;
  254. position: relative;
  255. .header {
  256. position: absolute;
  257. left: 0;
  258. top: 0;
  259. width: 100%;
  260. font-size: 36rpx;
  261. font-family: PingFang SC;
  262. font-weight: bold;
  263. color: #fffeff;
  264. height: 80rpx;
  265. font-size: 32rpx;
  266. font-weight: 700;
  267. z-index: 9;
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. }
  272. .goback-box {
  273. position: absolute;
  274. z-index: 10;
  275. left: 24rpx;
  276. top: 0;
  277. height: 80rpx;
  278. display: flex;
  279. align-items: center;
  280. }
  281. .goback {
  282. width: 30rpx;
  283. height: 36rpx;
  284. }
  285. }
  286. .bg {
  287. position: absolute;
  288. top: 0;
  289. left: 0;
  290. width: 100%;
  291. height: 100%;
  292. image {
  293. width: 100%;
  294. height: 100%;
  295. }
  296. }
  297. .money {
  298. position: relative;
  299. z-index: 10;
  300. font-size: 56rpx;
  301. height: 388rpx;
  302. line-height: 288rpx;
  303. }
  304. }
  305. .navbar {
  306. display: flex;
  307. height: 40px;
  308. padding: 0 5px;
  309. background: #fff;
  310. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  311. position: relative;
  312. z-index: 10;
  313. .nav-item {
  314. flex: 1;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. height: 100%;
  319. font-size: 15px;
  320. color: $font-color-dark;
  321. position: relative;
  322. &.current {
  323. color: $base-color;
  324. &:after {
  325. content: '';
  326. position: absolute;
  327. left: 50%;
  328. bottom: 0;
  329. transform: translateX(-50%);
  330. width: 44px;
  331. height: 0;
  332. border-bottom: 2px solid $base-color;
  333. }
  334. }
  335. }
  336. }
  337. // 列表
  338. .swiper-box {
  339. padding-top: 10rpx;
  340. .order-item {
  341. padding: 20rpx 30rpx;
  342. line-height: 1.5;
  343. .title-box {
  344. .title {
  345. font-size: $font-lg;
  346. color: $font-color-base;
  347. }
  348. .time {
  349. font-size: $font-base;
  350. color: $font-color-light;
  351. }
  352. }
  353. .money {
  354. color: #fd5b23;
  355. font-size: $font-lg;
  356. }
  357. }
  358. }
  359. .list-scroll-content {
  360. height: 100%;
  361. }
  362. .content {
  363. height: 100%;
  364. .empty-content {
  365. background-color: #ffffff;
  366. }
  367. }
  368. </style>