detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <!--
  2. 每月挑战 - 详情
  3. http://localhost:5173/card/#/pages/mytz/detail
  4. https://oss-mbh5.colormaprun.com/card/#/pages/mytz/detail
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content uni-column">
  9. <view class="top uni-column">
  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">{{ecName}}</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. <text class="toplogo">{{curMonth}}</text>
  17. <text class="cardDesc">{{ecDesc}}</text>
  18. </view>
  19. <view class="main uni-column">
  20. <view class="cupview uni-column">
  21. <view class="cup" :style="getCupStyle('cup')">
  22. <view class="cup-gray" :style="getCupStyle('cup-gray')"></view>
  23. </view>
  24. <text class="cup-text"><text style="font-weight: 600;">{{month}}月</text> |
  25. {{realNum}}/{{targetNum}}</text>
  26. <text class="cup-text2">{{progressText}}</text>
  27. </view>
  28. <button class="btnStart" @click="btnStart">{{btnText}}</button>
  29. </view>
  30. </view>
  31. <uni-popup ref="popup" :mask-click="false" maskBackgroundColor="rgba(0, 0, 0, 0.6)">
  32. <view class="popup">
  33. <swiper ref="swiper" class="swiper" :current="swiperCurrent" @change="swiperChange"
  34. :indicator-dots="false" indicator-active-color="rgba(46, 133, 236, 1)" :autoplay="false"
  35. :interval="5000">
  36. <swiper-item class="swiper-item uni-column">
  37. <view class="introduce uni-column">
  38. <text class="introduce-title">挑战赛规则</text>
  39. <view>
  40. <text class="introduce-sn">①</text>
  41. <text class="introduce-content">选任意定向地图,完成{{targetNum}}次挑战,你就胜利啦!</text>
  42. </view>
  43. <view>
  44. <text class="introduce-sn">②</text>
  45. <text class="introduce-content">挑战成功,会点亮你的电子奖杯!</text>
  46. </view>
  47. <view>
  48. <text class="introduce-sn">③</text>
  49. <text class="introduce-content">定向里程累计5千米,就有一枚奖章等你哦!</text>
  50. </view>
  51. </view>
  52. <image class="main-pic" mode="aspectFit" src="/static/mytz/main_pic.png"></image>
  53. <button class="swiper-item-button" @click="popupClose">确定</button>
  54. </swiper-item>
  55. </swiper>
  56. </view>
  57. </uni-popup>
  58. </view>
  59. </template>
  60. <script>
  61. import tools from '../../common/tools';
  62. import {
  63. token,
  64. apiCardBaseQuery,
  65. apiCurrentMonthlyChallengeQuery,
  66. checkResCode,
  67. checkToken
  68. } from '../../common/api';
  69. export default {
  70. data() {
  71. return {
  72. pageName: "mytz",
  73. rankKey: "rank-mytz",
  74. queryObj: {},
  75. queryString: "",
  76. token: "",
  77. tokenValid: false,
  78. ecId: 0, // 卡片id
  79. ecName: '', // 卡片名称
  80. ecDesc: '', // 卡片简介
  81. month: '', // 月名称
  82. realNum: 0, // 实际完赛次数
  83. targetNum: 0, // 要求完赛次数
  84. // mcType: 0, // 赛事类型 1 普通活动 2 线下赛 3 线上赛
  85. // mcName: "", // 赛事名称
  86. swiperCurrent: 0, // swiper当前所在滑块的 index
  87. cupProgress: 100, // 奖杯进度 (100 - 实际进度,初始值为100)
  88. progressText: "",
  89. btnText: "",
  90. }
  91. },
  92. computed: {
  93. curMonth() {
  94. var currentDate = new Date();
  95. var currentMonth = currentDate.getMonth() + 1; // 月份从0开始,所以要加1
  96. return `${currentMonth}月`;
  97. },
  98. },
  99. onLoad(query) { // 类型非必填,可自动推导
  100. // console.log(query);
  101. this.queryObj = query;
  102. this.queryString = tools.objectToQueryString(this.queryObj);
  103. // console.log(queryString);
  104. this.token = query["token"] ?? token;
  105. this.ecId = query["id"] ?? 0;
  106. this.getCardBaseQuery();
  107. this.getCurrentMonthlyChallengeQuery();
  108. },
  109. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  110. onReady() {
  111. this.dealFirstEnter();
  112. },
  113. onUnload() {},
  114. methods: {
  115. dealNotice(rank) {
  116. // console.log('[dealFirstEnter]');
  117. let that = this;
  118. uni.getStorage({
  119. key: that.rankKey,
  120. success: (res) => {
  121. console.log('[getStorage]', that.rankKey, res.data);
  122. const oldRank = res.data;
  123. if (oldRank != rank) {
  124. // that.notice = true;
  125. that.setRankValue(rank);
  126. }
  127. },
  128. fail: (e) => {
  129. console.log('[getStorage] fail', that.rankKey, e);
  130. // that.notice = false;
  131. that.setRankValue(rank);
  132. },
  133. })
  134. },
  135. setRankValue(data) {
  136. let that = this;
  137. uni.setStorage({
  138. key: that.rankKey,
  139. data: data,
  140. success: () => {
  141. console.log('[setStorage] success', that.rankKey, data);
  142. },
  143. fail: (e) => {
  144. console.log('[setStorage] fail', that.rankKey, e);
  145. },
  146. })
  147. },
  148. dealFirstEnter() {
  149. // console.log('[dealFirstEnter]');
  150. let that = this;
  151. uni.getStorage({
  152. key: that.firstEnterKey,
  153. success: (res) => {
  154. console.log('[getStorage]', that.firstEnterKey, res.data);
  155. },
  156. fail: (e) => {
  157. console.log('[getStorage] fail', that.firstEnterKey, e);
  158. that.btnInfo();
  159. that.setFirstEnterValue(true);
  160. },
  161. })
  162. },
  163. setFirstEnterValue(data) {
  164. let that = this;
  165. uni.setStorage({
  166. key: that.firstEnterKey,
  167. data: data,
  168. success: () => {
  169. console.log('[setStorage] success', that.firstEnterKey, data);
  170. },
  171. fail: (e) => {
  172. console.log('[setStorage] fail', that.firstEnterKey, e);
  173. },
  174. })
  175. },
  176. getCupProgress() {
  177. if (this.targetNum > 0 && this.realNum > 0) {
  178. if (this.realNum < this.targetNum) {
  179. const progress = this.realNum / this.targetNum * 100;
  180. this.cupProgress = 100 - progress;
  181. } else {
  182. this.cupProgress = 0;
  183. }
  184. } else {
  185. this.cupProgress = 100;
  186. }
  187. // console.log("cupProgress:", this.cupProgress);
  188. },
  189. getText() {
  190. if (!this.tokenValid) {
  191. this.progressText = `您尚未登录,欢迎参加挑战!!`;
  192. this.btnText = "开始挑战";
  193. }
  194. else if (this.realNum == 0) {
  195. this.progressText = `您尚未开始,欢迎参加挑战!!`;
  196. this.btnText = "开始挑战";
  197. }
  198. else if (this.realNum > 0 && this.realNum < this.targetNum) {
  199. this.progressText = `您已完成了${this.realNum}次挑战,继续加油!!`;
  200. this.btnText = "继续挑战";
  201. } else if (this.realNum > 0 && this.realNum >= this.targetNum){
  202. this.progressText = `恭喜,挑战成功!!`;
  203. this.btnText = "继续挑战";
  204. } else {
  205. this.progressText = ``;
  206. this.btnText = "开始挑战";
  207. }
  208. },
  209. getCupStyle(type) {
  210. if (! (this.month > 0)) {
  211. return '';
  212. }
  213. let group = 1;
  214. if (type == 'cup') {
  215. return `background-image: url("static/cup/${group}/${this.month}.png")`;
  216. } else if (type == 'cup-gray') {
  217. return `background-image: url("static/cup/${group}/${this.month}h.png"); height:${this.cupProgress}% ;`;
  218. }
  219. },
  220. // 卡片基本信息查询
  221. getCardBaseQuery() {
  222. uni.request({
  223. url: apiCardBaseQuery,
  224. header: {
  225. "Content-Type": "application/x-www-form-urlencoded",
  226. "token": this.token,
  227. },
  228. method: "POST",
  229. data: {
  230. ecId: this.ecId
  231. },
  232. success: (res) => {
  233. // console.log("getCardBaseQuery", res)
  234. const data = res.data.data;
  235. this.ecName = data.ecName;
  236. this.ecDesc = data.ecDesc;
  237. },
  238. fail: (err) => {
  239. console.log("getCardBaseQuery err", err)
  240. },
  241. });
  242. },
  243. // 玩家当前月挑战记录查询
  244. getCurrentMonthlyChallengeQuery() {
  245. uni.request({
  246. url: apiCurrentMonthlyChallengeQuery,
  247. header: {
  248. "Content-Type": "application/x-www-form-urlencoded",
  249. "token": this.token,
  250. },
  251. method: "POST",
  252. data: {},
  253. success: (res) => {
  254. // console.log("getCurrentMonthlyChallengeQuery", res);
  255. if (checkResCode(res)) {
  256. if (res.statusCode == 401) { // 未登录
  257. this.tokenValid = false;
  258. } else {
  259. this.tokenValid = true;
  260. }
  261. const data = res.data.data;
  262. this.month = data.month;
  263. this.realNum = data.realNum;
  264. this.targetNum = data.targetNum;
  265. this.dealNotice(this.realNum);
  266. this.getCupProgress();
  267. this.getText();
  268. }
  269. },
  270. fail: (err) => {
  271. console.log("getCurrentMonthlyChallengeQuery err", err)
  272. },
  273. });
  274. },
  275. btnBack() {
  276. // window.history.back();
  277. const url = `action://to_home/`;
  278. // window.location.href = url;
  279. tools.appAction(url);
  280. },
  281. btnInfo() {
  282. this.swiperCurrent = 0;
  283. this.$refs.popup.open();
  284. },
  285. btnStart() {
  286. const url = `action://to_map_list/`;
  287. // window.location.href = url;
  288. tools.appAction(url);
  289. },
  290. //当前轮播索引
  291. swiperChange(e) {
  292. const curIndex = e.detail.current;
  293. this.swiperCurrent = curIndex;
  294. },
  295. swiperNext() {
  296. this.swiperCurrent++;
  297. },
  298. popupClose() {
  299. this.$refs.popup.close()
  300. }
  301. }
  302. }
  303. </script>
  304. <style scoped>
  305. .content {
  306. width: 100vw;
  307. height: 100vh;
  308. }
  309. .top {
  310. width: 100%;
  311. height: 350rpx;
  312. padding-top: 36px;
  313. padding-bottom: 30px;
  314. justify-content: space-between;
  315. background-image: url("/static/backgroud/top_run.png"), linear-gradient(180deg, #178bff 0%, #004d9b 100%);
  316. background-repeat: no-repeat;
  317. background-position: 50rpx 50rpx, 0rpx 0rpx;
  318. /* background-position-x: center; */
  319. /* background-position-y: center; */
  320. background-size: auto 430rpx, contain;
  321. }
  322. .topbar {
  323. width: 90%;
  324. padding: 0rpx 30rpx;
  325. justify-content: space-between;
  326. }
  327. .topbar-back {
  328. width: 43rpx;
  329. height: 43rpx;
  330. /* opacity: 0; */
  331. }
  332. .topbar-info {
  333. width: 46rpx;
  334. height: 46rpx;
  335. /* opacity: 0; */
  336. }
  337. .topbar-rule {
  338. color: white;
  339. font-size: 32rpx;
  340. }
  341. .mcName {
  342. color: white;
  343. font-size: 40rpx;
  344. font-weight: 550;
  345. }
  346. .toplogo {
  347. width: 180rpx;
  348. height: 180rpx;
  349. /* margin-top: 20rpx; */
  350. background: url("/static/mytz/month_bg.png") no-repeat center;
  351. background-size: contain;
  352. color: #ff870d;
  353. font-size: 24px;
  354. font-weight: 700;
  355. text-align: center;
  356. line-height: 220rpx;
  357. }
  358. .cardDesc {
  359. /* font-weight: 550; */
  360. color: white;
  361. font-size: 32rpx;
  362. }
  363. .main {
  364. width: 80%;
  365. /* height: 800rpx; */
  366. flex-grow: 0.5;
  367. justify-content: space-between;
  368. }
  369. .cupview {
  370. height: 500rpx;
  371. margin-top: 150rpx;
  372. }
  373. .cup {
  374. width: 320rpx;
  375. height: 320rpx;
  376. /* background-image: url("/static/cup/004.png"); */
  377. background-position-x: center;
  378. background-repeat: no-repeat;
  379. background-size: 300rpx auto;
  380. }
  381. .cup-gray {
  382. width: 320rpx;
  383. /* height: 30%; */
  384. /* background-image: url("/static/cup/004h.png"); */
  385. background-position-x: center;
  386. background-repeat: no-repeat;
  387. background-size: 300rpx auto;
  388. overflow: hidden;
  389. /* filter: grayscale(1); */
  390. }
  391. .cup-text {
  392. color: #818181;
  393. font-size: 28rpx;
  394. line-height: 100rpx;
  395. }
  396. .cup-text2 {
  397. color: #333333;
  398. font-size: 28rpx;
  399. line-height: 100rpx;
  400. }
  401. .introduce {
  402. width: 80%;
  403. align-items: flex-start;
  404. justify-content: space-around;
  405. }
  406. .introduce-title {
  407. margin-top: 70rpx;
  408. margin-bottom: 60rpx;
  409. width: 100%;
  410. color: #333333;
  411. font-size: 36rpx;
  412. font-weight: 700;
  413. /* line-height: 60rpx; */
  414. text-align: center;
  415. }
  416. .introduce-sn {
  417. margin-right: 10rpx;
  418. color: #a16221;
  419. font-size: 38rpx;
  420. font-weight: 550;
  421. }
  422. .introduce-content {
  423. color: #333333;
  424. font-size: 28rpx;
  425. line-height: 72rpx;
  426. }
  427. .main-pic {
  428. width: 90%;
  429. height: 200rpx;
  430. }
  431. .btnStart {
  432. width: 100%;
  433. height: 100rpx;
  434. margin-bottom: 30rpx;
  435. color: white;
  436. font-weight: bold;
  437. line-height: 100rpx;
  438. background-color: #2e85ec;
  439. border-radius: 55rpx;
  440. }
  441. .popup {
  442. width: 90vw;
  443. height: 900rpx;
  444. background-color: #FEFBF6;
  445. border-radius: 50rpx;
  446. }
  447. .swiper {
  448. height: 100%;
  449. }
  450. .swiper-item {
  451. /* height: 80vh; */
  452. justify-content: space-between;
  453. /* background-color: lightblue; */
  454. }
  455. .swiper-item-title {
  456. margin-top: 80rpx;
  457. font-size: 40rpx;
  458. }
  459. .swiper-item-image {
  460. height: 300rpx;
  461. }
  462. .swiper-item-content {
  463. height: 100rpx;
  464. justify-content: start;
  465. }
  466. .swiper-item-button {
  467. width: 80%;
  468. height: 106rpx;
  469. margin-bottom: 80rpx;
  470. color: #ffffff;
  471. /* font-weight: bold; */
  472. line-height: 106rpx;
  473. background-color: #2e85ec;
  474. border-radius: 27px;
  475. }
  476. ::v-deep .uni-swiper-dots-horizontal {
  477. bottom: 230rpx;
  478. }
  479. </style>