index2.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <!--
  2. 成就 v2
  3. http://localhost:5173/card/#/pages/achievement/index2
  4. https://oss-mbh5.colormaprun.com/card/#/pages/achievement/index2
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content uni-column">
  9. <view class="topbar uni-row">
  10. <uni-icons v-if="showBack" type="left" class="topbar-back" @click="btnBack"></uni-icons>
  11. <text class="topbar-back" v-else></text>
  12. <text>成就</text>
  13. <text class="topbar-back"></text>
  14. </view>
  15. <my-tab ref="tab1" :initActIndex="tabCurrent" :tabItems="tabItems" :type="1" @onTabClick="onTabClick"></my-tab>
  16. <view class="main">
  17. <!-- 挑战 -->
  18. <view v-if="tabCurrent == 0">
  19. <view class="norecord" v-if="challengeRs == null || challengeRs.length == 0">暂无记录</view>
  20. <view class="uni-column" v-for="(item, index) in challengeRs" :key="index">
  21. <text class="year">{{item.year}}</text>
  22. <view class="norecord2" v-if="item.monthRs == null || item.monthRs.length == 0">暂无记录</view>
  23. <view class="list uni-row" v-else>
  24. <view class="item uni-column" v-for="(item2, index2) in item.monthRs" :key="index2">
  25. <view class="item-cup" :style="getCupStyle('cup', item2.month)">
  26. <view class="item-cup-gray"
  27. :style="getCupStyle('cup-gray', item2.month, getCupProgress(item2.targetNum, item2.realNum))">
  28. </view>
  29. </view>
  30. <view class="item-title uni-row">
  31. <text class="item-title-month">{{item2.month}}月</text>
  32. <view class="item-title-divide"></view>
  33. <text class="item-title-progress">{{item2.realNum}}/{{item2.targetNum}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 奖牌 -->
  40. <view v-if="tabCurrent == 1">
  41. <view class="norecord" v-if="activityRs == null || activityRs.length == 0">暂无记录</view>
  42. <view class="uni-column" v-for="(item, index) in activityRs" :key="index">
  43. <text class="year">{{item.year}}</text>
  44. <view class="norecord2" v-if="item.aiRs == null || item.aiRs.length == 0">暂无记录</view>
  45. <view class="list uni-row" v-else>
  46. <view class="item item-bg uni-column" v-for="(item2, index2) in item.aiRs" :key="index2"
  47. @click="showAchDetail(item2)">
  48. <view class="item-medal" :style="getMedalStyle(item2.iconUrl)"></view>
  49. <view class="item-title uni-column">
  50. <view class="item-title-ainame">{{item2.aiName}}</view>
  51. <view class="item-title-aitime">{{fmtTime(item2.aiTime)}}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 兑换 -->
  58. <view v-if="tabCurrent == 2">
  59. <view class="norecord" v-if="exchangeRs == null || exchangeRs.length == 0">暂无记录</view>
  60. <view class="uni-column" v-for="(item, index) in exchangeRs" :key="index">
  61. <text class="year">{{item.year}}</text>
  62. <view class="norecord2" v-if="item.aiRs == null || item.aiRs.length == 0">暂无记录</view>
  63. <view class="list uni-row" v-else>
  64. <view class="item uni-column"
  65. :class="item2.exState==1 ? 'item-convertible' : 'item-converted'"
  66. v-for="(item2, index2) in item.aiRs" :key="index2" @click="showAchDetail(item2)">
  67. <view class="item-medal" :style="getMedalStyle(item2.iconUrl)"></view>
  68. <view class="item-title uni-column">
  69. <view class="item-title-ainame">{{item2.aiName}}</view>
  70. <view class="item-title-aitime">{{fmtTime(item2.aiTime)}}</view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 页面载入后,弹窗显示新获取的成就 -->
  79. <my-popup ref="popupNewach" :dataList="popupDataList" @popup-close="onPopupNewachClose"></my-popup>
  80. <!-- 点击成就列表项后,弹窗显示对应的成就内容 -->
  81. <my-popup ref="popupAchdet" :dataList="popupAchdet" @popup-close="onPopupAchdetClose"></my-popup>
  82. <!-- <my-popup-map ref="mypopupmap" :point="point"></my-popup-map> -->
  83. </view>
  84. </template>
  85. <script>
  86. import tools from '../../common/tools';
  87. import {
  88. token,
  89. apiMonthlyChallengeQuery,
  90. apiAchievementQuery,
  91. apiExchangeListQuery,
  92. apiExchangeDetailQuery,
  93. apiUnReadMessageQuery,
  94. apiReadMessage,
  95. checkResCode
  96. } from '../../common/api';
  97. export default {
  98. data() {
  99. return {
  100. queryObj: {},
  101. queryString: "",
  102. token: "",
  103. tokenValid: false,
  104. challengeRs: [], // 挑战成就集合
  105. activityRs: [], // 活动成就集合
  106. exchangeRs: [], // 兑换记录集合
  107. unReadMessageRs: [], // 未读消息列表
  108. mqIdListStr: "", // 已读消息id列表 逗号分隔
  109. tabItems: ["挑战", "奖牌", "兑换"],
  110. tabCurrent: 0,
  111. popupDataList: [], // 弹窗数据:新获取的成就
  112. popupAchdet: [], // 弹窗数据:用户点击的成就列表项
  113. point: {
  114. longitude: 117.022194,
  115. latitude: 36.661612,
  116. name: "泉城广场定向赛起始点",
  117. },
  118. interval: null,
  119. showBack: false, // 是否在导航栏显示返回按钮
  120. }
  121. },
  122. computed: {},
  123. onLoad(query) { // 类型非必填,可自动推导
  124. // console.log(query);
  125. this.queryObj = query;
  126. this.queryString = tools.objectToQueryString(this.queryObj);
  127. // console.log(queryString);
  128. this.token = query["token"] ?? token;
  129. this.tabCurrent = parseInt(query["tabCurrent"] ?? 0);
  130. this.showBack = query["tabCurrent"] >= 0 ? true : false;
  131. this.getMonthlyChallengeQuery();
  132. this.getAchievementQuery();
  133. this.getExchangeListQuery();
  134. this.getUnReadMessageQuery();
  135. },
  136. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  137. onReady() {},
  138. onUnload() {
  139. if (this.interval != null) {
  140. clearInterval(this.interval);
  141. this.interval = null;
  142. }
  143. },
  144. methods: {
  145. getCupProgress(targetNum, realNum) {
  146. let cupProgress = 100;
  147. if (targetNum > 0 && realNum > 0) {
  148. if (realNum < targetNum) {
  149. const progress = realNum / targetNum * 100;
  150. cupProgress = 100 - progress;
  151. } else {
  152. cupProgress = 0;
  153. }
  154. }
  155. // console.log("cupProgress:", cupProgress);
  156. return cupProgress;
  157. },
  158. getCupStyle(type, month, cupProgress = 0) {
  159. if (!(month > 0)) {
  160. return '';
  161. }
  162. let group = 1;
  163. if (type == 'cup') {
  164. return `background-image: url("static/cup/${group}/${month}.png")`;
  165. } else if (type == 'cup-gray') {
  166. return `background-image: url("static/cup/${group}/${month}h.png"); height:${cupProgress}% ;`;
  167. }
  168. },
  169. getMedalStyle(bgurl) {
  170. return `background-image: url("${bgurl}")`;
  171. },
  172. fmtTime(timestamp, type = 2) {
  173. return tools.timestampToTime(timestamp * 1000, type);
  174. },
  175. // 玩家所有月挑战记录查询
  176. getMonthlyChallengeQuery() {
  177. uni.request({
  178. url: apiMonthlyChallengeQuery,
  179. header: {
  180. "Content-Type": "application/x-www-form-urlencoded",
  181. "token": this.token,
  182. },
  183. method: "POST",
  184. data: {},
  185. success: (res) => {
  186. // console.log("getMonthlyChallengeQuery", res);
  187. if (checkResCode(res)) {
  188. if (res.statusCode == 401) { // 未登录
  189. this.tokenValid = false;
  190. } else {
  191. this.tokenValid = true;
  192. }
  193. this.challengeRs = res.data.data;
  194. }
  195. },
  196. fail: (err) => {
  197. console.log("getMonthlyChallengeQuery err", err)
  198. },
  199. });
  200. },
  201. // 玩家活动成就查询
  202. getAchievementQuery() {
  203. uni.request({
  204. url: apiAchievementQuery,
  205. header: {
  206. "Content-Type": "application/x-www-form-urlencoded",
  207. "token": this.token,
  208. },
  209. method: "POST",
  210. data: {},
  211. success: (res) => {
  212. // console.log("getAchievementQuery", res);
  213. if (checkResCode(res)) {
  214. if (res.statusCode == 401) { // 未登录
  215. this.tokenValid = false;
  216. } else {
  217. this.tokenValid = true;
  218. }
  219. this.activityRs = res.data.data;
  220. }
  221. },
  222. fail: (err) => {
  223. console.log("getAchievementQuery err", err);
  224. },
  225. });
  226. },
  227. // 玩家兑换记录查询
  228. getExchangeListQuery() {
  229. uni.request({
  230. url: apiExchangeListQuery,
  231. header: {
  232. "Content-Type": "application/x-www-form-urlencoded",
  233. "token": this.token,
  234. },
  235. method: "POST",
  236. data: {},
  237. success: (res) => {
  238. // console.log("getExchangeListQuery", res);
  239. if (checkResCode(res)) {
  240. if (res.statusCode == 401) { // 未登录
  241. this.tokenValid = false;
  242. } else {
  243. this.tokenValid = true;
  244. }
  245. this.exchangeRs = res.data.data;
  246. }
  247. },
  248. fail: (err) => {
  249. console.log("getExchangeListQuery err", err);
  250. },
  251. });
  252. },
  253. // 玩家兑换详情查询
  254. exchangeDetailQuery(oarId) {
  255. uni.request({
  256. url: apiExchangeDetailQuery,
  257. header: {
  258. "Content-Type": "application/x-www-form-urlencoded",
  259. "token": this.token,
  260. },
  261. method: "POST",
  262. data: {
  263. oarId: oarId
  264. },
  265. success: (res) => {
  266. // console.log("exchangeDetailQuery", res);
  267. if (checkResCode(res)) {
  268. const data = res.data.data;
  269. // 弹窗已获取数据且可兑换状态时,不再更新弹窗数据
  270. if (this.popupAchdet.length > 0 && this.popupAchdet[0].qrCode != "" && data
  271. .qrCode != "") {
  272. return;
  273. }
  274. this.popupAchdet = [{
  275. "type": 4,
  276. "data": {
  277. "title": "兑换",
  278. "img": data.iconUrl,
  279. "content": data.aiName,
  280. "qrCode": data.qrCode,
  281. "exTime": this.fmtTime(data.exTime, 0)
  282. },
  283. }];
  284. if (data.qrCode == "") { // 已兑换
  285. clearInterval(this.interval);
  286. this.interval = null;
  287. }
  288. if (!this.$refs.popupAchdet.isOpen) {
  289. setTimeout(() => {
  290. this.$refs.popupAchdet.popupOpen();
  291. }, 100);
  292. }
  293. }
  294. },
  295. fail: (err) => {
  296. console.log("exchangeDetailQuery err", err);
  297. },
  298. });
  299. },
  300. // 未读消息列表查询
  301. getUnReadMessageQuery() {
  302. uni.request({
  303. url: apiUnReadMessageQuery,
  304. header: {
  305. "Content-Type": "application/x-www-form-urlencoded",
  306. "token": this.token,
  307. },
  308. method: "POST",
  309. data: {},
  310. success: (res) => {
  311. // console.log("getUnReadMessageQuery", res);
  312. if (checkResCode(res)) {
  313. if (res.statusCode == 401) { // 未登录
  314. this.tokenValid = false;
  315. } else {
  316. this.tokenValid = true;
  317. }
  318. this.unReadMessageRs = res.data.data;
  319. this.mqIdListStr = "";
  320. for (var i = 0; i < this.unReadMessageRs.length; i++) {
  321. let popupData = {
  322. type: 3,
  323. data: {}
  324. };
  325. if (this.unReadMessageRs[i].mqType == 1) { // 消息类型 1: 成就
  326. popupData.data.title = "恭喜";
  327. }
  328. popupData.data.img = this.unReadMessageRs[i].iconUrl;
  329. popupData.data.content = "恭喜获得成就 \r\n" + this.unReadMessageRs[i].aiName;
  330. this.popupDataList.push(popupData);
  331. this.mqIdListStr += this.unReadMessageRs[i].mqId;
  332. if (i < this.unReadMessageRs.length - 1) {
  333. this.mqIdListStr += ",";
  334. }
  335. }
  336. if (this.popupDataList.length > 0) {
  337. this.$refs.popupNewach.popupOpen();
  338. }
  339. }
  340. },
  341. fail: (err) => {
  342. console.log("getUnReadMessageQuery err", err);
  343. },
  344. });
  345. },
  346. // 标记消息已读
  347. readMessage() {
  348. uni.request({
  349. url: apiReadMessage,
  350. header: {
  351. "Content-Type": "application/x-www-form-urlencoded",
  352. "token": this.token,
  353. },
  354. method: "POST",
  355. data: {
  356. "mqIdListStr": this.mqIdListStr
  357. },
  358. success: (res) => {
  359. // console.log("readMessage", res);
  360. },
  361. fail: (err) => {
  362. console.log("readMessage err", err);
  363. },
  364. });
  365. },
  366. showAchDetail(data) {
  367. // console.log("showAchDetail", data);
  368. this.popupAchdet.length = 0;
  369. if (this.tabCurrent == 1) { // 奖牌
  370. let popupData = {
  371. type: 3,
  372. data: {}
  373. };
  374. popupData.data.title = "恭喜";
  375. popupData.data.img = data.iconUrl;
  376. popupData.data.content = "恭喜获得成就 \r\n" + data.aiName;
  377. this.popupAchdet.push(popupData);
  378. this.$refs.popupAchdet.popupOpen();
  379. }
  380. if (this.tabCurrent == 2) { // 兑换
  381. this.exchangeDetailQuery(data.oarId);
  382. this.interval = setInterval(this.exchangeDetailQuery, 2000, data.oarId);
  383. }
  384. },
  385. onPopupNewachClose() {
  386. // console.log("onPopupNewachClose");
  387. this.readMessage();
  388. },
  389. onPopupAchdetClose() {
  390. // console.log("onPopupAchdetClose");
  391. if (this.interval != null) {
  392. clearInterval(this.interval);
  393. this.interval = null;
  394. }
  395. if (this.tabCurrent == 2) { // 兑换
  396. this.getExchangeListQuery();
  397. }
  398. },
  399. btnBack() {
  400. window.history.back();
  401. },
  402. onTabClick(val) {
  403. // console.log("onTabClick: ", val);
  404. this.tabCurrent = val;
  405. },
  406. test() {
  407. // this.$refs.mypopupmap.popupOpen();
  408. const url =
  409. `action://to_map_app?title=${this.point.name}&latitude=${this.point.latitude}&longitude=${this.point.longitude}`;
  410. tools.appAction(url);
  411. }
  412. }
  413. }
  414. </script>
  415. <style scoped>
  416. .content {
  417. width: 100vw;
  418. height: 100vh;
  419. justify-content: flex-start;
  420. }
  421. .topbar {
  422. width: 90%;
  423. margin-top: 80rpx;
  424. justify-content: space-between;
  425. font-weight: 550;
  426. color: #333333;
  427. font-size: 18px;
  428. }
  429. .topbar-back {
  430. width: 43rpx;
  431. height: 43rpx;
  432. color: inherit !important;
  433. font-size: 48rpx !important;
  434. /* opacity: 0; */
  435. }
  436. .main {
  437. width: 90%;
  438. padding-top: 30rpx;
  439. padding-bottom: 30rpx;
  440. }
  441. .norecord {
  442. font-weight: 500;
  443. color: #818181;
  444. font-size: 14px;
  445. text-align: center;
  446. line-height: 80vh;
  447. }
  448. .norecord2 {
  449. font-weight: 500;
  450. color: #818181;
  451. font-size: 14px;
  452. text-align: center;
  453. line-height: 36px;
  454. }
  455. .year {
  456. width: 100%;
  457. margin-left: 20rpx;
  458. text-align: left;
  459. font-weight: 550;
  460. color: #818181;
  461. font-size: 16px;
  462. }
  463. .list {
  464. width: 100%;
  465. padding-bottom: 10rpx;
  466. flex-wrap: wrap;
  467. justify-content: flex-start;
  468. }
  469. .item {
  470. width: 31.85%;
  471. margin: 20rpx 5rpx;
  472. }
  473. .item-bg {
  474. background: #e7ecef;
  475. border-radius: 5px;
  476. }
  477. .item-cup {
  478. width: 28vw;
  479. height: 28vw;
  480. /* background: #e7ecef; */
  481. border-radius: 5px;
  482. background-image: url("/static/cup/1/004.png");
  483. background-position-x: center;
  484. /* background-position-y: center; */
  485. background-repeat: no-repeat;
  486. background-size: 100% auto;
  487. /* background-clip: padding-box; */
  488. mask-image: url('/static/backgroud/mask.png');
  489. mask-size: 100%;
  490. mask-repeat: no-repeat;
  491. mask-clip: padding-box;
  492. }
  493. .item-cup-gray {
  494. width: 100%;
  495. /* height: 60%; */
  496. background-image: url("/static/cup/1/004h.png");
  497. background-position-x: center;
  498. background-repeat: no-repeat;
  499. background-size: 100% auto;
  500. overflow: hidden;
  501. /* filter: grayscale(1); */
  502. }
  503. .item-medal {
  504. width: 20vw;
  505. height: 20vw;
  506. margin-top: 25rpx;
  507. background-position-x: center;
  508. /* background-position-y: center; */
  509. background-repeat: no-repeat;
  510. background-size: auto 100%;
  511. }
  512. .item-title {
  513. width: 100%;
  514. margin-top: 10rpx;
  515. justify-content: center;
  516. }
  517. .item-title-month {
  518. color: #333333;
  519. font-size: 14px;
  520. font-weight: 550;
  521. }
  522. .item-title-divide {
  523. width: 4px;
  524. height: 14px;
  525. margin: 0 12rpx;
  526. background: #c6c6c6;
  527. border-radius: 2px;
  528. }
  529. .item-title-progress {
  530. color: #818181;
  531. font-size: 13px;
  532. font-weight: 500;
  533. }
  534. .item-title-ainame {
  535. margin-top: 12rpx;
  536. font-weight: 500;
  537. color: #333333;
  538. font-size: 12px;
  539. }
  540. .item-title-aitime {
  541. margin-top: 12rpx;
  542. margin-bottom: 20rpx;
  543. color: #818181;
  544. font-size: 11px;
  545. }
  546. .item-convertible {
  547. background: url("/static/medal/convertible.png") #e7ecef no-repeat;
  548. background-size: 30%;
  549. border-radius: 5px;
  550. }
  551. .item-converted {
  552. background: url("/static/medal/converted.png") #e7ecef no-repeat;
  553. background-size: 30%;
  554. border-radius: 5px;
  555. }
  556. </style>