active.vue 20 KB

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