index.vue 15 KB

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