list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div class="bg101010">
  3. <div v-for="item in list" :key="item.id" class="m15">
  4. <div style="display: flex;align-items: center;">
  5. <div class="wh60">
  6. <img class="wh56" :src="iconURL(item.giftBagFileKey)" alt="" />
  7. </div>
  8. <div class="ml12">
  9. <div class="txt1">{{ item.giftBagName.length > 8 ? item.giftBagName.slice(0, 8) + '...' : item.giftBagName }}</div>
  10. <div class="txt2">{{ item.giftBagDetailed }}</div>
  11. </div>
  12. </div>
  13. <div :class="item.availableStatus === 1 ? 'gift-btn disabled' : 'gift-btn'" @click="receive(item)">{{ ['领取', '已领完', '查看'][item.availableStatus] }}</div>
  14. </div>
  15. <img class="w80h67" src="~/assets/image/activity/welfare-community/return.png" alt="" @click="returnUp">
  16. <van-popup v-model="showVideoSuccess" position="top" style="background: transparent;color: #999;" :close-on-click-overlay="false">
  17. <div class="w290h215 dialog-view">
  18. <div class="txt3">恭喜您获得礼包</div>
  19. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showVideoSuccess = false" />
  20. <div class="txt4">请在游戏中兑换<br />激活码为:{{ gameActivationCode }}。<span class="c3B86FF" @click="copyCode()">复制</span></div>
  21. <div class="buy-btn" @click="order('showVideoSuccess')">购买云机</div>
  22. </div>
  23. </van-popup>
  24. <van-popup v-model="showAd" position="top" style="background: transparent;color: #999;" :close-on-click-overlay="false" @close="closeShowAd">
  25. <div v-for="(item, index) in adlist" :key="item.id" class="m114">
  26. <div v-if="index === 0" class="fwc">
  27. <div v-if="time" class="countdown">{{ time }}s后关闭广告</div>
  28. <video ref="videoPlayer" class="w290h330" :src="item.adVideoBase.videoUrl" x5-video-orientation="landscape" x5-video-player-type="h5" :x5-video-player-fullscreen="false" :controls="false" :webkit-playsinline="true" :playsinline="true" :autoplay="true" play-btn-position="center" :show-fullscreen-btn="false" :muted="true" @ended="ended" />
  29. <van-icon name="close" color="#999999" size="34" style="margin:15px auto 0;" @click="closeAd" />
  30. </div>
  31. </div>
  32. </van-popup>
  33. <van-popup v-model="showBuy" style="background: transparent;color: #999;" position="top" :close-on-click-overlay="false">
  34. <div class="w290h276 dialog-view">
  35. <div class="txt3">平台内下1单,立得惊喜礼包</div>
  36. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showBuy = false" />
  37. <img class="w100h107" src="~/assets/image/activity/welfare-community/gift.png" alt="">
  38. <div class="buy-btn" style="margin:15px auto 0;" @click="order('showBuy')">下单得惊喜礼包</div>
  39. </div>
  40. </van-popup>
  41. <van-popup v-model="showBuySuccess" style="background: transparent;color: #999;" position="top" :close-on-click-overlay="false">
  42. <div class="w290h233 dialog-view">
  43. <div class="txt3">恭喜您获得礼包</div>
  44. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showBuySuccess = false" />
  45. <div class="txt4">请在游戏中兑换<br />激活码为:{{ gameActivationCode }}。<span class="c3B86FF" @click="copyCode()">复制</span></div>
  46. <div class="fsc mt20">
  47. <div class="fcc">
  48. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_iphone@2x.png" alt="" />
  49. <span class="txt5">进入云机</span>
  50. </div>
  51. <img class="w12h10 ml10 mt15" src="~/assets/image/activity/welfare-community/arrow@2x.png" alt="">
  52. <div class="fcc">
  53. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_yingyongshichang@2x.png" alt="">
  54. <span class="txt5">打开应用市场</span>
  55. </div>
  56. <img class="w12h10 mt15" src="~/assets/image/activity/welfare-community/arrow@2x.png" alt="">
  57. <div class="fcc">
  58. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_xiazai@2x.png" alt="">
  59. <span class="txt5">下载{{ gameName }}游戏</span>
  60. </div>
  61. </div>
  62. </div>
  63. </van-popup>
  64. <van-popup v-model="showLogin" style="background: transparent;color: #999;" position="top" :close-on-click-overlay="false" @click-close-icon="returnUp">
  65. <div class="w580h582">
  66. <img class="w412h238" src="~/assets/image/activity/welfare-community/tip.png" />
  67. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="returnUp" />
  68. <div class="txt6">领取礼包,请先绑定手机号</div>
  69. <img class="buy-btn-2" src="~/assets/image/activity/welfare-community/btn.png" @click="login" />
  70. </div>
  71. </van-popup>
  72. </div>
  73. </template>
  74. <script>
  75. import { Toast } from 'vant';
  76. import { fileKeyToUrl } from '@/plugins/file-center.js';
  77. export default {
  78. auth: false,
  79. data() {
  80. return {
  81. showVideoSuccess: false,
  82. showAd: false,
  83. showBuy: false,
  84. showBuySuccess: false,
  85. showLogin: false,
  86. list: [],
  87. id: '',
  88. token: '',
  89. giftBagId: '',
  90. gameActivationCode: '',
  91. adlist: [],
  92. time: 30,
  93. timer: null
  94. }
  95. },
  96. head: {
  97. title: '福利社区',
  98. },
  99. computed: {
  100. iconURL() {
  101. return (key) => {
  102. return fileKeyToUrl(key)
  103. }
  104. }
  105. },
  106. created() {
  107. this.token = this.$route.query.token;
  108. this.id = this.$route.query.id;
  109. this.user = this.$route.query.user;
  110. this.gameName = this.$route.query.gameName;
  111. this.getAppGameGiftActivityDetailsList();
  112. },
  113. mounted() {
  114. document.addEventListener('visibilitychange', this.handleVisiable)
  115. },
  116. destroyed() {
  117. document.removeEventListener('visibilitychange', this.handleVisiable)
  118. },
  119. methods: {
  120. handleVisiable(e) {
  121. if (e.target.visibilityState === 'visible') {
  122. this.getAppGameGiftActivityDetailsList();
  123. }
  124. },
  125. closeShowAd() {
  126. this.showAd = false;
  127. clearInterval(this.timer);
  128. },
  129. closeAd() {
  130. this.showAd = false;
  131. clearInterval(this.timer);
  132. if (this.time === 0) {
  133. this.videoSuccess()
  134. }
  135. },
  136. async copyCode() {
  137. await this.$native.clipboard.writeText(this.gameActivationCode);
  138. this.$toast.success('复制成功');
  139. },
  140. order(key) {
  141. if (key === 'showBuy') {
  142. this.showBuy = false
  143. }
  144. if (key === 'showVideoSuccess') {
  145. this.showVideoSuccess = false
  146. }
  147. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  148. window.webkit.messageHandlers.order.postMessage({});
  149. }
  150. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  151. window.native.startPurchase();
  152. }
  153. },
  154. login() {
  155. this.showLogin = false
  156. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  157. window.webkit.messageHandlers.showLogin.postMessage({});
  158. }
  159. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  160. window.native.startBindPhone();
  161. }
  162. },
  163. ended() {
  164. this.showAd = false;
  165. clearInterval(this.timer);
  166. this.videoSuccess();
  167. },
  168. returnUp() {
  169. this.$router.push({ path: '/welfare-community', query: { token: this.$route.query.token, user: this.user } })
  170. },
  171. async receive(item) {
  172. if (item.availableStatus === 2) {
  173. this.gameActivationCode = item.gameActivationCode
  174. if (item.buy === 1) {
  175. this.showBuySuccess = true;
  176. }
  177. if (item.buy === 0) {
  178. this.showVideoSuccess = true;
  179. }
  180. return
  181. }
  182. if (item.availableStatus === 1) {
  183. return
  184. }
  185. this.giftBagId = item.id;
  186. if (this.$route.query.user === '2') {
  187. if (item.taskType === 2) {
  188. this.buySuccess(item);
  189. }
  190. if (item.taskType === 1) {
  191. const res = await this.$axios.$post('/public/v5/advertising/getAdInfoByAdPlace', { id: 1, adPlace: 24, os: this.$userAgent.isAndroid ? 1 : 2 }, { headers: { Authorization: this.token } });
  192. this.adlist = res.data
  193. if (!this.adlist.length) {
  194. return
  195. }
  196. this.adlist = this.adlist.length > 1 ? this.randomSort(this.adlist) : this.adlist;
  197. this.showAd = true
  198. setTimeout(() => {
  199. this.time = this.$refs.videoPlayer[0].duration > 30 ? 30 : parseInt(this.$refs.videoPlayer[0].duration);
  200. this.timer = setInterval(
  201. () => --this.time <= 0 && clearInterval(this.timer),
  202. 1000);
  203. }, 800)
  204. }
  205. } else {
  206. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  207. this.showLogin = true
  208. }
  209. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  210. window.webkit.messageHandlers.showLogin.postMessage({});
  211. }
  212. }
  213. },
  214. randomSort(array) {
  215. const length = array.length;
  216. if (!Array.isArray(array) || length <= 1) return;
  217. for (let index = 0; index < length - 1; index++) {
  218. const randomIndex = Math.floor(Math.random() * (length - index)) + index;
  219. [array[index], array[randomIndex]] = [array[randomIndex], array[index]];
  220. }
  221. return array;
  222. },
  223. async getAppGameGiftActivityDetailsList() {
  224. try {
  225. const res = await this.$axios.$get('/activity/game/giftActivity/getAppGameGiftActivityDetailsList?giftActivityId=' + this.id, { headers: { Authorization: this.token } });
  226. this.list = res.data;
  227. } catch (err) {
  228. Toast({
  229. message: err.message,
  230. duration: 3000
  231. });
  232. }
  233. },
  234. async buySuccess(item) {
  235. try {
  236. const res = await this.$axios.$get('/activity/game/giftActivity/receiveGameGift?giftBagId=' + item.id, { headers: { Authorization: this.token } });
  237. this.gameActivationCode = res.data.gameActivationCode;
  238. if (res.data.buy === 1) {
  239. this.showBuySuccess = true;
  240. }
  241. if (res.data.buy === 0) {
  242. this.showVideoSuccess = true;
  243. }
  244. } catch (err) {
  245. if (err.response.data.status === 8500) {
  246. this.showBuy = true;
  247. } else {
  248. Toast({
  249. message: err.message,
  250. duration: 3000
  251. });
  252. }
  253. }
  254. },
  255. async videoSuccess() {
  256. try {
  257. const res = await this.$axios.$get('/activity/game/giftActivity/receiveGameGift?giftBagId=' + this.giftBagId, { headers: { Authorization: this.token } });
  258. this.gameActivationCode = res.data.gameActivationCode;
  259. this.getAppGameGiftActivityDetailsList();
  260. if (res.data.buy === 1) {
  261. this.showBuySuccess = true;
  262. }
  263. if (res.data.buy === 0) {
  264. this.showVideoSuccess = true;
  265. }
  266. } catch (err) {
  267. Toast({
  268. message: err.message,
  269. duration: 3000
  270. });
  271. }
  272. }
  273. }
  274. }
  275. </script>
  276. <style scoped>
  277. .w80h67 {
  278. width: 80px;
  279. height: 67px;
  280. position: fixed;
  281. left: 0;
  282. bottom: 70px;
  283. }
  284. .buy-btn-2 {
  285. width: 207px;
  286. height: 40px;
  287. display: block;
  288. margin: 27px auto 0;
  289. }
  290. .w580h582 {
  291. width: 290px;
  292. height: 291px;
  293. background-color: #ffffff;
  294. border-radius: 8px;
  295. overflow: hidden;
  296. margin: 0 auto;
  297. position: relative;
  298. }
  299. .w412h238 {
  300. width: 206px;
  301. height: 119px;
  302. display: block;
  303. margin: 40px auto 17px;
  304. }
  305. .disabled {
  306. background: #2b3c5c !important;
  307. color: #999999 !important;
  308. }
  309. .txt6 {
  310. height: 22px;
  311. font-size: 16px;
  312. font-weight: 500;
  313. color: #363636;
  314. line-height: 22px;
  315. text-align: center;
  316. }
  317. .wh40 {
  318. width: 40px;
  319. height: 40px;
  320. }
  321. .mt20 {
  322. margin-top: 20px;
  323. }
  324. .fsc {
  325. display: flex;
  326. align-items: flex-start;
  327. justify-content: center;
  328. }
  329. .ml10 {
  330. margin-left: 10px;
  331. }
  332. .w12h10 {
  333. width: 12px;
  334. height: 10px;
  335. }
  336. .txt5 {
  337. font-size: 12px;
  338. color: #666666;
  339. margin-top: 3px;
  340. }
  341. .fcc {
  342. display: flex;
  343. flex-direction: column;
  344. justify-content: center;
  345. align-items: center;
  346. }
  347. .w100h107 {
  348. width: 100px;
  349. height: 107px;
  350. display: block;
  351. margin: 17px auto 0;
  352. }
  353. .w290h233 {
  354. width: 290px;
  355. height: 233px;
  356. margin: 0 auto;
  357. }
  358. .w290h276 {
  359. width: 290px;
  360. height: 276px;
  361. margin: 0 auto;
  362. }
  363. .dialog-view {
  364. background: linear-gradient(360deg, #ffffff 0%, #dfefff 100%);
  365. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.5);
  366. border-radius: 8px;
  367. position: relative;
  368. overflow: hidden;
  369. }
  370. .countdown {
  371. width: 92px;
  372. height: 25px;
  373. background: rgba(6, 6, 6, 0.5);
  374. border-radius: 13px;
  375. position: absolute;
  376. top: 10px;
  377. right: 10px;
  378. font-size: 11px;
  379. text-align: center;
  380. line-height: 25px;
  381. color: #cccccc;
  382. }
  383. .mt15 {
  384. margin-top: 15px;
  385. }
  386. .fwc {
  387. display: flex;
  388. flex-direction: column;
  389. justify-content: center;
  390. position: relative;
  391. }
  392. .w290h330 {
  393. width: 290px;
  394. height: 330px;
  395. background: #000000;
  396. }
  397. .buy-btn {
  398. width: 207px;
  399. height: 40px;
  400. background: linear-gradient(90deg, #38aefc 0%, #3b7fff 100%);
  401. border-radius: 20px;
  402. line-height: 40px;
  403. text-align: center;
  404. font-weight: 500;
  405. color: #ffffff;
  406. font-size: 16px;
  407. margin: 20px auto 0;
  408. }
  409. .c3B86FF {
  410. color: #3b86ff;
  411. }
  412. .txt4 {
  413. width: 290px;
  414. font-size: 14px;
  415. color: #666666;
  416. line-height: 20px;
  417. margin-top: 12px;
  418. text-align: center;
  419. }
  420. .txt3 {
  421. width: 290px;
  422. font-size: 18px;
  423. font-weight: 500;
  424. color: #363636;
  425. line-height: 25px;
  426. text-align: center;
  427. margin-top: 47px;
  428. }
  429. .w290h215 {
  430. width: 290px;
  431. height: 215px;
  432. margin: 0 auto;
  433. position: relative;
  434. }
  435. .m114 {
  436. margin: 0 auto;
  437. width: 290px;
  438. }
  439. .icon-close {
  440. position: absolute;
  441. top: 20px;
  442. right: 20px;
  443. }
  444. .gift-btn {
  445. width: 78px;
  446. height: 28px;
  447. background: #3b7fff;
  448. border-radius: 4px;
  449. font-size: 14px;
  450. color: #ffffff;
  451. line-height: 28px;
  452. text-align: center;
  453. justify-self: end;
  454. }
  455. .ml12 {
  456. margin-left: 12px;
  457. }
  458. .txt2 {
  459. font-size: 14px;
  460. color: #cfd1d4;
  461. line-height: 20px;
  462. margin-top: 5px;
  463. }
  464. .txt1 {
  465. font-size: 18px;
  466. font-weight: 500;
  467. color: #cfd1d4;
  468. line-height: 25px;
  469. }
  470. .wh60 {
  471. width: 60px;
  472. height: 60px;
  473. border: 1px solid #eaeaea;
  474. border-radius: 50%;
  475. padding: 2px;
  476. box-sizing: border-box;
  477. }
  478. .wh56 {
  479. width: 56px;
  480. height: 56px;
  481. border-radius: 50%;
  482. }
  483. .bg101010 {
  484. background: #101010;
  485. min-height: 100vh;
  486. overflow: hidden;
  487. }
  488. .m15 {
  489. margin: 15px;
  490. height: 83px;
  491. background: #1e2022;
  492. box-shadow: 0px 3px 7px 0px #1e2022;
  493. border-radius: 8px;
  494. display: flex;
  495. align-items: center;
  496. justify-content: space-between;
  497. padding: 12px 15px 12px;
  498. box-sizing: border-box;
  499. }
  500. </style>