rankList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <!--
  2. [报名] 样式1 - 排名列表
  3. http://localhost:5173/card/#/pages/bm/style1/rankList
  4. https://oss-mbh5.colormaprun.com/card/#/pages/bm/style1/rankList
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content uni-column">
  9. <view class="uni-column" :class="cssTop">
  10. <view class="topbar uni-row">
  11. <image mode="aspectFit" class="topbar-back" @click="btnBack" src="/static/default/back.png"></image>
  12. <text class="mcName">{{mcName}}</text>
  13. <text class="topbar-rule" @click="btnInfo" >规则</text>
  14. <!-- <image mode="aspectFit" class="topbar-info" @click="btnInfo" src="/static/default/info.png"></image> -->
  15. </view>
  16. <view class="topcontent uni-column">
  17. <view>
  18. <text class="toptext">{{coiName}}</text>
  19. <text class="toptext" v-if="teamNum > 0">{{getTeamName(teamType, teamNum)}}</text>
  20. </view>
  21. <view class="top-countdown uni-row">
  22. <image mode="aspectFit" class="cal" src="/static/default/cal.png"></image>
  23. <text>{{countdown}}</text>
  24. </view>
  25. </view>
  26. <view class="topbtm uni-column">
  27. <view class="topbtm-content uni-row">
  28. <text class="topbtm-sspm" v-if="mcState==1 && allowMcSignUp"></text>
  29. <text class="topbtm-sspm">实时排名</text>
  30. <view class="btnReGroup" v-if="mcState==1 && allowMcSignUp" @click="btnReGroup">重新分组</view>
  31. </view>
  32. </view>
  33. <!-- <text class="mcName">{{ecId}} - {{mcId}} - {{token}}</text> -->
  34. </view>
  35. <view class="main uni-column">
  36. <uni-segmented-control class="main-tab" :current="tabCurrent" :values="tabItems"
  37. @clickItem="onClickTabItem" styleType="button" activeColor="#2e85ec"></uni-segmented-control>
  38. <view class="tab-view uni-column">
  39. <!-- 总排名 -->
  40. <my-ranklist v-show="tabCurrent === 0" :rankRs="rankList.totalRankRs"></my-ranklist>
  41. <!-- 队伍排名 -->
  42. <my-ranklist v-show="tabCurrent === 1" v-if="teamType==0" :rankRs="rankList.teamRankRs" :teamType="this.teamType"></my-ranklist>
  43. <!-- 队内排名 -->
  44. <my-ranklist v-show="tabCurrent === 2" v-if="teamType==0" :rankRs="rankList.inTeamRs"></my-ranklist>
  45. <!-- 学生排名 -->
  46. <my-ranklist v-show="tabCurrent === 1" v-if="teamType==1" :rankRs="teamNum==1 ? rankList.inTeamRs : rankList.otherRs[1]"></my-ranklist>
  47. <!-- 家长排名 -->
  48. <my-ranklist v-show="tabCurrent === 2" v-if="teamType==1" :rankRs="teamNum==2 ? rankList.inTeamRs : rankList.otherRs[2]"></my-ranklist>
  49. </view>
  50. <button class="btnStart btnStart-disable" v-if="mcState==0">活动尚未开始</button>
  51. <button class="btnStart btnStart-enable" v-if="mcState==1" @click="btnStart">开始比赛</button>
  52. <button class="btnStart btnStart-disable" v-if="mcState==2">活动已结束</button>
  53. </view>
  54. <my-popup ref="mypopup" :dataList="popupDataList" :acttime="acttime"></my-popup>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import tools from '/common/tools';
  60. import { teamName, defaultPopUpDataList } from '/common/define';
  61. import {
  62. token,
  63. apiCardDetailQuery,
  64. apiCardRankDetailQuery,
  65. apiCardConfigQuery,
  66. apiUserCurrentRankNumQuery,
  67. apiIsAllowMcSignUp,
  68. checkResCode
  69. } from '/common/api';
  70. export default {
  71. data() {
  72. return {
  73. pageName: "rankList",
  74. firstEnterKey: 'firstEnter-bm',
  75. rankKey: "rank-bm-style1",
  76. queryObj: {},
  77. queryString: "",
  78. token: "",
  79. ecId: 0, // 卡片id
  80. mcId: 0, // 赛事id
  81. mcType: 0, // 赛事类型 1 普通活动 2 线下赛 3 线上赛
  82. mcName: "", // 赛事名称
  83. acttime: "", // 活动时间
  84. beginSecond: null, // 活动或赛事开始时间戳,单位秒
  85. endSecond: null, // 活动或赛事结束时间戳,单位秒
  86. coiName: "", // 已报名单位名称,可为空
  87. ocaId: 0, // 关联id,带入到App活动详情页面
  88. teamNum: 0, // 已报名队伍编号,可为0
  89. mcState: 0 , // 赛事/活动状态 0: 未开始 1: 进行中 2: 已结束
  90. allowMcSignUp: false, // 是否允许重新分组
  91. countdown: "", // 倒计时
  92. rankList: { // 排名列表
  93. totalRankRs: [],
  94. teamRankRs: [],
  95. inTeamRs: [],
  96. otherRs: []
  97. },
  98. interval: null,
  99. teamType: 0, // 队伍类型
  100. dispArrStr: "", // 要显示的集合范围 (total,team,in,other)
  101. tabItems: [],
  102. tabCurrent: 0,
  103. cssTop: "",
  104. popupDataList: [],
  105. }
  106. },
  107. computed: {},
  108. onLoad(query) { // 类型非必填,可自动推导
  109. // console.log(query);
  110. this.queryObj = query;
  111. this.queryString = tools.objectToQueryString(this.queryObj);
  112. // console.log(queryString);
  113. this.token = query["token"] ?? token;
  114. this.ecId = query["id"] ?? 0;
  115. this.firstEnterKey += "-" + this.ecId;
  116. console.log("firstEnterKey:", this.firstEnterKey);
  117. this.rankKey += "-" + this.ecId;
  118. console.log("rankKey:", this.rankKey);
  119. tools.removeCssCode();
  120. this.getCardConfigQuery();
  121. this.getUserCurrentRankNumQuery();
  122. this.isAllowMcSignUp();
  123. },
  124. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  125. onReady() {
  126. // this.dealFirstEnter();
  127. },
  128. onUnload() {
  129. this.clear();
  130. },
  131. methods: {
  132. dealNotice(rank) {
  133. // console.log('[dealFirstEnter]');
  134. let that = this;
  135. uni.getStorage({
  136. key: that.rankKey,
  137. success: (res) => {
  138. console.log('[getStorage]', that.rankKey, res.data);
  139. const oldRank = res.data;
  140. if (oldRank != rank) {
  141. // that.notice = true;
  142. that.setRankValue(rank);
  143. }
  144. },
  145. fail: (e) => {
  146. console.log('[getStorage] fail', that.rankKey, e);
  147. // that.notice = false;
  148. that.setRankValue(rank);
  149. },
  150. })
  151. },
  152. setRankValue(data) {
  153. let that = this;
  154. uni.setStorage({
  155. key: that.rankKey,
  156. data: data,
  157. success: () => {
  158. console.log('[setStorage] success', that.rankKey, data);
  159. },
  160. fail: (e) => {
  161. console.log('[setStorage] fail', that.rankKey, e);
  162. },
  163. })
  164. },
  165. dealFirstEnter() {
  166. // console.log('[dealFirstEnter]');
  167. let that = this;
  168. uni.getStorage({
  169. key: that.firstEnterKey,
  170. success: (res) => {
  171. console.log('[getStorage]', that.firstEnterKey, res.data);
  172. },
  173. fail: (e) => {
  174. console.log('[getStorage] fail', that.firstEnterKey, e);
  175. that.btnInfo();
  176. that.setFirstEnterValue(true);
  177. },
  178. })
  179. },
  180. setFirstEnterValue(data) {
  181. let that = this;
  182. uni.setStorage({
  183. key: that.firstEnterKey,
  184. data: data,
  185. success: () => {
  186. console.log('[setStorage] success', that.firstEnterKey, data);
  187. },
  188. fail: (e) => {
  189. console.log('[setStorage] fail', that.firstEnterKey, e);
  190. },
  191. })
  192. },
  193. clear() {
  194. if (this.interval != null) {
  195. clearInterval(this.interval);
  196. this.interval = null;
  197. }
  198. },
  199. loadConfig(config) {
  200. // console.log("config", config);
  201. // 加载CSS样式
  202. const css = config.css;
  203. if (css != undefined && css.length > 0) {
  204. tools.loadCssCode(css);
  205. if (css.indexOf(".top{") >= 0) {
  206. this.cssTop = "top";
  207. }
  208. }
  209. if (this.cssTop == "") {
  210. this.cssTop = "top-default";
  211. }
  212. console.log("[loadConfig] cssTop:", this.cssTop);
  213. // 加载队伍类型 0: 红黄蓝紫 1: 学生/家长
  214. if (config.teamType != undefined && config.teamType >= 0) {
  215. this.teamType = config.teamType;
  216. }
  217. if (this.teamType == 0) {
  218. this.dispArrStr = "total,team,in", // 要显示的集合范围 (total,team,in,other)
  219. this.tabItems = ['总排名', '队伍排名', '队内排名'];
  220. } else if (this.teamType == 1) {
  221. this.dispArrStr = "total,in,other", // 要显示的集合范围 (total,team,in,other)
  222. this.tabItems = ['总排名', '学生排名', '家长排名'];
  223. }
  224. // 加载弹窗数据
  225. const popupDataList = config.popupDataList;
  226. // console.log("[loadConfig] popupDataList:", popupDataList);
  227. if (popupDataList != undefined && popupDataList.length > 0) {
  228. for (var i = 0; i < popupDataList.length; i++) {
  229. // console.log("[loadConfig] popupDataList", i, popupDataList[i]);
  230. if (popupDataList[i] == 'default') {
  231. for (var j = 0; j < defaultPopUpDataList.length; j++) {
  232. this.popupDataList.push(defaultPopUpDataList[j]);
  233. }
  234. } else {
  235. this.popupDataList.push(popupDataList[i]);
  236. }
  237. }
  238. } else {
  239. this.popupDataList = defaultPopUpDataList;
  240. console.log("[loadConfig] popupDataList 加载默认列表");
  241. }
  242. // console.log("[loadConfig] popupDataList:", this.popupDataList);
  243. },
  244. // 获取倒计时
  245. getCountdown() {
  246. // console.log(this.endSecond)
  247. if (this.endSecond > 0) {
  248. const now = Date.now() / 1000;
  249. const dif = this.endSecond - now;
  250. // const dif = 3600*24 - 60;
  251. if (dif > 0) {
  252. this.countdown = '距结束 ' + tools.convertSecondsToDHM(dif);
  253. } else {
  254. this.countdown = "活动已结束";
  255. }
  256. // this.countdown = tools.convertSecondsToHMS(dif);
  257. } else {
  258. this.countdown = "距结束 --天--小时";
  259. }
  260. },
  261. fmtMcTime(timestamp) {
  262. var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  263. // var Y = date.getFullYear() + '-';
  264. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  265. var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  266. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  267. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  268. // var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  269. const timeStr = M + D + h + m;
  270. // console.log("timeStr", timeStr);
  271. return timeStr;
  272. },
  273. // 获取活动时间
  274. getActtime() {
  275. this.acttime = this.fmtMcTime(this.beginSecond) + " 至 " + this.fmtMcTime(this.endSecond);
  276. },
  277. getTeamName(teamType, teamIndex) {
  278. return teamName[teamType][teamIndex];
  279. },
  280. getCardConfigQuery() {
  281. uni.request({
  282. url: apiCardConfigQuery,
  283. header: {
  284. "Content-Type": "application/x-www-form-urlencoded",
  285. "token": this.token,
  286. },
  287. method: "POST",
  288. data: {
  289. ecId: this.ecId,
  290. pageName: this.pageName
  291. },
  292. success: (res) => {
  293. // console.log("getCardConfigQuery", res)
  294. const data = res.data.data;
  295. // console.log("configJson", data.configJson);
  296. const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
  297. // console.log("configJson", data.configJson);
  298. /* const config = {
  299. "css": `
  300. .top{
  301. width: 100%;
  302. height: 26vh;
  303. padding-top: 30px;
  304. justify-content: space-between;
  305. background-image: url('static/backgroud/top_run.png'), url('static/backgroud/top_colorbar.png'), linear-gradient(180deg,#178bff 0%,#004d9b 100%);
  306. background-repeat: no-repeat;
  307. background-position: 45px 25px, center, 0px 0px;
  308. background-size: auto 27vh, auto 22vh , cover;
  309. }
  310. `,
  311. "popupDataList": [
  312. {
  313. "type": 1,
  314. "data": {
  315. "title": "山青活动",
  316. "img": "/static/logo/sqsj.png",
  317. "content": "山青世界为广大青少年提供了亲近自然、劳动实践、拓展培训、军事教育、科普体验、自然探索的平台和机会,也为企事业单位青年团队提供会议培训、拓展训练等服务",
  318. }
  319. },
  320. "default"
  321. ],
  322. "teamType": 1
  323. }; */
  324. this.loadConfig(config);
  325. this.getCardDetailQuery();
  326. setTimeout(this.dealFirstEnter, 500);
  327. },
  328. fail: (err) => {
  329. console.log("getCardConfigQuery err", err)
  330. },
  331. });
  332. },
  333. // 卡片对应活动或赛事详情查询
  334. getCardDetailQuery() {
  335. uni.request({
  336. url: apiCardDetailQuery,
  337. header: {
  338. "Content-Type": "application/x-www-form-urlencoded",
  339. "token": this.token,
  340. },
  341. method: "POST",
  342. data: {
  343. ecId: this.ecId
  344. },
  345. success: (res) => {
  346. // console.log("getCardDetailQuery", res)
  347. const data = res.data.data;
  348. this.mcType = data.mcType;
  349. this.mcId = data.mcId;
  350. this.mcName = data.mcName;
  351. this.beginSecond = data.beginSecond;
  352. this.endSecond = data.endSecond;
  353. this.coiName = data.coiName;
  354. this.teamNum = data.teamNum;
  355. this.ocaId = data.ocaId;
  356. this.mcState = tools.checkMcState(this.beginSecond, this.endSecond);
  357. this.getCountdown();
  358. this.getActtime();
  359. this.getCardRankDetailQuery();
  360. this.clear();
  361. this.interval = setInterval(this.getCountdown, 60000);
  362. },
  363. fail: (err) => {
  364. console.log("getCardDetailQuery err", err)
  365. },
  366. });
  367. },
  368. // 排名查询
  369. getCardRankDetailQuery() {
  370. uni.request({
  371. url: apiCardRankDetailQuery,
  372. header: {
  373. "Content-Type": "application/x-www-form-urlencoded",
  374. "token": this.token,
  375. },
  376. method: "POST",
  377. data: {
  378. mcIdListStr: this.mcId,
  379. mcType: this.mcType,
  380. dispArrStr: this.dispArrStr
  381. },
  382. success: (res) => {
  383. // console.log("getCardRankDetailQuery", res)
  384. const rankdata = res.data.data;
  385. this.rankList.totalRankRs = rankdata.totalRankRs;
  386. this.rankList.teamRankRs = rankdata.teamRankRs;
  387. this.rankList.inTeamRs = rankdata.inTeamRs;
  388. this.rankList.otherRs = rankdata.otherRs;
  389. },
  390. fail: (err) => {
  391. console.log("getCardRankDetailQuery err", err)
  392. },
  393. });
  394. },
  395. // 卡片用户当前排名查询
  396. getUserCurrentRankNumQuery() {
  397. uni.request({
  398. url: apiUserCurrentRankNumQuery,
  399. header: {
  400. "Content-Type": "application/x-www-form-urlencoded",
  401. "token": this.token,
  402. },
  403. method: "POST",
  404. data: {
  405. ecId: this.ecId
  406. },
  407. success: (res) => {
  408. // console.log("getUserCurrentRankNumQuery", res)
  409. if (res.data.code == 0) {
  410. const data = res.data.data;
  411. const rankNum = data.rankNum;
  412. this.dealNotice(rankNum);
  413. }
  414. },
  415. fail: (err) => {
  416. console.log("getUserCurrentRankNumQuery err", err)
  417. },
  418. });
  419. },
  420. // 是否允许重新分组(报名)
  421. isAllowMcSignUp() {
  422. uni.request({
  423. url: apiIsAllowMcSignUp,
  424. header: {
  425. "Content-Type": "application/x-www-form-urlencoded",
  426. "token": this.token,
  427. },
  428. method: "POST",
  429. data: {
  430. ecId: this.ecId
  431. },
  432. success: (res) => {
  433. // console.log("isAllowMcSignUp", res)
  434. if (res.data.code == 0) {
  435. const data = res.data.data;
  436. this.allowMcSignUp = data.allowSignUp;
  437. }
  438. },
  439. fail: (err) => {
  440. console.log("isAllowMcSignUp err", err)
  441. },
  442. });
  443. },
  444. btnBack() {
  445. // window.history.back();
  446. const url = `action://to_home/`;
  447. // window.location.href = url;
  448. tools.appAction(url);
  449. },
  450. btnReGroup() {
  451. this.queryObj.from = "rankList";
  452. this.queryString = tools.objectToQueryString(this.queryObj);
  453. uni.navigateTo({
  454. url: '/pages/bm/style1/signup?' + this.queryString
  455. });
  456. },
  457. btnStart() {
  458. const url = `action://to_detail/?id=${this.ocaId}&matchType=${this.mcType}`;
  459. // window.location.href = url;
  460. tools.appAction(url);
  461. },
  462. btnInfo() {
  463. // console.log(this.$refs.mypopup);
  464. this.$refs.mypopup.popupOpen();
  465. },
  466. onClickTabItem(e) {
  467. if (this.tabCurrent != e.currentIndex) {
  468. this.tabCurrent = e.currentIndex;
  469. }
  470. }
  471. }
  472. }
  473. </script>
  474. <style scoped>
  475. .content {
  476. width: 100vw;
  477. height: 100vh;
  478. }
  479. .top-default {
  480. width: 100%;
  481. height: 24.6vh;
  482. padding-top: 36px;
  483. justify-content: space-between;
  484. background-image: url("/static/backgroud/top_run.png"), url("/static/backgroud/top_colorbar.png"), linear-gradient(180deg,#f8a95a 0%,#d25f11 100%);
  485. /* background-image: url("/static/backgroud/top_run.png"), url("/static/backgroud/top_colorbar.png"), linear-gradient(180deg,#7aedff 0%,#047200 100%); */
  486. /* background-image: url("/static/backgroud/top_run.png"), url("/static/backgroud/top_colorbar.png"), linear-gradient(180deg,#178bff 0%,#004d9b 100%); */
  487. background-repeat: no-repeat;
  488. background-position: 45px 25px, center, 0px 0px;
  489. /* background-position-x: center; */
  490. /* background-position-y: center; */
  491. background-size: auto 27vh, auto 22vh , cover;
  492. }
  493. .topbar {
  494. width: 90%;
  495. justify-content: space-between;
  496. }
  497. .topbar-back {
  498. width: 43rpx;
  499. height: 43rpx;
  500. /* opacity: 0; */
  501. }
  502. .topbar-info {
  503. width: 46rpx;
  504. height: 46rpx;
  505. }
  506. .topbar-rule {
  507. color: white;
  508. font-size: 32rpx;
  509. }
  510. .mcName {
  511. color: white;
  512. font-size: 39rpx;
  513. font-weight: bold;
  514. }
  515. .topcontent {
  516. /* height: 1300rpx; */
  517. /* background-color: #2e85ec; */
  518. margin-top: 50rpx;
  519. justify-content: center;
  520. }
  521. .top-countdown {
  522. height: 90rpx;
  523. color: #ffdc51;
  524. font-size: 28rpx;
  525. }
  526. .cal {
  527. width: 46rpx;
  528. height: 46rpx;
  529. margin-right: 20rpx;
  530. }
  531. .toptext {
  532. margin: 0 10rpx;
  533. color: #ffffff;
  534. font-size: 35rpx;
  535. font-weight: 500;
  536. line-height: 60rpx;
  537. }
  538. .btnReGroup {
  539. width: 130rpx;
  540. height: 36rpx;
  541. margin-top: 15rpx;
  542. margin-bottom: 15rpx;
  543. background: #ffcb00;
  544. border-radius: 15px;
  545. color: #000000;
  546. font-size: 24rpx;
  547. text-align: center;
  548. line-height: 36rpx;
  549. }
  550. .topbtm {
  551. width: 100%;
  552. height: 60rpx;
  553. margin-bottom: 10rpx;
  554. justify-content: space-evenly;
  555. }
  556. .topbtm-content {
  557. width: 100%;
  558. justify-content: space-around;
  559. /* justify-content: space-between; */
  560. }
  561. .topbtm-sspm {
  562. width: 120rpx;
  563. color: #ffee00;
  564. font-size: 24rpx;
  565. text-align: center;
  566. }
  567. .main {
  568. width: 100%;
  569. /* height: 70vh; */
  570. flex-grow: 1;
  571. justify-content: space-around;
  572. /* justify-content: space-between; */
  573. }
  574. .main-tab {
  575. width: 90%;
  576. margin-top: 20rpx;
  577. }
  578. .tab-view {
  579. width: 100%;
  580. /* height: 69vh; */
  581. flex-grow: 1;
  582. }
  583. .btnStart {
  584. width: 70%;
  585. /* height: 6vh; */
  586. height: 80rpx;
  587. /* margin-bottom: 1vh; */
  588. margin-bottom: 20rpx;
  589. /* font-weight: bold; */
  590. color: white;
  591. font-size: 32rpx;
  592. line-height: 80rpx;
  593. border-radius: 27px;
  594. }
  595. .btnStart-enable {
  596. background-color: #ffb40b;
  597. }
  598. .btnStart-disable {
  599. background-color: #c3c3c3;
  600. }
  601. </style>