index2.vue 15 KB

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