index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <view class="activity" catchtouchmove="true" :style="pageIndex == 1 ? 'background-image:none;background-color:#e03519' : ''">
  3. <!-- <view class="rule" @click="showRule">活动规则</view> -->
  4. <!-- logo与跑马灯 -->
  5. <view class="header">
  6. <img :src="acticve_detail.logo" class="logo" v-if="pageIndex == 1" />
  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">
  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">{{ question.title }}</view>
  25. <!-- 选项区域 -->
  26. <view class="options">
  27. <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>
  28. </view>
  29. <!-- 提交答案 -->
  30. <button :class="['submit-btn', { disabled: !answer_id }]" @click="_handleSubmitAnswer">提交</button>
  31. </view>
  32. <!-- 结果页面 -->
  33. <view class="page-3" v-if="pageIndex == 3">
  34. <view class="no-join-number" v-if="acticve_detail.join_last == 0 && acticve_detail.share_last == 0 && isFromIndex">
  35. <view class="header">
  36. <text>您的答题次数已用完!</text>
  37. <text>谢谢参与</text>
  38. </view>
  39. <view class="tip">
  40. <text>1.余额请前往小程序余额页面申请提现</text>
  41. <text>2.实物奖励请填写收获地址或者等待客服进行充值</text>
  42. </view>
  43. </view>
  44. <view v-else>
  45. <!-- 结果展示 -->
  46. <view class="result-success result-content" v-if="is_answer">
  47. <view class="result-text" style="color: #fff">恭喜您,答对啦!</view>
  48. <view class="result-btn" @click="_goLottery">立即抽奖</view>
  49. </view>
  50. <view class="result-fail result-content" v-if="!is_answer">
  51. <view class="result-text" style="color: #fff">很遗憾,您答错了!</view>
  52. <button open-type="share" class="result-btn">分享给好友再来一次</button>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 抽奖入口 -->
  57. <view class="lottery-entrance" v-if="showLottery">
  58. <view class="close-btn" @click="_handleCloseLottery">x</view>
  59. <image @click="_goLottery" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174439.gif" alt="" />
  60. </view>
  61. </view>
  62. </template>
  63. <script setup>
  64. import { ref, getCurrentInstance } from "vue";
  65. import { onShareAppMessage, onLoad, onShow } from "@dcloudio/uni-app";
  66. import http from "@/utils/request";
  67. const { appContext } = getCurrentInstance();
  68. const $checkAccess = appContext.config.globalProperties.$checkAccess;
  69. const pageIndex = ref(1);
  70. const question = ref({
  71. title: "",
  72. answer_list: [],
  73. });
  74. const showLottery = ref(true);
  75. const acticve_detail = ref({});
  76. const detialId = ref(null);
  77. const answer_id = ref(null);
  78. const is_answer = ref(false);
  79. const lottery_list = ref("还没有人中奖,快来参与吧!");
  80. const isFromIndex = ref(false);
  81. onLoad((options) => {
  82. //未登陆提醒用户登陆
  83. if (!$checkAccess.checkLogin()) {
  84. uni.showModal({
  85. title: "温馨提示",
  86. content: "请先登录",
  87. confirmText: "去登录",
  88. cancelText: "取消",
  89. success: (res) => {
  90. if (res.confirm) {
  91. uni.redirectTo({
  92. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${options.id}`,
  93. });
  94. }
  95. },
  96. });
  97. return;
  98. }
  99. if (options.id) {
  100. _getDeatail(detialId.value);
  101. detialId.value = options.id;
  102. }
  103. // #ifdef MP-WEIXIN
  104. //分享按钮
  105. uni.showShareMenu({
  106. withShareTicket: true,
  107. menus: ["shareAppMessage", "shareTimeline"],
  108. });
  109. // #endif
  110. });
  111. onShow(() => {
  112. console.log("回到小程序");
  113. if (detialId.value) {
  114. console.log(1111);
  115. _getDeatail(detialId.value);
  116. }
  117. });
  118. // 定义页面的分享逻辑
  119. onShareAppMessage((res) => {
  120. if (res) {
  121. _addShare();
  122. }
  123. return {
  124. title: "正月十五猜灯谜",
  125. path: `/pages/activity/index?id=${detialId.value}`,
  126. imageUrl: "https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174500.jpg",
  127. };
  128. });
  129. const _handleCloseLottery = () => {
  130. showLottery.value = false;
  131. };
  132. const _getDeatail = (id) => {
  133. http.request("api/riddle_active/get_detail", { id }).then((response) => {
  134. if (response.code == "success") {
  135. acticve_detail.value = response.data;
  136. if (response.data.join_last > 0) {
  137. _getQuestion();
  138. pageIndex.value = 2;
  139. }
  140. http.request("api/lottery_riddle_record/get_list_all", { lottery_id: response.data.lottery_id }).then((res) => {
  141. if (res.code == "success") {
  142. console.log(res);
  143. if (res.data?.length > 0) {
  144. let str = "";
  145. res.data.forEach((item) => {
  146. str += `用户${item.username}已获得${item.reward_name};`;
  147. });
  148. lottery_list.value = str;
  149. }
  150. }
  151. });
  152. }
  153. });
  154. };
  155. const _getQuestion = () => {
  156. http.request("api/riddle_question/get_question").then((response) => {
  157. if (response.code == "success") {
  158. question.value = response.data;
  159. }
  160. });
  161. };
  162. const _handleSelectAnswer = (id) => {
  163. answer_id.value = id;
  164. };
  165. const _handleSubmitAnswer = () => {
  166. if (!answer_id.value) return;
  167. const _param = {
  168. active_id: detialId.value,
  169. question_id: question.value.id,
  170. answer_id: answer_id.value,
  171. };
  172. http.request("api/riddle_answer/check_answer", _param).then((response) => {
  173. if (response.code == "success") {
  174. pageIndex.value = 3;
  175. _getDeatail(detialId.value);
  176. is_answer.value = response.data.is_answer;
  177. }
  178. });
  179. };
  180. const _addShare = () => {
  181. http.request("api/riddle_active_share/add", { active_id: detialId.value }).then((response) => {});
  182. };
  183. const _goLottery = () => {
  184. if (!$checkAccess.checkLogin()) {
  185. uni.showModal({
  186. title: "温馨提示",
  187. content: "请先登录",
  188. confirmText: "去登录",
  189. cancelText: "取消",
  190. success: (res) => {
  191. if (res.confirm) {
  192. uni.redirectTo({
  193. url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${detialId.value}`,
  194. });
  195. }
  196. },
  197. });
  198. return;
  199. }
  200. uni.navigateTo({
  201. url: `/pages/activity/lottery?id=${acticve_detail.value.lottery_id}`,
  202. });
  203. pageIndex.value = 1;
  204. };
  205. const _handleChangePage = (index) => {
  206. if (index == 1 && acticve_detail.value.join_last > 0) {
  207. pageIndex.value = 2;
  208. } else {
  209. pageIndex.value = 3;
  210. if (acticve_detail.value.join_last == 0 && acticve_detail.value.share_last == 0) {
  211. isFromIndex.value = true;
  212. }
  213. }
  214. };
  215. </script>
  216. <style lang="less" scoped>
  217. .activity {
  218. padding: 0 16rpx 120rpx;
  219. height: 100vh;
  220. box-sizing: border-box;
  221. overflow: hidden;
  222. position: relative;
  223. width: 100vw;
  224. background-image: url("https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174500.jpg");
  225. background-repeat: no-repeat;
  226. background-size: 100% 100%;
  227. .header {
  228. .logo {
  229. width: 100%;
  230. height: 300rpx;
  231. }
  232. .barrage-box {
  233. padding: 10rpx;
  234. width: 100%;
  235. transform-origin: 65vw 75vw;
  236. transform: rotate(0deg);
  237. white-space: nowrap;
  238. display: flex;
  239. justify-content: center;
  240. align-items: center;
  241. z-index: 3;
  242. box-sizing: border-box;
  243. background-color: #fff;
  244. opacity: 0.8;
  245. overflow-x: hidden;
  246. margin-top: 20rpx;
  247. }
  248. .text {
  249. width: 200vw; //调整文字显示
  250. font-size: 16px;
  251. color: #333;
  252. animation: aniMove 8s linear infinite;
  253. animation-fill-mode: forwards;
  254. }
  255. /* 文字滚动 */
  256. @keyframes aniMove {
  257. 0% {
  258. transform: translateX(100%);
  259. }
  260. 100% {
  261. transform: translateX(-100%);
  262. }
  263. }
  264. }
  265. .page-1 {
  266. width: 100%;
  267. display: flex;
  268. align-items: center;
  269. flex-direction: column;
  270. justify-content: center;
  271. .activity-info {
  272. padding-top: 100rpx;
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. justify-content: center;
  277. width: 100%;
  278. .title {
  279. font-size: 46rpx;
  280. font-weight: bold;
  281. color: #fff;
  282. text-align: center;
  283. margin-bottom: 40rpx;
  284. }
  285. .active-rule {
  286. display: block;
  287. height: 500rpx;
  288. width: 100%;
  289. font-size: 24rpx;
  290. line-height: 40rpx;
  291. border-radius: 10rpx;
  292. padding: 20rpx;
  293. box-sizing: border-box;
  294. margin-bottom: 40rpx;
  295. background-color: #ffffff;
  296. opacity: 0.8;
  297. .rich_text {
  298. white-space: break-spaces;
  299. }
  300. }
  301. }
  302. .activity-btn {
  303. width: 90%;
  304. background-color: #e7522f;
  305. color: #fff;
  306. border-radius: 60rpx;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. padding: 16rpx;
  311. }
  312. }
  313. .page-2 {
  314. height: 100%;
  315. display: flex;
  316. flex-direction: column;
  317. z-index: 10;
  318. width: 100%;
  319. display: flex;
  320. flex-direction: column;
  321. align-items: center;
  322. justify-content: center;
  323. .question {
  324. // 题干的样式
  325. background-color: #fff;
  326. height: 200rpx;
  327. border-radius: 6rpx;
  328. padding: 26rpx;
  329. opacity: 0.95;
  330. margin-bottom: 60rpx;
  331. }
  332. .options {
  333. // 选项的样式
  334. display: flex;
  335. gap: 20rpx;
  336. flex-direction: column;
  337. width: 100%;
  338. > .option {
  339. height: 80rpx;
  340. line-height: 80rpx;
  341. padding-left: 26rpx;
  342. border-radius: 6rpx;
  343. background-color: #fff;
  344. margin-bottom: 20rpx;
  345. opacity: 0.95;
  346. width: 100%;
  347. box-sizing: border-box;
  348. &.active {
  349. background-color: #e7522f;
  350. }
  351. }
  352. }
  353. .submit-btn {
  354. width: 100%;
  355. height: 80rpx;
  356. background-color: #e7522f;
  357. color: #fff;
  358. border-radius: 60rpx;
  359. display: flex;
  360. justify-content: center;
  361. align-items: center;
  362. padding: 16rpx;
  363. margin-top: 60rpx;
  364. &.disabled {
  365. background-color: #ccc;
  366. }
  367. }
  368. }
  369. .page-3 {
  370. width: 100%;
  371. height: 100%;
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. justify-content: center;
  376. opacity: 0.95;
  377. .result-content {
  378. width: 100%;
  379. .result-text {
  380. font-size: 46rpx;
  381. font-weight: bold;
  382. color: #fff;
  383. text-align: center;
  384. margin-bottom: 40rpx;
  385. }
  386. .result-btn {
  387. width: 100%;
  388. height: 80rpx;
  389. background-color: #f0370e;
  390. color: #fff;
  391. border-radius: 60rpx;
  392. display: flex;
  393. justify-content: center;
  394. align-items: center;
  395. padding: 16rpx;
  396. margin-top: 60rpx;
  397. box-sizing: border-box;
  398. }
  399. }
  400. .no-join-number {
  401. width: 100%;
  402. background-color: #fff;
  403. border-radius: 6rpx;
  404. padding: 26rpx;
  405. opacity: 0.95;
  406. margin-bottom: 60rpx;
  407. display: flex;
  408. flex-direction: column;
  409. box-sizing: border-box;
  410. gap: 40rpx;
  411. font-size: 36rpx;
  412. .header {
  413. display: flex;
  414. flex-direction: column;
  415. align-items: center;
  416. justify-content: center;
  417. gap: 20rpx;
  418. }
  419. .tip {
  420. font-size: 24rpx;
  421. display: flex;
  422. flex-direction: column;
  423. gap: 20rpx;
  424. }
  425. }
  426. }
  427. .lottery-entrance {
  428. position: absolute;
  429. z-index: 10;
  430. right: 20rpx;
  431. bottom: 100rpx;
  432. image {
  433. width: 160rpx;
  434. height: 160rpx;
  435. }
  436. .close-btn {
  437. width: 40rpx;
  438. height: 40rpx;
  439. font-size: 24rpx;
  440. line-height: 40rpx;
  441. border-radius: 50%;
  442. border: 1rpx solid #ddd;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. position: absolute;
  447. top: 5rpx;
  448. right: 0;
  449. color: #fff;
  450. }
  451. }
  452. }
  453. </style>