index2.vue 18 KB

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