detail.vue 12 KB

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