index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <view class="activity" style="background-image: none; background-color: #e03519; 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" style="font-size: 36rpx; font-weight: 300"></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. white-space: break-spaces;
  362. }
  363. }
  364. }
  365. .activity-btn {
  366. width: 90%;
  367. background-color: #ff8000;
  368. color: #fff;
  369. border-radius: 60rpx;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. padding: 16rpx;
  374. }
  375. }
  376. .page-2 {
  377. display: flex;
  378. flex-direction: column;
  379. z-index: 10;
  380. width: 100%;
  381. display: flex;
  382. flex-direction: column;
  383. align-items: center;
  384. justify-content: center;
  385. box-sizing: border-box;
  386. padding: 80rpx 16rpx 0;
  387. .question {
  388. // 题干的样式
  389. background-color: #fff;
  390. height: 300rpx;
  391. border-radius: 6rpx;
  392. padding: 26rpx;
  393. opacity: 0.8;
  394. margin-bottom: 30rpx;
  395. width: 100%;
  396. box-sizing: border-box;
  397. overflow: auto;
  398. }
  399. .options {
  400. // 选项的样式
  401. display: flex;
  402. gap: 20rpx;
  403. flex-direction: column;
  404. width: 100%;
  405. > .option {
  406. height: 80rpx;
  407. line-height: 80rpx;
  408. padding-left: 26rpx;
  409. border-radius: 6rpx;
  410. background-color: #fff;
  411. margin-bottom: 10rpx;
  412. opacity: 0.95;
  413. width: 100%;
  414. box-sizing: border-box;
  415. &.active {
  416. background-color: #ffd6a0;
  417. }
  418. }
  419. }
  420. .submit-btn {
  421. width: 100%;
  422. height: 80rpx;
  423. background-color: #ffd6a0;
  424. color: #7e4304;
  425. border-radius: 60rpx;
  426. display: flex;
  427. justify-content: center;
  428. align-items: center;
  429. padding: 16rpx;
  430. margin-top: 60rpx;
  431. &.disabled {
  432. background-color: #ccc;
  433. }
  434. }
  435. .rule-btn {
  436. position: absolute;
  437. right: 0;
  438. top: 8%;
  439. color: #7e4304;
  440. padding: 15rpx 10rpx 15rpx 35rpx;
  441. background-color: #ffd6a0;
  442. border-top-left-radius: 60rpx;
  443. border-bottom-left-radius: 60rpx;
  444. text-align: center;
  445. font-size: 28rpx;
  446. }
  447. .lottery_rule_box {
  448. width: 500rpx;
  449. display: block;
  450. overflow: hidden;
  451. background-color: #fc335f;
  452. font-size: 26rpx;
  453. margin: 0 auto;
  454. line-height: 50rpx;
  455. border-radius: 10rpx;
  456. padding: 20rpx 25rpx 20rpx;
  457. .lottery_rule_title {
  458. color: #ffffff;
  459. height: 60rpx;
  460. font-size: 32rpx;
  461. line-height: 60rpx;
  462. text-align: center;
  463. margin-bottom: 10rpx;
  464. .close_btn {
  465. float: right;
  466. width: 40rpx;
  467. height: 40rpx;
  468. font-size: 24rpx;
  469. margin-top: 9rpx;
  470. line-height: 40rpx;
  471. border-radius: 50%;
  472. border: 1rpx solid #ffffff;
  473. }
  474. }
  475. .lottery_rule_info {
  476. display: block;
  477. height: 500rpx;
  478. font-size: 24rpx;
  479. line-height: 40rpx;
  480. border-radius: 10rpx;
  481. padding: 20rpx;
  482. box-sizing: border-box;
  483. background-color: #ffffff;
  484. .rich_text {
  485. white-space: break-spaces;
  486. }
  487. }
  488. }
  489. }
  490. .page-3 {
  491. width: 100%;
  492. height: 100%;
  493. display: flex;
  494. flex-direction: column;
  495. align-items: center;
  496. justify-content: center;
  497. opacity: 0.95;
  498. box-sizing: border-box;
  499. padding: 0 16rpx;
  500. padding-top: 250rpx;
  501. .result-content {
  502. width: 100%;
  503. .result-text {
  504. font-size: 56rpx;
  505. font-weight: bold;
  506. color: #fff;
  507. text-align: center;
  508. margin-bottom: 100rpx;
  509. }
  510. .result-btn-list {
  511. display: flex;
  512. gap: 20rpx;
  513. }
  514. .result-btn {
  515. width: 100%;
  516. height: 80rpx;
  517. background-color: #ff8000;
  518. color: #fff;
  519. border-radius: 60rpx;
  520. display: flex;
  521. justify-content: center;
  522. align-items: center;
  523. padding: 16rpx;
  524. margin-top: 60rpx;
  525. box-sizing: border-box;
  526. font-size: 36rpx;
  527. }
  528. }
  529. .no-join-number {
  530. width: 100%;
  531. background-color: #fff;
  532. border-radius: 6rpx;
  533. padding: 26rpx;
  534. opacity: 0.95;
  535. margin-bottom: 60rpx;
  536. display: flex;
  537. flex-direction: column;
  538. box-sizing: border-box;
  539. gap: 40rpx;
  540. font-size: 36rpx;
  541. .header {
  542. display: flex;
  543. flex-direction: column;
  544. align-items: center;
  545. justify-content: center;
  546. gap: 20rpx;
  547. }
  548. .tip {
  549. font-size: 24rpx;
  550. display: flex;
  551. flex-direction: column;
  552. gap: 20rpx;
  553. }
  554. }
  555. }
  556. .lottery-entrance {
  557. position: absolute;
  558. z-index: 10;
  559. right: 5rpx;
  560. top: 240rpx;
  561. image {
  562. width: 160rpx;
  563. height: 160rpx;
  564. }
  565. .close-btn {
  566. width: 40rpx;
  567. height: 40rpx;
  568. font-size: 24rpx;
  569. line-height: 40rpx;
  570. border-radius: 50%;
  571. border: 1rpx solid #ddd;
  572. display: flex;
  573. align-items: center;
  574. justify-content: center;
  575. position: absolute;
  576. top: 5rpx;
  577. right: 0;
  578. color: #fff;
  579. }
  580. }
  581. }
  582. </style>