active.vue 20 KB

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