123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- <template>
- <view class="activity" style="background-image: none; background-color: #e03519; padding: 0 0 120rpx">
- <!-- <view class="rule" @click="showRule">活动规则</view> -->
- <!-- logo与跑马灯 -->
- <view class="header">
- <img :src="acticve_detail.logo" class="logo" mode="widthFix" />
- <view class="barrage-box">
- <view class="text">{{ lottery_list }}</view>
- </view>
- </view>
- <!-- 立即参与页面 -->
- <view class="page-1" v-if="pageIndex == 1" style="padding: 0 16rpx">
- <view class="activity-info">
- <text class="title">{{ acticve_detail?.name }}</text>
- <view class="active-rule">
- <rich-text :nodes="acticve_detail.active_rule" class="rich_text"></rich-text>
- </view>
- </view>
- <view class="activity-btn" @click="_handleChangePage(1)">立即参与</view>
- </view>
- <!-- 答题页面 -->
- <view class="page-2" v-if="pageIndex == 2">
- <!-- 题干区域 -->
- <view class="question">
- <text>猜灯谜:{{ question.title }}</text>
- <br />
- <view style="margin-top: 20rpx">(请从下面选择正确答案提交)</view>
- </view>
- <!-- 选项区域 -->
- <view class="options">
- <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>
- </view>
- <!-- 提交答案 -->
- <button :class="['submit-btn', { disabled: !answer_id }]" @click="_handleSubmitAnswer">提交</button>
- <!-- 活动规则 -->
- <view class="rule-btn" @click="_handleChangeRule('show')">活动规则</view>
- <uni-popup ref="lotteryRule" type="center">
- <view class="lottery_rule_box">
- <view class="lottery_rule_title">
- <text>活动规则</text>
- <view class="close_btn" @click="_handleChangeRule('close')"> X </view>
- </view>
- <scroll-view class="lottery_rule_info" scroll-y="true">
- <rich-text :nodes="acticve_detail.active_rule" class="rich_text"></rich-text>
- </scroll-view>
- </view>
- </uni-popup>
- </view>
- <!-- 结果页面 -->
- <view class="page-3" v-if="pageIndex == 3">
- <view class="no-join-number" v-if="acticve_detail.join_last == 0 && acticve_detail.share_last == 0 && isFromIndex">
- <view class="header">
- <text>您的答题次数已用完!</text>
- <text>谢谢参与</text>
- </view>
- <view class="tip">
- <text>1.余额请前往小程序余额页面申请提现</text>
- <text>2.实物奖励请填写收获地址或者等待客服进行充值</text>
- </view>
- </view>
- <view v-else style="width: 100%">
- <!-- 结果展示 -->
- <view class="result-success result-content" v-if="is_answer">
- <view class="result-text" style="color: #fff">恭喜您,答对啦!</view>
- <view class="result-btn-list">
- <view class="result-btn" @click="_goLottery">立即抽奖</view>
- <button open-type="share" class="result-btn">分享好友再来一次</button>
- </view>
- </view>
- <view class="result-fail result-content" v-if="!is_answer">
- <view class="result-text" style="color: #fff">很遗憾,您答错了!</view>
- <button open-type="share" class="result-btn">分享好友再来一次</button>
- </view>
- </view>
- </view>
- <!-- 抽奖入口 -->
- <view class="lottery-entrance" v-if="showLottery && pageIndex !== 1">
- <view class="close-btn" @click="_handleCloseLottery">x</view>
- <image @click="_goLottery" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250207-174439.gif" alt="" />
- </view>
- </view>
- </template>
- <script setup>
- import { ref, getCurrentInstance } from "vue";
- import { onShareAppMessage, onLoad, onShow } from "@dcloudio/uni-app";
- import http from "@/utils/request";
- const { appContext } = getCurrentInstance();
- const $checkAccess = appContext.config.globalProperties.$checkAccess;
- const pageIndex = ref(1);
- const question = ref({
- title: "",
- answer_list: [],
- });
- const showLottery = ref(true);
- const acticve_detail = ref({});
- const detialId = ref(null);
- const answer_id = ref(null);
- const is_answer = ref(false);
- const lottery_list = ref("还没有人中奖,快来参与吧!");
- const isFromIndex = ref(false);
- const lotteryRule = ref();
- onLoad((options) => {
- //未登陆提醒用户登陆
- if (!$checkAccess.checkLogin()) {
- uni.showModal({
- title: "温馨提示",
- content: "请先登录",
- confirmText: "去登录",
- cancelText: "取消",
- success: (res) => {
- if (res.confirm) {
- uni.redirectTo({
- url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${options.id}`,
- });
- }
- },
- });
- return;
- }
- if (options.id) {
- _getDeatail(detialId.value);
- detialId.value = options.id;
- }
- // #ifdef MP-WEIXIN
- //分享按钮
- uni.showShareMenu({
- withShareTicket: true,
- menus: ["shareAppMessage", "shareTimeline"],
- });
- // #endif
- });
- onShow(() => {
- console.log("回到小程序");
- if (detialId.value) {
- _getDeatail(detialId.value);
- }
- });
- // 定义页面的分享逻辑
- onShareAppMessage((res) => {
- if (res) {
- _addShare();
- }
- return {
- title: "正月十五猜灯谜",
- path: `/pages/activity/index?id=${detialId.value}`,
- imageUrl: "https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250210-115640.jpg",
- };
- });
- const _handleCloseLottery = () => {
- showLottery.value = false;
- };
- const _getDeatail = (id) => {
- if (!id) return;
- http.request("api/riddle_active/get_detail", { id }).then((response) => {
- console.log(response);
- if (response.code == "success") {
- acticve_detail.value = response.data;
- if (response.data.join_last > 0) {
- _getQuestion();
- pageIndex.value = 1;
- }
- http.request("api/lottery_riddle_record/get_list_all", { lottery_id: response.data.lottery_id }).then((res) => {
- if (res.code == "success") {
- if (res.data?.length > 0) {
- let str = "";
- res.data.forEach((item) => {
- str += `用户${item.username}已获得${item.reward_name};`;
- });
- lottery_list.value = str;
- }
- }
- });
- } else {
- console.log(response);
- uni.showToast({
- title: response.msg,
- icon: "none",
- });
- }
- });
- };
- const _getQuestion = () => {
- http.request("api/riddle_question/get_question").then((response) => {
- if (response.code == "success") {
- question.value = response.data;
- }
- });
- };
- const _handleSelectAnswer = (id) => {
- answer_id.value = id;
- };
- const _handleSubmitAnswer = () => {
- if (!answer_id.value) return;
- const _param = {
- active_id: detialId.value,
- question_id: question.value.id,
- answer_id: answer_id.value,
- };
- http.request("api/riddle_answer/check_answer", _param).then((response) => {
- if (response.code == "success") {
- pageIndex.value = 3;
- // _getDeatail(detialId.value);
- is_answer.value = response.data.is_answer;
- }
- });
- };
- const _addShare = () => {
- http.request("api/riddle_active_share/add", { active_id: detialId.value }).then((response) => {});
- };
- const _goLottery = () => {
- if (!$checkAccess.checkLogin()) {
- uni.showModal({
- title: "温馨提示",
- content: "请先登录",
- confirmText: "去登录",
- cancelText: "取消",
- success: (res) => {
- if (res.confirm) {
- uni.redirectTo({
- url: `/pages/login/index?redirect=/pages/activity/index&activity_id=${detialId.value}`,
- });
- }
- },
- });
- return;
- }
- uni.navigateTo({
- url: `/pages/activity/lottery?id=${acticve_detail.value.lottery_id}&activity_id=${detialId.value}`,
- });
- setTimeout(() => {
- pageIndex.value = 1;
- }, 1000);
- };
- const _handleChangePage = (index) => {
- if (index == 1 && acticve_detail.value.join_last > 0) {
- pageIndex.value = 2;
- answer_id.value = null;
- } else {
- pageIndex.value = 3;
- if (acticve_detail.value.join_last == 0 && acticve_detail.value.share_last == 0) {
- isFromIndex.value = true;
- }
- }
- };
- const _handleChangeRule = (type) => {
- if (type == "show") lotteryRule.value.open("center");
- else lotteryRule.value.close();
- };
- </script>
- <style lang="less" scoped>
- .activity {
- padding: 0 16rpx 120rpx;
- height: 100vh;
- box-sizing: border-box;
- overflow: hidden;
- position: relative;
- width: 100vw;
- .header {
- .logo {
- width: 100%;
- }
- .barrage-box {
- padding: 10rpx;
- width: 100%;
- transform-origin: 65vw 75vw;
- transform: rotate(0deg);
- white-space: nowrap;
- display: flex;
- justify-content: center;
- align-items: center;
- z-index: 3;
- box-sizing: border-box;
- background-color: #fff;
- opacity: 0.8;
- overflow-x: hidden;
- }
- .text {
- width: 200vw; //调整文字显示
- font-size: 16px;
- color: #333;
- animation: aniMove 8s linear infinite;
- animation-fill-mode: forwards;
- }
- /* 文字滚动 */
- @keyframes aniMove {
- 0% {
- transform: translateX(100%);
- }
- 100% {
- transform: translateX(-100%);
- }
- }
- }
- .page-1 {
- width: 100%;
- display: flex;
- align-items: center;
- flex-direction: column;
- justify-content: center;
- box-sizing: border-box;
- .activity-info {
- padding-top: 80rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 100%;
- .title {
- font-size: 46rpx;
- font-weight: bold;
- color: #fff;
- text-align: center;
- margin-bottom: 40rpx;
- }
- .active-rule {
- display: block;
- width: 100%;
- font-size: 30rpx;
- line-height: 40rpx;
- border-radius: 10rpx;
- padding: 26rpx;
- box-sizing: border-box;
- margin-bottom: 40rpx;
- background-color: #ffffff;
- opacity: 0.8;
- .rich_text {
- white-space: break-spaces;
- }
- }
- }
- .activity-btn {
- width: 90%;
- background-color: #ff8000;
- color: #fff;
- border-radius: 60rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 16rpx;
- }
- }
- .page-2 {
- height: 100%;
- display: flex;
- flex-direction: column;
- z-index: 10;
- width: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- box-sizing: border-box;
- padding: 0 16rpx;
- margin-top: -200rpx;
- .question {
- // 题干的样式
- background-color: #fff;
- max-height: 300rpx;
- border-radius: 6rpx;
- padding: 26rpx;
- opacity: 0.95;
- margin-bottom: 30rpx;
- width: 100%;
- box-sizing: border-box;
- overflow: auto;
- }
- .options {
- // 选项的样式
- display: flex;
- gap: 20rpx;
- flex-direction: column;
- width: 100%;
- > .option {
- height: 80rpx;
- line-height: 80rpx;
- padding-left: 26rpx;
- border-radius: 6rpx;
- background-color: #fff;
- margin-bottom: 10rpx;
- opacity: 0.95;
- width: 100%;
- box-sizing: border-box;
- &.active {
- background-color: #ffd6a0;
- }
- }
- }
- .submit-btn {
- width: 100%;
- height: 80rpx;
- background-color: #ffd6a0;
- color: #7e4304;
- border-radius: 60rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 16rpx;
- margin-top: 60rpx;
- &.disabled {
- background-color: #ccc;
- }
- }
- .rule-btn {
- position: absolute;
- right: 0;
- top: 8%;
- color: #7e4304;
- padding: 15rpx 10rpx 15rpx 35rpx;
- background-color: #ffd6a0;
- border-top-left-radius: 60rpx;
- border-bottom-left-radius: 60rpx;
- text-align: center;
- font-size: 28rpx;
- }
- .lottery_rule_box {
- width: 500rpx;
- display: block;
- overflow: hidden;
- background-color: #fc335f;
- font-size: 26rpx;
- margin: 0 auto;
- line-height: 50rpx;
- border-radius: 10rpx;
- padding: 20rpx 25rpx 20rpx;
- .lottery_rule_title {
- color: #ffffff;
- height: 60rpx;
- font-size: 32rpx;
- line-height: 60rpx;
- text-align: center;
- margin-bottom: 10rpx;
- .close_btn {
- float: right;
- width: 40rpx;
- height: 40rpx;
- font-size: 24rpx;
- margin-top: 9rpx;
- line-height: 40rpx;
- border-radius: 50%;
- border: 1rpx solid #ffffff;
- }
- }
- .lottery_rule_info {
- display: block;
- height: 500rpx;
- font-size: 24rpx;
- line-height: 40rpx;
- border-radius: 10rpx;
- padding: 20rpx;
- box-sizing: border-box;
- background-color: #ffffff;
- .rich_text {
- white-space: break-spaces;
- }
- }
- }
- }
- .page-3 {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- opacity: 0.95;
- box-sizing: border-box;
- padding: 0 16rpx;
- margin-top: -250rpx;
- .result-content {
- width: 100%;
- .result-text {
- font-size: 56rpx;
- font-weight: bold;
- color: #fff;
- text-align: center;
- margin-bottom: 100rpx;
- }
- .result-btn-list {
- display: flex;
- gap: 20rpx;
- }
- .result-btn {
- width: 100%;
- height: 80rpx;
- background-color: #ff8000;
- color: #fff;
- border-radius: 60rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 16rpx;
- margin-top: 60rpx;
- box-sizing: border-box;
- font-size: 36rpx;
- }
- }
- .no-join-number {
- width: 100%;
- background-color: #fff;
- border-radius: 6rpx;
- padding: 26rpx;
- opacity: 0.95;
- margin-bottom: 60rpx;
- display: flex;
- flex-direction: column;
- box-sizing: border-box;
- gap: 40rpx;
- font-size: 36rpx;
- .header {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- gap: 20rpx;
- }
- .tip {
- font-size: 24rpx;
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- }
- }
- }
- .lottery-entrance {
- position: absolute;
- z-index: 10;
- right: 20rpx;
- bottom: 100rpx;
- image {
- width: 160rpx;
- height: 160rpx;
- }
- .close-btn {
- width: 40rpx;
- height: 40rpx;
- font-size: 24rpx;
- line-height: 40rpx;
- border-radius: 50%;
- border: 1rpx solid #ddd;
- display: flex;
- align-items: center;
- justify-content: center;
- position: absolute;
- top: 5rpx;
- right: 0;
- color: #fff;
- }
- }
- }
- </style>
|