lottery.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <template>
  2. <view>
  3. <view class="lottery_box" :style="height">
  4. <view class="lottery_time" v-if="lotteryInfo.id">活动时间:{{ lotteryInfo.start_date }} ~ {{ lotteryInfo.end_date }}</view>
  5. <view class="lottery_info">
  6. <image class="lottery_logo" v-if="lotteryInfo.logo" :src="lotteryInfo.logo" mode="widthFix"></image>
  7. <button class="lottery_rule_btn" @click="showRule">活动规则</button>
  8. </view>
  9. <l-dialer
  10. :customStyle="'width: 500rpx;height: 500rpx;margin: 0rpx auto;'"
  11. @click="onClick"
  12. dial-style="color: rgba(60,48,158,0.7); padding: 32rpx;background-image: url(https://mall.findit.ltd/uploads/images/default/lottery_bg.png)"
  13. :prizeList="prizeList"
  14. :turns="5"
  15. :duration="5"
  16. @done="onDone"
  17. ref="dialer"
  18. />
  19. <view class="record_box">
  20. <view class="score_info">
  21. <view class="custom_score">可用次数:{{ lotteryInfo.number }}</view>
  22. <view class="need_score" v-if="!lotteryInfo.id">暂无可参与的活动</view>
  23. </view>
  24. <button class="lottery_record" @click="showRecord" v-if="lotteryInfo.id">
  25. <image class="lottery_record_img" src="https://mall.findit.ltd/uploads/images/default/lottery_record.png" mode=""></image>
  26. <text class="lottery_record_text">中奖记录</text>
  27. </button>
  28. </view>
  29. <button open-type="share" class="share-btn">分享好友再答一次题</button>
  30. </view>
  31. <uni-popup ref="lotteryRule" type="center">
  32. <view class="lottery_rule_box">
  33. <view class="lottery_rule_title">
  34. <text>活动规则</text>
  35. <view class="close_btn" @click="closeRule"> X </view>
  36. </view>
  37. <scroll-view class="lottery_rule_info" scroll-y="true">
  38. <rich-text :nodes="lotteryInfo.rule" class="rich_text"></rich-text>
  39. </scroll-view>
  40. </view>
  41. </uni-popup>
  42. <uni-popup ref="lotteryRecord" type="bottom">
  43. <view class="lottery_record_box">
  44. <view class="lottery_record_title">
  45. <text>我的奖品</text>
  46. <view class="close_btn" @click="closeRecord"> X </view>
  47. </view>
  48. <view class="lottery_record_none" v-if="!recordList.length">这里还是空的哦~</view>
  49. <scroll-view class="lottery_record_list" scroll-y="true">
  50. <view class="lottery_record_item" v-for="(item, index) in recordList" :key="index">
  51. <view class="reward_time">{{ item.insert_time }}</view>
  52. <view class="reward_name">{{ item.reward_name }}</view>
  53. <view class="reward_state" v-if="item.status">{{ item.state }}</view>
  54. <view class="reward_state" v-if="!item.status" @click="openAddr(index)">{{ item.state }}</view>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. </uni-popup>
  59. <uni-popup ref="addrPopup" type="bottom" class="popup" background-color="#FFFFFF">
  60. <view class="popup_title">收货地址 <navigator url="/pages/addr/index?notify=addr" class="to_addr_page">管理</navigator> </view>
  61. <view class="addr_list">
  62. <view class="addr_item" v-for="(item, index) in addrList" :key="index" @click="checkedAddrItem(item)">
  63. <view class="radio_label">
  64. <image
  65. class="radio_icon"
  66. :src="item.id == checkedAddr.id ? 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/radioed.png' : 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/radio.png'"
  67. ></image>
  68. </view>
  69. <view class="contact_user">
  70. <text class="contact_name">{{ item.contact_name }}</text>
  71. <text class="contact_phone">{{ item.contact_phone }}</text>
  72. <text class="contact_default" v-if="item.is_default">默认</text>
  73. <text class="contact_shop">{{ item.contact_shop }}</text>
  74. </view>
  75. <view class="contact_addr"> {{ item.contact_province }} {{ item.contact_city }} {{ item.contact_area }} {{ item.contact_addr }} </view>
  76. </view>
  77. </view>
  78. <view class="create_box">
  79. <navigator url="/pages/addr/index?notify=addr&type=create" class="create_addr">新建收货地址</navigator>
  80. </view>
  81. </uni-popup>
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. height: "",
  89. // 奖项列表,
  90. prizeList: [],
  91. // 中奖记录
  92. recordList: [],
  93. // 地址列表
  94. addrList: [],
  95. // 抽奖信息
  96. lotteryInfo: {
  97. id: 0,
  98. name: "",
  99. logo: "",
  100. number: "0",
  101. start_date: "",
  102. end_date: "",
  103. start_time: "",
  104. end_time: "",
  105. rule: "",
  106. },
  107. recordId: 0,
  108. // 请求参数
  109. requestParam: {
  110. id: 0,
  111. activity_id: 0,
  112. },
  113. };
  114. },
  115. onLoad(param) {
  116. // 接收参数
  117. this.requestParam.id = param.id;
  118. this.requestParam.activity_id = param.activity_id;
  119. // 如果有scene参数的话,获取其中的ID
  120. if (param.scene) {
  121. // 转键值对参数
  122. let scene = this.$http.strToParam(param.scene);
  123. // 如果没有传入ID,但是传入了场景ID,获取场景ID
  124. if (!param.id && scene.id) this.requestParam.id = scene.id;
  125. }
  126. // 窗口信息
  127. var sysinfo = uni.getWindowInfo();
  128. // 获取屏幕可用高度
  129. this.height = "height:" + sysinfo.windowHeight + "px;";
  130. // 监听地址变动
  131. uni.$on("addr_list_change", (data) => {
  132. // 地址列表
  133. this.addrList = data.list;
  134. });
  135. // #ifdef MP-WEIXIN
  136. //分享按钮
  137. uni.showShareMenu({
  138. withShareTicket: true,
  139. menus: ["shareAppMessage", "shareTimeline"],
  140. });
  141. // #endif
  142. },
  143. onShareAppMessage(obj) {
  144. if (obj) {
  145. this.shareRequest();
  146. }
  147. return {
  148. title: "正月十五猜灯谜",
  149. path: "/pages/activity/index?id=" + this.requestParam.activity_id,
  150. imageUrl: "https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/lottery/20250210-115640.jpg",
  151. };
  152. },
  153. onShow() {
  154. // 没有数据的话,或者请求中,不允许刷新
  155. if (this.isReqing) return;
  156. // 登录提示
  157. if (!this.$checkAccess.alterLogin()) return;
  158. // 如果存在产品ID的话
  159. if (this.requestParam.id > 0) {
  160. // 设置请求中
  161. this.isReqing = true;
  162. // 请求
  163. this.$http.request("api/lottery_riddle/get_detail", this.requestParam).then((re) => {
  164. // 设置非请求中
  165. this.isReqing = false;
  166. // 成功结果
  167. if (re.code == "success") {
  168. this.lotteryInfo = re.data;
  169. this.prizeList = re.data.reward_list;
  170. } else {
  171. if (re.code != "no_login") {
  172. uni.showModal({
  173. content: re.msg,
  174. showCancel: false,
  175. });
  176. }
  177. }
  178. });
  179. } else {
  180. uni.showModal({
  181. content: "未知的活动ID",
  182. showCancel: false,
  183. });
  184. }
  185. },
  186. methods: {
  187. shareRequest() {
  188. this.$http.request("api/riddle_active_share/add", { active_id: this.requestParam.activity_id }).then((response) => {});
  189. },
  190. onDone(index) {
  191. // 奖项
  192. let prize = this.prizeList[index];
  193. // 结果
  194. uni.showModal({
  195. title: prize.id == 0 ? "很遗憾" : "恭喜您",
  196. content: (prize.id != 0 ? `获得` : "") + prize.name + (prize.reward_type == 5 ? ",请在中奖记录中填写收货地址" : ""),
  197. showCancel: false,
  198. success: (re) => {
  199. if (re.confirm && prize.reward_type == 5) {
  200. // 显示中奖列表
  201. this.showRecord();
  202. }
  203. },
  204. });
  205. },
  206. onClick() {
  207. // 活动是否开始
  208. if (!this.lotteryInfo.id) {
  209. uni.showToast({
  210. title: "暂无可参与活动",
  211. icon: "none",
  212. });
  213. return;
  214. }
  215. // 活动是否开始
  216. if (this.lotteryInfo.start_time * 1000 > new Date().getTime()) {
  217. uni.showToast({
  218. title: "活动还没开始哦",
  219. icon: "none",
  220. });
  221. return;
  222. }
  223. // 活动是否结束
  224. if (this.lotteryInfo.end_time * 1000 <= new Date().getTime()) {
  225. uni.showToast({
  226. title: "活动已结束了哦",
  227. icon: "none",
  228. });
  229. return;
  230. }
  231. // 次数已用完了
  232. if (this.lotteryInfo.number <= 0) {
  233. uni.showToast({
  234. title: "次数已用完了",
  235. icon: "none",
  236. });
  237. return;
  238. }
  239. // 次数操作
  240. this.lotteryInfo.number = this.lotteryInfo.number - 1;
  241. // 请求列表
  242. this.$http.request("/api/lottery_riddle/get_reward", { lottery_id: this.lotteryInfo.id }).then((re) => {
  243. // 设置非请求中
  244. this.isReqing = false;
  245. // 成功结果
  246. if (re.code == "success") {
  247. // 奖品列表更新
  248. this.prizeList = re.data.reward_list;
  249. // 奖品的索引
  250. return this.$refs.dialer.run(re.data.reward_index);
  251. } else {
  252. uni.showToast({
  253. title: re.msg,
  254. icon: "none",
  255. });
  256. return;
  257. }
  258. });
  259. },
  260. showRule() {
  261. this.$refs.lotteryRule.open("center");
  262. },
  263. closeRule() {
  264. this.$refs.lotteryRule.close();
  265. },
  266. showRecord() {
  267. // 活动是否开始
  268. if (this.lotteryInfo.id) {
  269. // 请求列表
  270. this.$http.request("/api/lottery_riddle_record/get_list", { lottery_id: this.lotteryInfo.id }).then((re) => {
  271. // 设置非请求中
  272. this.isReqing = false;
  273. // 成功结果
  274. if (re.code == "success") {
  275. this.recordList = re.data;
  276. }
  277. });
  278. }
  279. this.$refs.lotteryRecord.open("bottom");
  280. },
  281. closeRecord() {
  282. this.$refs.lotteryRecord.close();
  283. },
  284. openAddr(index) {
  285. // 选择的下标
  286. this.recordIndex = index;
  287. // 地址列表
  288. this.getAddrList(true);
  289. },
  290. // 选择地址
  291. checkedAddrItem(item) {
  292. // 判断数据
  293. this.$http.request("api/lottery_riddle_record/set_addr", { id: this.recordList[this.recordIndex].id, addr_id: item.id }, "post").then((callback) => {
  294. // 获取成功
  295. if (callback.code == "success") {
  296. this.recordList[this.recordIndex].status = 1;
  297. this.recordList[this.recordIndex].state = "进行中";
  298. }
  299. this.$refs.addrPopup.close();
  300. });
  301. },
  302. getAddrList(showPopup = false) {
  303. // 判断数据
  304. this.$http.request("api/custom_addr/get_list").then((callback) => {
  305. // 获取成功
  306. if (callback.code == "success") {
  307. this.addrList = callback.data;
  308. // 如果有的话
  309. if (this.addrList.length) {
  310. // 获取默认的
  311. for (let i in this.addrList) {
  312. // 如果是默认的
  313. if (this.addrList[i].is_default) this.checkedAddr = this.addrList[i];
  314. }
  315. // 如果没有默认的话
  316. if (!this.checkedAddr.id) {
  317. this.checkedAddr = this.addrList[this.addrList.length - 1];
  318. }
  319. }
  320. // 弹出地址层
  321. if (showPopup) this.$refs.addrPopup.open("bottom");
  322. }
  323. });
  324. },
  325. },
  326. };
  327. </script>
  328. <style lang="less">
  329. .lottery_box {
  330. display: block;
  331. width: 750rpx;
  332. height: 1100rpx;
  333. margin: 0 auto;
  334. position: relative;
  335. background: linear-gradient(to bottom, #fc335f 0%, #fb7224 80%, #ffffff 100%);
  336. .share-btn {
  337. width: 80%;
  338. height: 80rpx;
  339. background-color: #f0370e;
  340. color: #fff;
  341. border-radius: 60rpx;
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. padding: 16rpx;
  346. margin-top: 60rpx;
  347. box-sizing: border-box;
  348. }
  349. .lottery_time {
  350. top: 0rpx;
  351. left: 35rpx;
  352. z-index: 1;
  353. width: 700rpx;
  354. color: #ffffff;
  355. display: block;
  356. height: 40rpx;
  357. font-size: 24rpx;
  358. line-height: 40rpx;
  359. text-align: center;
  360. position: absolute;
  361. border-radius: 10rpx;
  362. background-color: rgba(0, 0, 0, 0.15);
  363. }
  364. .lottery_info {
  365. width: 750rpx;
  366. overflow: hidden;
  367. margin: 0rpx auto;
  368. position: relative;
  369. margin-bottom: 40rpx;
  370. .lottery_logo {
  371. float: left;
  372. width: 750rpx;
  373. height: 240rpx;
  374. display: block;
  375. }
  376. .lottery_rule_btn {
  377. top: 50%;
  378. right: 0rpx;
  379. width: 120rpx;
  380. height: 60rpx;
  381. color: #ffffff;
  382. overflow: hidden;
  383. font-size: 24rpx;
  384. text-align: center;
  385. line-height: 60rpx;
  386. position: absolute;
  387. padding: 0rpx 0rpx;
  388. border-top-left-radius: 30rpx;
  389. border-bottom-left-radius: 30rpx;
  390. border-top-right-radius: 0rpx;
  391. border-bottom-right-radius: 0rpx;
  392. background-color: rgba(0, 0, 0, 0.3);
  393. }
  394. .lottery_rule_btn::after {
  395. border: 0rpx solid transparent;
  396. }
  397. }
  398. .record_box {
  399. display: block;
  400. height: 120rpx;
  401. overflow: hidden;
  402. position: relative;
  403. margin-top: 40rpx;
  404. .score_info {
  405. display: block;
  406. overflow: auto;
  407. .custom_score {
  408. height: 60rpx;
  409. font-size: 28rpx;
  410. text-align: center;
  411. line-height: 60rpx;
  412. }
  413. .need_score {
  414. height: 60rpx;
  415. font-size: 32rpx;
  416. text-align: center;
  417. line-height: 60rpx;
  418. }
  419. }
  420. .lottery_record {
  421. top: 0rpx;
  422. right: 0rpx;
  423. width: 120rpx;
  424. height: 120rpx;
  425. overflow: hidden;
  426. text-align: center;
  427. position: absolute;
  428. padding: 0rpx 0rpx;
  429. background-color: transparent;
  430. .lottery_record_img {
  431. width: 60rpx;
  432. height: 60rpx;
  433. display: block;
  434. margin: 0rpx auto;
  435. }
  436. .lottery_record_text {
  437. color: #ffffff;
  438. display: block;
  439. height: 40rpx;
  440. width: 120rpx;
  441. font-size: 24rpx;
  442. line-height: 40rpx;
  443. }
  444. }
  445. .lottery_record::after {
  446. border: none;
  447. }
  448. }
  449. }
  450. .lottery_rule_box {
  451. width: 500rpx;
  452. display: block;
  453. overflow: hidden;
  454. background: #ffffff;
  455. font-size: 26rpx;
  456. margin: 0rpx auto;
  457. line-height: 50rpx;
  458. border-radius: 10rpx;
  459. padding: 0rpx 25rpx;
  460. padding-bottom: 20rpx;
  461. background-color: #fc335f;
  462. .lottery_rule_title {
  463. color: #ffffff;
  464. height: 60rpx;
  465. font-size: 32rpx;
  466. line-height: 60rpx;
  467. text-align: center;
  468. margin-bottom: 10rpx;
  469. .close_btn {
  470. float: right;
  471. width: 40rpx;
  472. height: 40rpx;
  473. font-size: 24rpx;
  474. margin-top: 9rpx;
  475. line-height: 40rpx;
  476. border-radius: 50%;
  477. border: 1rpx solid #ffffff;
  478. }
  479. }
  480. .lottery_rule_info {
  481. display: block;
  482. height: 500rpx;
  483. font-size: 24rpx;
  484. line-height: 40rpx;
  485. border-radius: 10rpx;
  486. padding: 20rpx 20rpx;
  487. box-sizing: border-box;
  488. background-color: #ffffff;
  489. .rich_text {
  490. white-space: break-spaces;
  491. }
  492. }
  493. }
  494. .lottery_record_box {
  495. display: block;
  496. color: #deb887;
  497. height: 700rpx;
  498. padding: 10rpx 25rpx;
  499. background-color: #faebd7;
  500. .lottery_record_title {
  501. color: #000000;
  502. height: 80rpx;
  503. font-weight: bold;
  504. font-size: 32rpx;
  505. line-height: 80rpx;
  506. text-align: center;
  507. margin-bottom: 20rpx;
  508. .close_btn {
  509. float: right;
  510. width: 40rpx;
  511. height: 40rpx;
  512. color: #deb887;
  513. font-size: 24rpx;
  514. margin-top: 9rpx;
  515. line-height: 40rpx;
  516. border-radius: 50%;
  517. border: 2rpx solid #deb887;
  518. }
  519. }
  520. .lottery_record_none {
  521. display: block;
  522. height: 200rpx;
  523. color: #deb887;
  524. font-size: 26rpx;
  525. text-align: center;
  526. line-height: 200rpx;
  527. }
  528. .lottery_record_list {
  529. display: block;
  530. height: 500rpx;
  531. .lottery_record_item {
  532. height: 80rpx;
  533. display: block;
  534. font-size: 26rpx;
  535. overflow: hidden;
  536. line-height: 80rpx;
  537. .reward_time {
  538. float: left;
  539. width: 300rpx;
  540. }
  541. .reward_name {
  542. float: left;
  543. width: 200rpx;
  544. }
  545. .reward_state {
  546. float: right;
  547. }
  548. }
  549. }
  550. }
  551. .popup {
  552. overflow: hidden;
  553. .popup_title {
  554. display: block;
  555. overflow: hidden;
  556. margin: 0rpx auto;
  557. font-size: 36rpx;
  558. height: 120rpx;
  559. line-height: 120rpx;
  560. padding: 0rpx 20rpx;
  561. border-bottom: 10rpx solid #f8f8f8;
  562. .to_addr_page {
  563. float: right;
  564. color: #f59a23;
  565. display: block;
  566. height: 120rpx;
  567. line-height: 120rpx;
  568. font-size: 26rpx;
  569. padding: 0rpx 10rpx;
  570. }
  571. }
  572. .addr_list {
  573. width: 730rpx;
  574. display: block;
  575. overflow: hidden;
  576. margin: 0rpx auto;
  577. min-height: 500rpx;
  578. .addr_item {
  579. display: block;
  580. font-size: 24rpx;
  581. overflow: hidden;
  582. line-height: 40rpx;
  583. padding: 15rpx 10rpx;
  584. border-radius: 15rpx;
  585. border-bottom: 2rpx solid #dddddd;
  586. .radio_label {
  587. width: 40rpx;
  588. float: left;
  589. height: 50rpx;
  590. padding-top: 30rpx;
  591. margin-right: 20rpx;
  592. .radio_icon {
  593. float: left;
  594. width: 40rpx;
  595. height: 40rpx;
  596. }
  597. }
  598. .contact_user {
  599. float: left;
  600. width: 640rpx;
  601. display: block;
  602. height: 50rpx;
  603. font-size: 24rpx;
  604. line-height: 50rpx;
  605. .contact_name {
  606. font-size: 26rpx;
  607. font-weight: bold;
  608. margin-right: 16rpx;
  609. }
  610. .contact_default {
  611. color: #f59a23;
  612. font-size: 20rpx;
  613. margin-left: 16rpx;
  614. border: 1rpx solid #f59a23;
  615. }
  616. .contact_shop {
  617. float: right;
  618. font-size: 26rpx;
  619. margin-right: 16rpx;
  620. }
  621. }
  622. .contact_addr {
  623. float: left;
  624. width: 640rpx;
  625. display: block;
  626. font-size: 24rpx;
  627. line-height: 30rpx;
  628. padding: 10rpx 5rpx;
  629. }
  630. }
  631. }
  632. .create_box {
  633. height: 140rpx;
  634. display: block;
  635. .create_addr {
  636. width: 700rpx;
  637. height: 80rpx;
  638. display: block;
  639. color: #ffffff;
  640. font-size: 30rpx;
  641. overflow: hidden;
  642. line-height: 80rpx;
  643. padding: 0rpx 0rpx;
  644. text-align: center;
  645. margin: 0rpx auto;
  646. margin-top: 20rpx;
  647. border-radius: 40rpx;
  648. background-color: #e03519;
  649. }
  650. }
  651. }
  652. </style>