index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <template>
  2. <view class="activity" style="background-image: none; background-color: #f89c33; padding: 0 0 120rpx">
  3. <!-- <view class="rule" @click="showRule">活动规则</view> -->
  4. <!-- logo与跑马灯 -->
  5. <view class="header">
  6. <img :src="acticve_detail.logo" class="logo" mode="widthFix" />
  7. <view class="barrage-box">
  8. <view class="text">{{ lottery_list }}</view>
  9. </view>
  10. </view>
  11. <!-- 立即参与页面 -->
  12. <view class="page-1" v-if="pageIndex == 1" style="padding: 0 16rpx">
  13. <view class="activity-info">
  14. <!-- <text class="title">{{ acticve_detail?.name }}</text> -->
  15. <view class="active-rule">
  16. <rich-text :nodes="acticve_detail.active_rule" class="rich_text"></rich-text>
  17. </view>
  18. </view>
  19. <view class="activity-btn" @click="_handleChangePage(1)">立即参与</view>
  20. </view>
  21. <!-- 答题页面 -->
  22. <view class="page-2" v-if="pageIndex == 2">
  23. <!-- 题干区域 -->
  24. <view class="question">
  25. <text style="font-weight: bold">{{ question.title }}</text>
  26. <br />
  27. <view style="margin-top: 20rpx">(请从下面选择正确答案提交)</view>
  28. </view>
  29. <!-- 选项区域 -->
  30. <view class="options">
  31. <view :class="['option', { active: answer_id == item.id }]" v-for="item in question.answer_list" :key="item.id" @click="_handleSelectAnswer(item.id)">{{ item.value }}</view>
  32. </view>
  33. <!-- 提交答案 -->
  34. <button :class="['submit-btn', { disabled: !answer_id }]" @click="_handleSubmitAnswer">提交</button>
  35. <!-- 活动规则 -->
  36. <view class="rule-btn" @click="_handleChangeRule('show')">活动规则</view>
  37. <uni-popup ref="lotteryRule" type="center">
  38. <view class="lottery_rule_box">
  39. <view class="lottery_rule_title">
  40. <text>活动规则</text>
  41. <view class="close_btn" @click="_handleChangeRule('close')"> X </view>
  42. </view>
  43. <scroll-view class="lottery_rule_info" scroll-y="true">
  44. <rich-text :nodes="acticve_detail.active_rule" class="rich_text"></rich-text>
  45. </scroll-view>
  46. </view>
  47. </uni-popup>
  48. </view>
  49. <!-- 结果页面 -->
  50. <view class="page-3" v-if="pageIndex == 3">
  51. <view class="no-join-number" v-if="acticve_detail.join_last <= 0 && acticve_detail.share_last == 0 && isFromIndex">
  52. <view class="header">
  53. <text>您的答题次数已用完!</text>
  54. <text>谢谢参与</text>
  55. </view>
  56. <view class="tip">
  57. <text>1.余额请前往小程序余额页面申请提现</text>
  58. <text>2.实物奖励请填写收获地址或者等待客服进行充值</text>
  59. </view>
  60. </view>
  61. <view style="width: 100%" v-else-if="acticve_detail.join_last <= 0 && acticve_detail.share_last !== 0 && isFromIndex">
  62. <view class="result-fail result-content">
  63. <view class="result-text" style="color: #fff">您的答题次数已用完!</view>
  64. <button open-type="share" class="result-btn">分享好友再来一次</button>
  65. </view>
  66. </view>
  67. <view v-else style="width: 100%">
  68. <!-- 结果展示 -->
  69. <view class="result-success result-content" v-if="is_answer">
  70. <view class="result-text" style="color: #fff">恭喜您,答对啦!</view>
  71. <view class="result-btn-list">
  72. <view class="result-btn" @click="_goLottery">立即抽奖</view>
  73. <button open-type="share" class="result-btn">分享好友再来一次</button>
  74. </view>
  75. </view>
  76. <view class="result-fail result-content" v-if="!is_answer">
  77. <view class="result-text" style="color: #fff">很遗憾,您答错了!</view>
  78. <button open-type="share" class="result-btn">分享好友再来一次</button>
  79. </view>
  80. </view>
  81. </view>
  82. <!-- 抽奖入口 -->
  83. <view class="lottery-entrance" v-if="showLottery && pageIndex !== 1">
  84. <!-- <view class="close-btn" @click="_handleCloseLottery">x</view> -->
  85. <image @click="_goLottery" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174439.gif" alt="" />
  86. </view>
  87. </view>
  88. </template>
  89. <script setup>
  90. import { ref, getCurrentInstance } from 'vue';
  91. import { onShareAppMessage, onLoad, onShow } from '@dcloudio/uni-app';
  92. import http from '@/utils/request';
  93. const { appContext } = getCurrentInstance();
  94. const $checkAccess = appContext.config.globalProperties.$checkAccess;
  95. const pageIndex = ref(1);
  96. const question = ref({
  97. title: '',
  98. answer_list: [],
  99. });
  100. const showLottery = ref(true);
  101. const acticve_detail = ref({});
  102. const detialId = ref(null);
  103. const answer_id = ref(null);
  104. const is_answer = ref(false);
  105. const lottery_list = ref('还没有人中奖,快来参与吧!');
  106. const isFromIndex = ref(false);
  107. const lotteryRule = ref();
  108. const shareObj = ref(null);
  109. onLoad((options) => {
  110. //未登陆提醒用户登陆
  111. if (!$checkAccess.checkLogin()) {
  112. uni.showModal({
  113. title: '温馨提示',
  114. content: '请先登录',
  115. confirmText: '去登录',
  116. cancelText: '取消',
  117. success: (res) => {
  118. if (res.confirm) {
  119. uni.redirectTo({
  120. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${options.id}`,
  121. });
  122. }
  123. },
  124. });
  125. return;
  126. }
  127. if (options.id) {
  128. _getDeatail(detialId.value);
  129. detialId.value = options.id;
  130. }
  131. // #ifdef MP-WEIXIN
  132. //分享按钮
  133. uni.showShareMenu({
  134. withShareTicket: true,
  135. menus: ['shareAppMessage', 'shareTimeline'],
  136. });
  137. // #endif
  138. });
  139. onShow(() => {
  140. console.log('回到小程序');
  141. if (detialId.value) {
  142. _getDeatail(detialId.value);
  143. }
  144. if ($checkAccess.checkLogin()) {
  145. http.request('api/custom/get_info').then((callback) => {
  146. if (callback.code == 'success') {
  147. // 存储登录标识
  148. uni.setStorageSync('userInfo', callback.data);
  149. }
  150. });
  151. }
  152. });
  153. // 定义页面的分享逻辑
  154. onShareAppMessage((res) => {
  155. if (res) {
  156. _addShare();
  157. }
  158. return {
  159. title: acticve_detail.value.name, //"999智控终端平台\n正月十五猜灯谜",
  160. path: `/pages/activity/index?id=${detialId.value}`,
  161. imageUrl: acticve_detail.value.logo,
  162. promise: new Promise((resolve, reject) => {
  163. http.request('api/share_message/get_item', { item_id: detialId.value, pages: '/pages/activity/index' }).then((callback) => {
  164. console.log(callback, 'api/share_message/get_item');
  165. resolve({
  166. title: callback.data?.title == '' ? acticve_detail.value.name : callback.data.title,
  167. path: `/pages/activity/index?id=${detialId.value}`,
  168. imageUrl: callback.data?.image_url == '' ? acticve_detail.value.logo : callback.data.image_url,
  169. });
  170. });
  171. }),
  172. };
  173. });
  174. const _handleCloseLottery = () => {
  175. showLottery.value = false;
  176. };
  177. const _getDeatail = (id) => {
  178. if (!id) return;
  179. http.request('api/riddle_active/get_detail', { id }).then((response) => {
  180. console.log(response);
  181. if (response.code == 'success') {
  182. uni.setNavigationBarTitle({
  183. title: response.data.name,
  184. });
  185. acticve_detail.value = response.data;
  186. if (response.data.join_last > 0) {
  187. _getQuestion();
  188. pageIndex.value = 1;
  189. }
  190. http.request('api/lottery_riddle_record/get_list_all', { lottery_id: response.data.lottery_id }).then((res) => {
  191. if (res.code == 'success') {
  192. if (res.data?.length > 0) {
  193. let str = '';
  194. res.data.forEach((item) => {
  195. str += `用户${item.username}已获得${item.reward_name};`;
  196. });
  197. lottery_list.value = str;
  198. }
  199. }
  200. });
  201. } else {
  202. console.log(response);
  203. uni.showToast({
  204. title: response.msg,
  205. icon: 'none',
  206. });
  207. }
  208. });
  209. };
  210. const _getQuestion = () => {
  211. http.request('api/riddle_question/get_question').then((response) => {
  212. if (response.code == 'success') {
  213. question.value = response.data;
  214. }
  215. });
  216. };
  217. const _handleSelectAnswer = (id) => {
  218. answer_id.value = id;
  219. };
  220. const _handleSubmitAnswer = () => {
  221. if (!answer_id.value) return;
  222. const _param = {
  223. active_id: detialId.value,
  224. question_id: question.value.id,
  225. answer_id: answer_id.value,
  226. };
  227. http.request('api/riddle_answer/check_answer', _param).then((response) => {
  228. if (response.code == 'success') {
  229. pageIndex.value = 3;
  230. // _getDeatail(detialId.value);
  231. is_answer.value = response.data.is_answer;
  232. } else {
  233. uni.showToast({
  234. title: response.msg,
  235. icon: 'none',
  236. });
  237. }
  238. });
  239. };
  240. const _addShare = () => {
  241. http.request('api/riddle_active_share/add', { active_id: detialId.value }).then((response) => {});
  242. };
  243. const _goLottery = () => {
  244. if (!$checkAccess.checkLogin()) {
  245. uni.showModal({
  246. title: '温馨提示',
  247. content: '请先登录',
  248. confirmText: '去登录',
  249. cancelText: '取消',
  250. success: (res) => {
  251. if (res.confirm) {
  252. uni.redirectTo({
  253. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${detialId.value}`,
  254. });
  255. }
  256. },
  257. });
  258. return;
  259. }
  260. uni.navigateTo({
  261. url: `/pages/activity/lottery?id=${acticve_detail.value.lottery_id}&activity_id=${detialId.value}`,
  262. });
  263. setTimeout(() => {
  264. pageIndex.value = 1;
  265. }, 1000);
  266. };
  267. const _handleChangePage = (index) => {
  268. if (index == 1 && acticve_detail.value.join_last > 0) {
  269. pageIndex.value = 2;
  270. answer_id.value = null;
  271. } else {
  272. pageIndex.value = 3;
  273. if (acticve_detail.value.join_last == 0 || acticve_detail.value.share_last == 0) {
  274. isFromIndex.value = true;
  275. }
  276. }
  277. };
  278. const _handleChangeRule = (type) => {
  279. if (type == 'show') lotteryRule.value.open('center');
  280. else lotteryRule.value.close();
  281. };
  282. </script>
  283. <style lang="less" scoped>
  284. .activity {
  285. padding: 0 16rpx 120rpx;
  286. box-sizing: border-box;
  287. position: relative;
  288. width: 100vw;
  289. min-height: 100vh;
  290. .header {
  291. .logo {
  292. width: 100%;
  293. }
  294. .barrage-box {
  295. padding: 10rpx;
  296. width: 100%;
  297. transform-origin: 65vw 75vw;
  298. transform: rotate(0deg);
  299. white-space: nowrap;
  300. display: flex;
  301. justify-content: center;
  302. align-items: center;
  303. z-index: 3;
  304. box-sizing: border-box;
  305. background-color: #fff;
  306. opacity: 0.8;
  307. overflow-x: hidden;
  308. }
  309. .text {
  310. width: 200vw; //调整文字显示
  311. font-size: 16px;
  312. color: #333;
  313. animation: aniMove 8s linear infinite;
  314. animation-fill-mode: forwards;
  315. }
  316. /* 文字滚动 */
  317. @keyframes aniMove {
  318. 0% {
  319. transform: translateX(100%);
  320. }
  321. 100% {
  322. transform: translateX(-100%);
  323. }
  324. }
  325. }
  326. .page-1 {
  327. width: 100%;
  328. display: flex;
  329. align-items: center;
  330. flex-direction: column;
  331. justify-content: center;
  332. box-sizing: border-box;
  333. .activity-info {
  334. padding-top: 80rpx;
  335. display: flex;
  336. flex-direction: column;
  337. align-items: center;
  338. justify-content: center;
  339. width: 100%;
  340. .title {
  341. font-size: 46rpx;
  342. font-weight: bold;
  343. color: #fff;
  344. text-align: center;
  345. margin-bottom: 40rpx;
  346. }
  347. .active-rule {
  348. display: block;
  349. width: 100%;
  350. font-size: 30rpx;
  351. line-height: 40rpx;
  352. border-radius: 10rpx;
  353. padding: 26rpx;
  354. box-sizing: border-box;
  355. margin-bottom: 40rpx;
  356. background-color: #ffffff;
  357. opacity: 0.8;
  358. height: 400rpx;
  359. overflow-y: auto;
  360. .rich_text {
  361. font-size: 28rpx;
  362. font-weight: bold;
  363. white-space: break-spaces;
  364. }
  365. }
  366. }
  367. .activity-btn {
  368. width: 90%;
  369. background-color: #ff8000;
  370. color: #fff;
  371. border-radius: 60rpx;
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. padding: 16rpx;
  376. }
  377. }
  378. .page-2 {
  379. display: flex;
  380. flex-direction: column;
  381. z-index: 10;
  382. width: 100%;
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. justify-content: center;
  387. box-sizing: border-box;
  388. padding: 80rpx 16rpx 0;
  389. .question {
  390. // 题干的样式
  391. width: 100%;
  392. opacity: 0.8;
  393. height: 300rpx;
  394. padding: 26rpx;
  395. overflow: auto;
  396. font-size: 28rpx;
  397. border-radius: 6rpx;
  398. margin-bottom: 30rpx;
  399. background-color: #fff;
  400. box-sizing: border-box;
  401. }
  402. .options {
  403. // 选项的样式
  404. display: flex;
  405. gap: 20rpx;
  406. flex-direction: column;
  407. width: 100%;
  408. > .option {
  409. height: 80rpx;
  410. line-height: 80rpx;
  411. padding-left: 26rpx;
  412. border-radius: 6rpx;
  413. background-color: #fff;
  414. margin-bottom: 10rpx;
  415. opacity: 0.95;
  416. width: 100%;
  417. box-sizing: border-box;
  418. &.active {
  419. background-color: #ffd6a0;
  420. }
  421. }
  422. }
  423. .submit-btn {
  424. width: 100%;
  425. height: 80rpx;
  426. background-color: #ffd6a0;
  427. color: #7e4304;
  428. border-radius: 60rpx;
  429. display: flex;
  430. justify-content: center;
  431. align-items: center;
  432. padding: 16rpx;
  433. margin-top: 60rpx;
  434. &.disabled {
  435. background-color: #ccc;
  436. }
  437. }
  438. .rule-btn {
  439. position: absolute;
  440. right: 0;
  441. top: 8%;
  442. color: #7e4304;
  443. padding: 15rpx 10rpx 15rpx 35rpx;
  444. background-color: #ffd6a0;
  445. border-top-left-radius: 60rpx;
  446. border-bottom-left-radius: 60rpx;
  447. text-align: center;
  448. font-size: 28rpx;
  449. }
  450. .lottery_rule_box {
  451. width: 500rpx;
  452. display: block;
  453. overflow: hidden;
  454. background-color: #fc335f;
  455. font-size: 26rpx;
  456. margin: 0 auto;
  457. line-height: 50rpx;
  458. border-radius: 10rpx;
  459. padding: 20rpx 25rpx 20rpx;
  460. .lottery_rule_title {
  461. color: #ffffff;
  462. height: 60rpx;
  463. font-size: 32rpx;
  464. line-height: 60rpx;
  465. text-align: center;
  466. margin-bottom: 10rpx;
  467. .close_btn {
  468. float: right;
  469. width: 40rpx;
  470. height: 40rpx;
  471. font-size: 24rpx;
  472. margin-top: 9rpx;
  473. line-height: 40rpx;
  474. border-radius: 50%;
  475. border: 1rpx solid #ffffff;
  476. }
  477. }
  478. .lottery_rule_info {
  479. display: block;
  480. height: 500rpx;
  481. font-size: 24rpx;
  482. line-height: 40rpx;
  483. border-radius: 10rpx;
  484. padding: 20rpx;
  485. box-sizing: border-box;
  486. background-color: #ffffff;
  487. .rich_text {
  488. white-space: break-spaces;
  489. }
  490. }
  491. }
  492. }
  493. .page-3 {
  494. width: 100%;
  495. height: 100%;
  496. display: flex;
  497. flex-direction: column;
  498. align-items: center;
  499. justify-content: center;
  500. opacity: 0.95;
  501. box-sizing: border-box;
  502. padding: 0 16rpx;
  503. padding-top: 250rpx;
  504. .result-content {
  505. width: 100%;
  506. .result-text {
  507. font-size: 56rpx;
  508. font-weight: bold;
  509. color: #fff;
  510. text-align: center;
  511. margin-bottom: 100rpx;
  512. }
  513. .result-btn-list {
  514. display: flex;
  515. gap: 20rpx;
  516. }
  517. .result-btn {
  518. width: 100%;
  519. height: 80rpx;
  520. background-color: #ff8000;
  521. color: #fff;
  522. border-radius: 60rpx;
  523. display: flex;
  524. justify-content: center;
  525. align-items: center;
  526. padding: 16rpx;
  527. margin-top: 60rpx;
  528. box-sizing: border-box;
  529. font-size: 36rpx;
  530. }
  531. }
  532. .no-join-number {
  533. width: 100%;
  534. background-color: #fff;
  535. border-radius: 6rpx;
  536. padding: 26rpx;
  537. opacity: 0.95;
  538. margin-bottom: 60rpx;
  539. display: flex;
  540. flex-direction: column;
  541. box-sizing: border-box;
  542. gap: 40rpx;
  543. font-size: 36rpx;
  544. .header {
  545. display: flex;
  546. flex-direction: column;
  547. align-items: center;
  548. justify-content: center;
  549. gap: 20rpx;
  550. }
  551. .tip {
  552. font-size: 24rpx;
  553. display: flex;
  554. flex-direction: column;
  555. gap: 20rpx;
  556. }
  557. }
  558. }
  559. .lottery-entrance {
  560. position: absolute;
  561. z-index: 10;
  562. right: 5rpx;
  563. top: 240rpx;
  564. image {
  565. width: 160rpx;
  566. height: 160rpx;
  567. }
  568. .close-btn {
  569. width: 40rpx;
  570. height: 40rpx;
  571. font-size: 24rpx;
  572. line-height: 40rpx;
  573. border-radius: 50%;
  574. border: 1rpx solid #ddd;
  575. display: flex;
  576. align-items: center;
  577. justify-content: center;
  578. position: absolute;
  579. top: 5rpx;
  580. right: 0;
  581. color: #fff;
  582. }
  583. }
  584. }
  585. </style>