active.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <template>
  2. <view class="redpacket_active">
  3. <view class="welcome" :style="pageIndex == 1 ? 'height:auto' : ''">
  4. <!-- logo与跑马灯 -->
  5. <view class="header">
  6. <img :src="activeInfo.logo" class="logo" mode="widthFix" />
  7. <view class="barrage-box">
  8. <view class="text">{{ lottery_list?.length == 0 ? '还没有人中奖,快来参与吧!' : lottery_list }}</view>
  9. </view>
  10. </view>
  11. <!-- 立即参与页面 -->
  12. <view class="page-1" style="padding: 0 16rpx" v-if="pageIndex == 0">
  13. <view class="activity-info">
  14. <!-- <text class="title">{{ acticve_detail?.name }}</text> -->
  15. <view class="active-rule">
  16. <image class="rule-title" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/rule-title.png" />
  17. <rich-text :nodes="activeInfo.rule" class="rich_text" style="font-size: 36rpx; font-weight: 300"></rich-text>
  18. </view>
  19. </view>
  20. <view class="activity-btn" @click="_handleChangePage(1)">立即参与</view>
  21. </view>
  22. </view>
  23. <view
  24. class="active"
  25. v-if="pageIndex == 1"
  26. :style="
  27. isGetReward
  28. ? 'background-image:url(https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/get-reward-background.png)'
  29. : product_list.length == 0
  30. ? 'background-image:url(https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/no-product-background.png)'
  31. : 'background-image:url(https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/active-background.png)'
  32. "
  33. >
  34. <view class="active-text" v-if="isGetReward">{{ rewardInfo?.money || 0 }}&nbsp;<text style="font-size: 36rpx">元</text></view>
  35. <view class="active_btn" v-if="!isGetReward" :style="product_list.length == 0 ? 'top:285rpx' : 'top: 280rpx'" @click="get_reward"> </view>
  36. <view class="active_rule_btn" @click="showRule">活动规则</view>
  37. <view class="active_record_btn" @click="showRecord">领取记录</view>
  38. <view class="left-number">领取机会剩余 {{ activeInfo.number }} 次</view>
  39. <view class="active-product" v-if="product_list.length !== 0">
  40. <image class="active-product-title" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/active-product-title" />
  41. <!-- 产品列表 -->
  42. <view class="product_list">
  43. <!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
  44. <view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item, index) in product_list" :key="index">
  45. <image class="product_image" :src="item.product_thumb" mode="" />
  46. <view class="product_name">
  47. <text>{{ item.product_name }}</text></view
  48. >
  49. <view class="product_spec"
  50. ><text>{{ item.sku_attr_names }}</text></view
  51. >
  52. <view class="stock_price">
  53. <text>¥{{ item.price }} </text>
  54. <view class="product_stock">剩{{ item.stock }}个</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- <view class="lottery_need_score"> </view> -->
  60. <uni-popup ref="activeRule" type="center">
  61. <view class="active_rule_box">
  62. <view class="activity-info">
  63. <!-- <text class="title">{{ acticve_detail?.name }}</text> -->
  64. <view class="active-rule">
  65. <image class="rule-title" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/rule-title.png" />
  66. <rich-text :nodes="activeInfo.rule" class="rich_text" style="font-size: 36rpx; font-weight: 300"></rich-text>
  67. </view>
  68. </view>
  69. <view class="close-btn" @click="closeRule"></view>
  70. </view>
  71. </uni-popup>
  72. <uni-popup ref="rewardDialog" type="center">
  73. <view class="active_rule_box">
  74. <view class="activity-reward">
  75. <view class="reward-text">{{ rewardInfo?.money || 0 }}&nbsp;<text style="font-size: 36rpx">元</text></view>
  76. <view class="reward-btn" @click="closeReward"></view>
  77. </view>
  78. <view class="close-btn" @click="closeReward"></view>
  79. </view>
  80. </uni-popup>
  81. <uni-popup ref="activeRecord" type="center">
  82. <view class="active_rule_box">
  83. <view class="lottery_record">
  84. <view class="lottery_record_none" v-if="!recordList.length">这里还是空的哦~</view>
  85. <scroll-view class="lottery_record_list" scroll-y="true">
  86. <view class="lottery_record_item" v-for="(item, index) in recordList" :key="index">
  87. <view class="reward_name">获得{{ item.money }}元</view>
  88. <view class="reward_time">{{ item.insert_time }}</view>
  89. </view>
  90. </scroll-view>
  91. </view>
  92. <view class="close-btn" @click="closeRecord"></view>
  93. </view>
  94. </uni-popup>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. lottery_list: '',
  103. // 抽奖信息
  104. activeInfo: {
  105. id: 0,
  106. name: '',
  107. logo: '',
  108. number: '0',
  109. start_date: '',
  110. end_date: '',
  111. start_time: '',
  112. end_time: '',
  113. rule: '',
  114. },
  115. // 请求参数
  116. requestParam: {
  117. id: 0,
  118. },
  119. pageIndex: 0,
  120. product_list: [],
  121. rewardInfo: {},
  122. isGetReward: false, //记录本次是否领取
  123. recordList: [],
  124. };
  125. },
  126. onLoad(param) {
  127. //未登陆提醒用户登陆
  128. try {
  129. // 接收参数
  130. console.log(param, 'onload param');
  131. this.requestParam.id = param.id;
  132. this.pageIndex = param.pageIndex || 0;
  133. // 如果有scene参数的话,获取其中的ID
  134. if (param.scene) {
  135. // 转键值对参数
  136. let scene = this.$http.strToParam(param.scene);
  137. // 如果没有传入ID,但是传入了场景ID,获取场景ID
  138. if (!param.id && scene.id) this.requestParam.id = scene.id;
  139. }
  140. // 窗口信息
  141. var sysinfo = uni.getWindowInfo();
  142. // 获取屏幕可用高度
  143. this.height = 'height:' + sysinfo.windowHeight + 'px;';
  144. // #ifdef MP-WEIXIN
  145. //分享按钮
  146. uni.showShareMenu({
  147. withShareTicket: true,
  148. menus: ['shareAppMessage', 'shareTimeline'],
  149. });
  150. // #endif
  151. } catch (e) {
  152. console.log(e);
  153. }
  154. },
  155. onShareAppMessage(obj) {
  156. // if (obj) {
  157. // this.shareRequest();
  158. // }
  159. return {
  160. title: '999智控终端平台\n新人抽奖',
  161. path: `/pages/redpacket/active?id=${this.requestParam.id}`,
  162. imageUrl: 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250210-143021.jpg',
  163. promise: new Promise((resolve, reject) => {
  164. this.$http.request('api/share_message/get_item', { item_id: this.requestParam.id, pages: '/pages/redpacket/active' }).then((callback) => {
  165. console.log(callback, 'api/share_message/get_item');
  166. let obj = {
  167. title: callback.data?.title == '' ? this.activeInfo.name : callback.data.title,
  168. path: '/pages/redpacket/active?id=' + this.requestParam.id,
  169. imageUrl: callback.data?.image_url == '' ? this.activeInfo.logo : callback.data.image_url,
  170. };
  171. resolve(obj);
  172. });
  173. }),
  174. };
  175. },
  176. onShow() {
  177. console.log(this.requestParam, 'onshow requestParam');
  178. if (!this.$checkAccess.checkLogin()) {
  179. uni.showModal({
  180. title: '温馨提示',
  181. content: '请先登录',
  182. confirmText: '去登录',
  183. cancelText: '取消',
  184. success: (res) => {
  185. if (res.confirm) {
  186. uni.redirectTo({
  187. url: `/pages/login/index?redirect=/pages/redpacket/active&id=${this.requestParam.id}`,
  188. });
  189. }
  190. },
  191. });
  192. return;
  193. }
  194. // 没有数据的话,或者请求中,不允许刷新
  195. if (this.isReqing) return;
  196. // 登录提示
  197. // if (!this.$checkAccess.alterLogin()) return;
  198. // 如果存在产品ID的话
  199. if (this.requestParam?.id > 0) {
  200. // 设置请求中
  201. this.isReqing = true;
  202. // 请求
  203. this.$http.request('api/redpacket_active/get_detail', this.requestParam).then((re) => {
  204. // 设置非请求中
  205. this.isReqing = false;
  206. // 成功结果
  207. if (re.code == 'success') {
  208. this.activeInfo = re.data;
  209. this.prizeList = re.data.reward_list;
  210. this.product_list = Object.values(re.data.product_list || {});
  211. this._getRecordList();
  212. } else {
  213. if (re.code != 'no_login') {
  214. uni.showModal({
  215. content: re.msg,
  216. showCancel: false,
  217. });
  218. }
  219. }
  220. });
  221. } else {
  222. uni.showModal({
  223. content: '未知的活动ID',
  224. showCancel: false,
  225. });
  226. }
  227. },
  228. methods: {
  229. _getRecordList() {
  230. this.$http.request('api/redpacket_active_record/get_list_all', { active_id: this.requestParam.id }).then((res) => {
  231. if (res.code == 'success') {
  232. if (res.data?.length > 0) {
  233. let str = '';
  234. res.data.forEach((item) => {
  235. str += `用户${item.username}已获得${item.money}元;`;
  236. });
  237. this.lottery_list = str;
  238. }
  239. }
  240. });
  241. },
  242. _handleChangePage(index) {
  243. this.pageIndex = index;
  244. },
  245. showRule() {
  246. this.$refs.activeRule.open('center');
  247. },
  248. closeRule() {
  249. this.$refs.activeRule.close();
  250. },
  251. toDetail(item) {
  252. uni.navigateTo({
  253. url: '/pages/product/index?product_id=' + item.id,
  254. });
  255. },
  256. get_reward() {
  257. this.$http.request('api/redpacket_active/get_reward', { active_id: this.requestParam.id }).then((res) => {
  258. if (res.code == 'success') {
  259. this.rewardInfo = res.data.reward_list[res.data.reward_index];
  260. this.showReward();
  261. } else {
  262. console.log(res.msg);
  263. uni.showToast({
  264. title: res.msg,
  265. icon: 'none',
  266. });
  267. }
  268. });
  269. },
  270. showReward() {
  271. this.$refs.rewardDialog.open('center');
  272. },
  273. closeReward() {
  274. this.isGetReward = true;
  275. this.$refs.rewardDialog.close();
  276. },
  277. closeRecord() {
  278. this.$refs.activeRecord.close();
  279. },
  280. showRecord() {
  281. // 活动是否开始
  282. // 请求列表
  283. this.$http.request('/api/redpacket_active_record/get_list', { active_id: this.requestParam.id }).then((re) => {
  284. // 设置非请求中
  285. this.isReqing = false;
  286. // 成功结果
  287. if (re.code == 'success') {
  288. this.recordList = re.data;
  289. } else {
  290. this.recordList = [];
  291. }
  292. this.$refs.activeRecord.open('center');
  293. });
  294. },
  295. },
  296. };
  297. </script>
  298. <style lang="less" scoped>
  299. .redpacket_active {
  300. box-sizing: border-box;
  301. position: relative;
  302. height: 100vh;
  303. .activity-info {
  304. padding-top: 60rpx;
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. justify-content: center;
  309. width: 100%;
  310. .active-rule {
  311. font-size: 30rpx;
  312. line-height: 40rpx;
  313. box-sizing: border-box;
  314. margin-bottom: 75rpx;
  315. width: 570rpx;
  316. height: 464rpx;
  317. overflow-y: auto;
  318. padding: 24rpx 48rpx;
  319. background-color: #fff5ca;
  320. border-radius: 24rpx 24rpx 24rpx 24rpx;
  321. .rule-title {
  322. width: 411.5rpx;
  323. height: 66rpx;
  324. margin: 0 auto;
  325. display: block;
  326. margin-bottom: 32rpx;
  327. }
  328. .rich_text {
  329. white-space: break-spaces;
  330. }
  331. }
  332. }
  333. .welcome {
  334. width: 100vw;
  335. height: 100%;
  336. display: flex;
  337. flex-direction: column;
  338. box-sizing: border-box;
  339. background: #e63521;
  340. .header {
  341. .logo {
  342. width: 100%;
  343. }
  344. .barrage-box {
  345. padding: 10rpx;
  346. width: 100%;
  347. transform-origin: 65vw 75vw;
  348. transform: rotate(0deg);
  349. white-space: nowrap;
  350. display: flex;
  351. justify-content: center;
  352. align-items: center;
  353. z-index: 3;
  354. box-sizing: border-box;
  355. background-color: #ff8b37;
  356. opacity: 0.8;
  357. overflow-x: hidden;
  358. margin-top: -6rpx;
  359. }
  360. .text {
  361. width: 200vw; //调整文字显示
  362. font-size: 16px;
  363. color: #333;
  364. animation: aniMove 8s linear infinite;
  365. animation-fill-mode: forwards;
  366. }
  367. /* 文字滚动 */
  368. @keyframes aniMove {
  369. 0% {
  370. transform: translateX(100%);
  371. }
  372. 100% {
  373. transform: translateX(-100%);
  374. }
  375. }
  376. }
  377. .page-1 {
  378. width: 100%;
  379. display: flex;
  380. align-items: center;
  381. flex-direction: column;
  382. box-sizing: border-box;
  383. height: 100%;
  384. .activity-btn {
  385. width: 368rpx;
  386. height: 109rpx;
  387. font-weight: bold;
  388. font-size: 52rpx;
  389. color: #e63521;
  390. background-color: #ffe13f;
  391. border-radius: 60rpx;
  392. text-align: center;
  393. line-height: 109rpx;
  394. }
  395. }
  396. }
  397. .active {
  398. background-size: contain;
  399. background-repeat: no-repeat;
  400. width: 100vw;
  401. min-height: 100vh;
  402. position: relative;
  403. background-color: #db1101;
  404. padding: 0 32rpx;
  405. box-sizing: border-box;
  406. padding-top: 702rpx;
  407. .left-number {
  408. position: absolute;
  409. width: 100%;
  410. text-align: center;
  411. top: 650rpx;
  412. font-size: 24rpx;
  413. color: #fff5ca;
  414. left: 0;
  415. }
  416. .active_btn {
  417. width: 130rpx;
  418. height: 130rpx;
  419. position: absolute;
  420. background-image: url('https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/get-btn.png');
  421. background-repeat: no-repeat;
  422. background-size: 100% 100%;
  423. left: 310rpx;
  424. }
  425. .active-text {
  426. font-size: 82rpx;
  427. color: #c91810;
  428. position: absolute;
  429. top: 220rpx;
  430. width: 100%;
  431. text-align: center;
  432. left: 0;
  433. }
  434. .active_rule_btn,
  435. .active_record_btn {
  436. width: 140rpx;
  437. height: 60rpx;
  438. background: #ffde9e;
  439. color: #ff0000;
  440. border-radius: 500rpx 0rpx 0rpx 500rpx;
  441. position: absolute;
  442. right: 0;
  443. top: 20rpx;
  444. z-index: inherit;
  445. font-size: 26rpx;
  446. text-align: center;
  447. line-height: 60rpx;
  448. }
  449. .active_record_btn {
  450. left: 0rpx;
  451. border-radius: 0 500rpx 500rpx 0;
  452. }
  453. .active_rule_box {
  454. display: flex;
  455. flex-direction: column;
  456. justify-content: center;
  457. align-items: center;
  458. .activity-reward {
  459. background-image: url('https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/reward-dialog.png');
  460. background-repeat: no-repeat;
  461. background-size: 100% 100%;
  462. width: 671rpx;
  463. height: 671rpx;
  464. position: relative;
  465. .reward-text {
  466. font-size: 82rpx;
  467. color: #c91810;
  468. position: absolute;
  469. top: 245rpx;
  470. width: 100%;
  471. text-align: center;
  472. }
  473. .reward-btn {
  474. background-image: url('https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/redpacket/happy-get.png');
  475. background-repeat: no-repeat;
  476. background-size: 100% 100%;
  477. width: 258rpx;
  478. height: 98rpx;
  479. position: absolute;
  480. bottom: 127rpx;
  481. left: 208rpx;
  482. }
  483. }
  484. }
  485. .active-product {
  486. background-color: #fff5ca;
  487. padding: 32rpx 24rpx;
  488. border-radius: 24rpx 24rpx 24rpx 24rpx;
  489. .active-product-title {
  490. width: 412rpx;
  491. height: 66rpx;
  492. margin: 0 auto;
  493. display: block;
  494. box-sizing: border-box;
  495. }
  496. .product_list {
  497. display: block;
  498. overflow: hidden;
  499. margin: 0rpx auto;
  500. .product_item {
  501. float: left;
  502. width: 320rpx;
  503. height: 520rpx;
  504. display: block;
  505. overflow: hidden;
  506. margin: 20rpx 0rpx;
  507. margin-right: 40rpx;
  508. background-color: #ffffff;
  509. border-radius: 20rpx;
  510. .product_image {
  511. width: 320rpx;
  512. height: 320rpx;
  513. }
  514. .product_name {
  515. height: 80rpx;
  516. font-size: 30rpx;
  517. line-height: 40rpx;
  518. overflow: hidden;
  519. margin: 10rpx 0rpx;
  520. padding: 0rpx 10rpx;
  521. text-overflow: ellipsis;
  522. .regiment_title {
  523. background-color: red;
  524. color: #f9f9f9;
  525. }
  526. }
  527. .product_spec {
  528. height: 30rpx;
  529. color: #999999;
  530. font-size: 24rpx;
  531. line-height: 30rpx;
  532. padding: 0rpx 10rpx;
  533. overflow: hidden;
  534. white-space: nowrap;
  535. text-overflow: ellipsis;
  536. }
  537. .stock_price {
  538. color: #dddddd;
  539. font-size: 20rpx;
  540. overflow: hidden;
  541. line-height: 30rpx;
  542. padding: 0rpx 10rpx;
  543. .product_price {
  544. float: left;
  545. color: red;
  546. font-size: 30rpx;
  547. line-height: 60rpx;
  548. .product_market {
  549. font-size: 24rpx;
  550. color: #999999;
  551. line-height: 30rpx;
  552. vertical-align: top;
  553. text-decoration: line-through;
  554. }
  555. }
  556. .product_stock {
  557. float: right;
  558. font-size: 20rpx;
  559. line-height: 60rpx;
  560. }
  561. }
  562. }
  563. .product_item:nth-child(even) {
  564. margin-right: 0rpx;
  565. }
  566. }
  567. }
  568. .lottery_record {
  569. background-image: url('https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/lettery_record.png');
  570. background-size: 100% 100%;
  571. background-repeat: no-repeat;
  572. width: 682rpx;
  573. height: 456rpx;
  574. margin: 0 auto;
  575. overflow-y: auto;
  576. padding: 56rpx 48rpx;
  577. box-sizing: border-box;
  578. .lottery_record_none {
  579. width: 100%;
  580. height: 100%;
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. color: #deb887;
  585. }
  586. .lottery_record_item {
  587. width: 586rpx;
  588. height: 93rpx;
  589. border-radius: 0rpx 0rpx 0rpx 0rpx;
  590. border-bottom: 1rpx solid #e3e3e3;
  591. display: flex;
  592. justify-content: space-between;
  593. align-items: center;
  594. .reward_name {
  595. color: #333;
  596. }
  597. .reward_time {
  598. font-size: 24rpx;
  599. color: #999999;
  600. }
  601. }
  602. }
  603. }
  604. .close-btn {
  605. background-image: url('https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/close_btn.png');
  606. background-repeat: no-repeat;
  607. background-size: 100% 100%;
  608. width: 62rpx;
  609. height: 62rpx;
  610. margin-top: 32rpx;
  611. }
  612. }
  613. </style>