index2.vue 17 KB

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