consumer.vue 8.0 KB

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