rankList.vue 18 KB

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