ranking.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <template>
  2. <view class="ranking">
  3. <!-- <custom-nav :title="pageTitle"></custom-nav> -->
  4. <view class="content">
  5. <view class="top_container">
  6. <view class="day-title">
  7. <text @tap="switchDay(0)" :class="day === 0 ? 'active' : ''">总榜单</text>
  8. <text @tap="switchDay(1)" :class="day === 1 ? 'active' : ''">昨日榜单</text>
  9. </view>
  10. </view>
  11. <view class="my_rank_container">
  12. <view class="my_rank" v-if="userServerInfo">
  13. <text class="num">{{ userServerInfo.rank }}</text>
  14. <image :src="avatarUrl" mode="" class="userImg"></image>
  15. <text class="name">{{ nickName }}</text>
  16. <text class="score">{{ userServerInfo.score }}</text>
  17. </view>
  18. </view>
  19. <view class="list_container">
  20. <view class="type-title" v-if="typeList.length > 0">
  21. <text v-for="(item, index) in typeList" :key="index" @tap="switchType(index)"
  22. :class="type === index ? 'active' : ''">{{ item }}</text>
  23. </view>
  24. <view class="rank_list_fixed_title">
  25. <view class="text1">排名</view>
  26. <view class="text3">
  27. <view class="text5">头像</view>
  28. <view class="text6">昵称</view>
  29. </view>
  30. <view class="text4">学分</view>
  31. </view>
  32. <view class="list">
  33. <scroll-view v-if="scrollview" show-scrollbar="true" :scroll-top="scrollTop"
  34. scroll-with-animation="true" :scroll-y="true" :style="{ height:'620px' }"
  35. @scrolltolower="scrolltolower" @scrolltoupper="scrolltoTop">
  36. <ranking-item v-for="(item, index) in list" :key="item.id" :index="item.rank || index + 1"
  37. :item="item" :rank="user.rank" :type="type"
  38. :bg="user.id === item.id && userServerInfo.type !== 3 && day === 0 && type + 1 === userServerInfo.type"></ranking-item>
  39. <custom-reach-bottom v-if="nomore || list.length" :nomore="nomore"></custom-reach-bottom>
  40. </scroll-view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- <page-toast :is-show="is_float" :is-close="false">
  45. <view class="toast_container shangsheng_toast" @click="is_float = 0">
  46. <image class="bg" src="https://api.jiuweiyun.cn/public/uploads/icon/toast9.png"></image>
  47. <view class="text">
  48. <view>上升了</view>
  49. <view>{{ is_float }}名</view>
  50. </view>
  51. </view>
  52. </page-toast> -->
  53. </view>
  54. </template>
  55. <script>
  56. import rankingItem from '../../components/ranking-item.vue';
  57. import {
  58. _API_GetUserRank
  59. } from '@/apis/user.js';
  60. var rank_prev_scroll = 0,
  61. prev_flag = true,
  62. location_flag = false,
  63. load_prev_scrolltop = 0;
  64. let ONE_H = 70;
  65. let PAGE_SIZE = 20;
  66. export default {
  67. onShareAppMessage: function(res) {
  68. uni.showLoading({
  69. title: '加载中',
  70. mask: true
  71. }); //显示loading
  72. if (res.from === 'button') {
  73. return {
  74. title: '我的排名',
  75. path: `/pages/crownshare/crownshare?top=${JSON.stringify(this.list.slice(0, 3))}&list=${JSON.stringify(this.shareList)}&season=${this.userServerInfo.season}`
  76. };
  77. }
  78. return {
  79. title: '大卫博士商学院卖货争霸',
  80. path: '/pages/index/index'
  81. };
  82. },
  83. components: {
  84. rankingItem
  85. },
  86. data() {
  87. return {
  88. pageTitle: '排行榜',
  89. typeList: [], //个人/批发商/团队/服务 导航栏显示内容
  90. day: 0, //今日/昨日
  91. type: 0, //个人/批发商/团队/服务
  92. page: 1, //
  93. list: [],
  94. user: {}, //用户当前排名和浮动情况
  95. scrollViewHeight: 0, //scrollview 高
  96. requesting: false, //是否正在请求
  97. nomore: false, //没得更多了
  98. scrollview: true, // 显示隐藏 scrollvew 解决切换后 scrolltop 不回到顶部的BUG
  99. shareList: [], //批发商分享列表
  100. scrollTop: 0, //设置竖向滚动条位置,
  101. is_float: 0,
  102. rankData: [],
  103. isClickLocation: false,
  104. avatarUrl: '',
  105. nickName: ''
  106. };
  107. },
  108. computed: {
  109. userWeixinInfo() {
  110. //用户微信信息
  111. return this.$store.state.userWeixinInfo;
  112. },
  113. userServerInfo() {
  114. //用户信息
  115. return this.$store.state.userinfo;
  116. },
  117. showFiexed() {
  118. //是否在屏幕下方显示显示个人信息
  119. return this.userServerInfo.type === this.type + 1 && this.userServerInfo.type !== 3 && this.day === 0;
  120. }
  121. },
  122. onShow() {
  123. },
  124. methods: {
  125. toShare() {
  126. uni.navigateTo({
  127. url: '../share/share'
  128. });
  129. },
  130. scrolltoTop() {
  131. if (this.isClickLocation) {
  132. let _this = this;
  133. this.getPageData(
  134. () => {
  135. _this.isClickLocation = false;
  136. _this.scrollTop = 0;
  137. _this.page = 1;
  138. },
  139. 0,
  140. 1
  141. );
  142. }
  143. },
  144. // 快速定位到我的位置
  145. locationMe(my) {
  146. this.isClickLocation = true;
  147. let max_one_screen_len = Math.ceil(this.scrollViewHeight / ONE_H);
  148. let toscroll;
  149. if (my % PAGE_SIZE < max_one_screen_len && my % PAGE_SIZE > 0) {
  150. toscroll = 0;
  151. } else if (my % PAGE_SIZE > PAGE_SIZE - max_one_screen_len || my % PAGE_SIZE === 0) {
  152. toscroll = (PAGE_SIZE - max_one_screen_len) * ONE_H;
  153. } else {
  154. toscroll = ((my % PAGE_SIZE) - 1) * ONE_H;
  155. }
  156. let you_page = Math.ceil(my / PAGE_SIZE);
  157. // 如果我的排名小于第一页的个数
  158. if (my < PAGE_SIZE) {
  159. this.scrollTop = toscroll;
  160. } else {
  161. if (!this.rankData.some(a => a.page === you_page)) {
  162. this.page = you_page;
  163. location_flag = true;
  164. let _this = this;
  165. this.getPageData(() => {
  166. // 计算出向下滚动距离
  167. if (toscroll > 0) {
  168. _this.scrollTop = toscroll;
  169. }
  170. }, 0);
  171. }
  172. }
  173. },
  174. switchDay(day) {
  175. //切换天
  176. this.day = day;
  177. this.switched();
  178. },
  179. switchType(index) {
  180. //切换类型
  181. this.type = index;
  182. this.switched();
  183. },
  184. getPageData(cb, isMy = 1, page) {
  185. page = page ? page : this.page;
  186. this.requesting = true;
  187. uni.showLoading({
  188. title: '加载中',
  189. mask: true
  190. });
  191. _API_GetUserRank({
  192. page_index: this.page,
  193. page_size: PAGE_SIZE
  194. }).then(res => {
  195. this.requesting = false;
  196. if (res.code == 200) {
  197. res.data.list.length < 20 ? (this.nomore = true) : ''; //如果返回的数据长度小于20,说明没得更多了
  198. this.rankData.push({
  199. page: page,
  200. data: res.data.list
  201. });
  202. this.rankData.sort((a, b) => a.page - b.page);
  203. cb && cb(res.data);
  204. uni.hideLoading();
  205. }
  206. })
  207. },
  208. switched() {
  209. //切换数据
  210. uni.showLoading({
  211. title: '加载中',
  212. mask: true
  213. }); //显示loading
  214. this.scrollViewHeight = 0; //将 scrollview 变为高变为零
  215. this.scrollview = false; // 隐藏 scrollvew 解决切换后 scrolltop 不回到顶部的BUG
  216. this.page = 1; //恢复页码
  217. this.nomore = false; //恢复没得更多了
  218. this.isClickLocation = false;
  219. this.scrollTop = 0;
  220. this.rankData = [];
  221. let _this = this;
  222. this.getPageData(data => {
  223. _this.scrollview = true; // 显示 scrollvew 解决切换后 scrolltop 不回到顶部的BUG
  224. data.per_data ? (_this.user = data.per_data) : ''; //是否有用户排名信息传过来,有就赋给 user
  225. _this.$scrollViewHeight('.list'); //设置页面内 scroll view 的高度
  226. if (_this.userServerInfo.type === 2 && _this.type === 1 && _this.day === 0) {
  227. //如果是批发商点击了批发商榜
  228. _this.makeCrownShareList();
  229. } else {
  230. _this.$hideLoading(); //异步操作结束,停止 loading
  231. }
  232. });
  233. },
  234. scrolltolower() {
  235. //下拉 scroll view 触底函数
  236. if (this.userServerInfo.type === 1 && this.type === 1) {
  237. //普通客户查看批发商榜时不会触发
  238. return;
  239. }
  240. if (!this.requesting && !this.nomore) {
  241. //防抖
  242. this.page = this.rankData[this.rankData.length - 1].page + 1;
  243. this.getPageData();
  244. }
  245. },
  246. async makeCrownShareList() {
  247. //生成批发商分享页面的列表数据
  248. const user = Object.assign({
  249. //生成用户信息
  250. name: this.userServerInfo.name,
  251. avatar: this.userWeixinInfo.avatarUrl,
  252. self: true
  253. },
  254. this.user
  255. );
  256. const rank = start => {
  257. this.shareList.forEach((e, i) => {
  258. e.rank = i + start;
  259. });
  260. };
  261. if (this.user.rank < 5) {
  262. //前四名的处理方式
  263. this.shareList = this.list.slice(0, 4);
  264. this.shareList.splice(this.user.rank - 1, 1, user);
  265. rank(1); //为分享数组里面的对象添加排名
  266. this.$hideLoading(); //异步操作结束,停止 loading
  267. } else if (this.user.rank > 4 && this.user.rank < 20) {
  268. //5 - 19 名的处理方式
  269. this.shareList = this.list.slice(this.user.rank - 3, this.user.rank + 1);
  270. this.shareList.splice(2, 1, user);
  271. rank(this.user.rank - 2); //为分享数组里面的对象添加排名
  272. this.$hideLoading(); //异步操作结束,停止 loading
  273. } else if (this.user.rank === 20) {
  274. //第 20 名的处理方式
  275. this.shareList = this.list.slice(17, 19);
  276. } else {
  277. this.$hideLoading();
  278. if (this.user.rank) {
  279. const page = Math.floor(this.user.rank / 20) + 1; //自己排名所处的页数(第几页)
  280. const index = this.user.rank % 20; //自己在自己那页的下标(第几个)
  281. const totalList = [...res1.data.list, ...res2.data.list, ...res3.data.list];
  282. this.shareList = totalList.slice(20 + index - 3, 20 + index + 1);
  283. this.shareList.splice(2, 1, user);
  284. rank(this.user.rank - 2); //为分享数组里面的对象添加排名
  285. this.$hideLoading(); //异步操作结束,停止 loading
  286. }
  287. }
  288. }
  289. },
  290. created() {
  291. this.avatarUrl = this.userServerInfo.avatar
  292. this.nickName = this.userServerInfo.name
  293. uni.showLoading({
  294. title: '加载中',
  295. mask: true
  296. }); //显示loading
  297. if (this.userServerInfo.type == 1) {
  298. //根据用户类型生成要展示的数据列表
  299. this.typeList = ['个人排行榜'];
  300. } else if (this.userServerInfo.type == 2) {
  301. // this.typeList = ['个人排行榜', '团队排行榜'];
  302. this.typeList = ['个人排行榜', '总排行榜'];
  303. } else if (this.userServerInfo.type == 3) {
  304. // this.typeList = ['个人排行榜', '团队排行榜'];
  305. this.typeList = ['个人排行榜', '总排行榜'];
  306. }
  307. this.$scrollViewHeight('.list'); //设置页面内 scroll view 的高度
  308. let _this = this;
  309. this.getPageData(data => {
  310. _this.$hideLoading(); //异步操作结束,停止 loading
  311. data.per_data ? (_this.user = data.per_data) : ''; //是否有用户排名信息传过来,有就赋给 user
  312. _this.is_float = (data.per_data && data.per_data.float) || 0;
  313. });
  314. },
  315. watch: {
  316. rankData: {
  317. handler(a, b) {
  318. if (a.length > 0) {
  319. this.list = [];
  320. a.forEach(item => {
  321. this.list = this.list.concat(item.data);
  322. });
  323. }
  324. },
  325. deep: true
  326. }
  327. }
  328. };
  329. </script>
  330. <style lang="scss" scoped>
  331. .ranking {
  332. @include page();
  333. .shangsheng_toast {
  334. width: 750rpx;
  335. height: 811rpx;
  336. .text {
  337. color: #e46b00;
  338. font-size: 60rpx;
  339. position: absolute;
  340. width: 200rpx;
  341. left: 50%;
  342. margin-left: -100rpx;
  343. bottom: 227rpx;
  344. text-align: center;
  345. line-height: 90rpx;
  346. }
  347. }
  348. .content {
  349. border-top: $custom-nav-borderbot-height solid $custom-nav-borderbot-color;
  350. display: flex;
  351. flex-direction: column;
  352. background-color: #f2f4f5;
  353. .top_container {
  354. width: 100%;
  355. height: 265rpx;
  356. background-image: url(../../static/new/rank_bg.png);
  357. background-repeat: no-repeat;
  358. background-size: 100% 100%;
  359. .day-title {
  360. width: 100%;
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. box-sizing: border-box;
  365. padding: 0 50rpx;
  366. margin: 34rpx 0 28rpx 0;
  367. text {
  368. height: 64rpx;
  369. width: 300rpx;
  370. line-height: 64rpx;
  371. text-align: center;
  372. box-sizing: border-box;
  373. border: 2rpx solid #ffffff;
  374. font-size: 36rpx;
  375. color: #ffffff;
  376. border-radius: 64rpx;
  377. &.active {
  378. color: #fa6342;
  379. background-color: #ffffff;
  380. }
  381. }
  382. }
  383. }
  384. .my_rank_container {
  385. width: 100%;
  386. padding: 0 30rpx;
  387. position: relative;
  388. height: 40rpx;
  389. margin-bottom: 30rpx;
  390. .my_rank {
  391. height: 120rpx;
  392. position: absolute;
  393. top: -80rpx;
  394. left: 30rpx;
  395. right: 30rpx;
  396. background-color: #ffffff;
  397. border-radius: 10rpx;
  398. box-sizing: border-box;
  399. padding: 0 42rpx;
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. .num {
  404. color: #2a2a2a;
  405. font-size: 40rpx;
  406. }
  407. .userImg {
  408. width: 64rpx;
  409. height: 64rpx;
  410. border-radius: 50%;
  411. }
  412. .name {
  413. font-size: 28rpx;
  414. color: #2a2a2a;
  415. }
  416. .score {
  417. color: #fa6342;
  418. font-size: 28rpx;
  419. }
  420. }
  421. }
  422. .share_btn {
  423. margin-top: 15rpx;
  424. padding: 0 30rpx;
  425. button {
  426. width: 100%;
  427. height: 76rpx;
  428. border: 2rpx solid #ffffff;
  429. border-radius: 24rpx;
  430. padding: 0;
  431. background: #fa6342;
  432. line-height: 76rpx;
  433. text-align: center;
  434. font-size: 28rpx;
  435. color: #ffffff;
  436. border-radius: 76rpx;
  437. }
  438. }
  439. .title-bar {
  440. height: 4rpx;
  441. width: 100%;
  442. background: #dedede;
  443. position: relative;
  444. .title-drog {
  445. width: 50%;
  446. height: 100%;
  447. background: #fa6342;
  448. position: absolute;
  449. top: 0;
  450. left: 0;
  451. &::after {
  452. content: '';
  453. display: block;
  454. width: 0;
  455. height: 0;
  456. border-style: solid;
  457. border-width: 8rpx 12rpx;
  458. border-color: transparent transparent red transparent;
  459. transform: translate(175.5rpx, -100%);
  460. }
  461. }
  462. }
  463. image {
  464. display: block;
  465. width: 100%;
  466. height: 240rpx;
  467. }
  468. .type-title {
  469. height: 83rpx;
  470. width: 100%;
  471. display: flex;
  472. justify-content: space-around;
  473. text {
  474. height: 83rpx;
  475. flex: 1;
  476. color: #999999;
  477. font-size: 36rpx;
  478. line-height: 83rpx;
  479. text-align: center;
  480. box-sizing: border-box;
  481. position: relative;
  482. border: 2rpx solid #ffffff;
  483. font-weight: 500;
  484. &.active {
  485. background-color: #ffffff;
  486. color: #fa6342;
  487. }
  488. }
  489. }
  490. .list_container {
  491. margin: 0 30rpx;
  492. flex: 1;
  493. display: flex;
  494. justify-content: space-between;
  495. flex-direction: column;
  496. box-shadow: 0 0 21rpx 3rpx rgba(255, 90, 11, 0.2);
  497. }
  498. .rank_list_fixed_title {
  499. width: 100%;
  500. height: 64rpx;
  501. line-height: 64rpx;
  502. color: #666666;
  503. font-size: 32rpx;
  504. padding: 0 30rpx;
  505. box-sizing: border-box;
  506. display: flex;
  507. justify-content: space-between;
  508. align-items: center;
  509. .text1 {
  510. width: 76rpx;
  511. }
  512. .text3 {
  513. width: calc(100% - 206rpx);
  514. display: flex;
  515. justify-content: space-between;
  516. align-items: center;
  517. margin-left: 40rpx;
  518. }
  519. .text4 {
  520. width: 130rpx;
  521. text-align: center;
  522. }
  523. .text5 {
  524. width: 64rpx;
  525. text-align: center;
  526. }
  527. .text6 {
  528. width: calc(100% - 104rpx);
  529. // text-align: center;
  530. text-align: left !important;
  531. }
  532. }
  533. .list {
  534. flex: 1;
  535. height: calc(100% - 91rpx - 64rpx);
  536. }
  537. .fiexed {
  538. height: 100rpx;
  539. bottom: 0;
  540. background: #fa6342;
  541. display: flex;
  542. padding: 0 30rpx;
  543. .left {
  544. height: 100%;
  545. width: 136rpx;
  546. display: flex;
  547. flex-direction: column;
  548. align-items: center;
  549. justify-content: center;
  550. text {
  551. color: #ffffff;
  552. font-size: 26rpx;
  553. &.rank {
  554. font-size: 32rpx;
  555. }
  556. }
  557. }
  558. .center {
  559. width: 380rpx;
  560. margin-left: 10rpx;
  561. height: 100%;
  562. display: flex;
  563. align-items: center;
  564. color: #ffffff;
  565. position: relative;
  566. image {
  567. width: 64rpx;
  568. height: 64rpx;
  569. border-radius: 50%;
  570. &.hat {
  571. position: absolute;
  572. top: 6rpx;
  573. left: -5rpx;
  574. width: 72rpx;
  575. height: 88rpx;
  576. }
  577. }
  578. text {
  579. margin-left: 30rpx;
  580. font-size: 24rpx;
  581. }
  582. }
  583. .right {
  584. flex: 1;
  585. display: flex;
  586. align-items: center;
  587. color: #ffffff;
  588. button {
  589. width: 146rpx;
  590. height: 48rpx;
  591. border: 2rpx solid #ffffff;
  592. border-radius: 24rpx;
  593. padding: 0;
  594. background: transparent;
  595. line-height: 48rpx;
  596. text-align: center;
  597. font-size: 24rpx;
  598. color: #ffffff;
  599. }
  600. .score {
  601. width: 130rpx;
  602. height: 100%;
  603. display: flex;
  604. align-items: center;
  605. color: #fa6342;
  606. image {
  607. width: 30rpx;
  608. height: 30rpx;
  609. }
  610. text {
  611. font-size: 24rpx;
  612. margin-left: 10rpx;
  613. }
  614. }
  615. .float {
  616. flex: 1;
  617. display: flex;
  618. align-items: center;
  619. image {
  620. width: 24rpx;
  621. height: 30rpx;
  622. }
  623. text {
  624. margin-left: 10rpx;
  625. font-size: 24rpx;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. </style>