lottery.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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-143021.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. uni.showModal({
  190. title: "分享成功",
  191. confirmText: "立即答题",
  192. cancelText: "留在此页",
  193. success: (res) => {
  194. if (res.confirm) {
  195. uni.redirectTo({
  196. url: "/pages/activity/index?id=" + this.requestParam.activity_id,
  197. });
  198. }
  199. },
  200. });
  201. });
  202. },
  203. onDone(index) {
  204. // 奖项
  205. let prize = this.prizeList[index];
  206. // 结果
  207. uni.showModal({
  208. title: prize.id == 0 ? "很遗憾" : "恭喜您",
  209. content: (prize.id != 0 ? `获得` : "") + prize.name + (prize.reward_type == 5 ? ",请在中奖记录中填写收货地址" : ""),
  210. showCancel: false,
  211. success: (re) => {
  212. if (re.confirm && prize.reward_type == 5) {
  213. // 显示中奖列表
  214. this.showRecord();
  215. }
  216. },
  217. });
  218. },
  219. onClick() {
  220. // 活动是否开始
  221. if (!this.lotteryInfo.id) {
  222. uni.showToast({
  223. title: "暂无可参与活动",
  224. icon: "none",
  225. });
  226. return;
  227. }
  228. // 活动是否开始
  229. if (this.lotteryInfo.start_time * 1000 > new Date().getTime()) {
  230. uni.showToast({
  231. title: "活动还没开始哦",
  232. icon: "none",
  233. });
  234. return;
  235. }
  236. // 活动是否结束
  237. if (this.lotteryInfo.end_time * 1000 <= new Date().getTime()) {
  238. uni.showToast({
  239. title: "活动已结束了哦",
  240. icon: "none",
  241. });
  242. return;
  243. }
  244. // 次数已用完了
  245. if (this.lotteryInfo.number <= 0) {
  246. uni.showToast({
  247. title: "次数已用完了",
  248. icon: "none",
  249. });
  250. return;
  251. }
  252. // 次数操作
  253. this.lotteryInfo.number = this.lotteryInfo.number - 1;
  254. // 请求列表
  255. this.$http.request("/api/lottery_riddle/get_reward", { lottery_id: this.lotteryInfo.id }).then((re) => {
  256. // 设置非请求中
  257. this.isReqing = false;
  258. // 成功结果
  259. if (re.code == "success") {
  260. // 奖品列表更新
  261. this.prizeList = re.data.reward_list;
  262. // 奖品的索引
  263. return this.$refs.dialer.run(re.data.reward_index);
  264. } else {
  265. uni.showToast({
  266. title: re.msg,
  267. icon: "none",
  268. });
  269. return;
  270. }
  271. });
  272. },
  273. showRule() {
  274. this.$refs.lotteryRule.open("center");
  275. },
  276. closeRule() {
  277. this.$refs.lotteryRule.close();
  278. },
  279. showRecord() {
  280. // 活动是否开始
  281. if (this.lotteryInfo.id) {
  282. // 请求列表
  283. this.$http.request("/api/lottery_riddle_record/get_list", { lottery_id: this.lotteryInfo.id }).then((re) => {
  284. // 设置非请求中
  285. this.isReqing = false;
  286. // 成功结果
  287. if (re.code == "success") {
  288. this.recordList = re.data;
  289. }
  290. });
  291. }
  292. this.$refs.lotteryRecord.open("bottom");
  293. },
  294. closeRecord() {
  295. this.$refs.lotteryRecord.close();
  296. },
  297. openAddr(index) {
  298. // 选择的下标
  299. this.recordIndex = index;
  300. // 地址列表
  301. this.getAddrList(true);
  302. },
  303. // 选择地址
  304. checkedAddrItem(item) {
  305. // 判断数据
  306. this.$http.request("api/lottery_riddle_record/set_addr", { id: this.recordList[this.recordIndex].id, addr_id: item.id }, "post").then((callback) => {
  307. // 获取成功
  308. if (callback.code == "success") {
  309. this.recordList[this.recordIndex].status = 1;
  310. this.recordList[this.recordIndex].state = "进行中";
  311. }
  312. this.$refs.addrPopup.close();
  313. });
  314. },
  315. getAddrList(showPopup = false) {
  316. // 判断数据
  317. this.$http.request("api/custom_addr/get_list").then((callback) => {
  318. // 获取成功
  319. if (callback.code == "success") {
  320. this.addrList = callback.data;
  321. // 如果有的话
  322. if (this.addrList.length) {
  323. // 获取默认的
  324. for (let i in this.addrList) {
  325. // 如果是默认的
  326. if (this.addrList[i].is_default) this.checkedAddr = this.addrList[i];
  327. }
  328. // 如果没有默认的话
  329. if (!this.checkedAddr.id) {
  330. this.checkedAddr = this.addrList[this.addrList.length - 1];
  331. }
  332. }
  333. // 弹出地址层
  334. if (showPopup) this.$refs.addrPopup.open("bottom");
  335. }
  336. });
  337. },
  338. },
  339. };
  340. </script>
  341. <style lang="less">
  342. .lottery_box {
  343. display: block;
  344. width: 750rpx;
  345. height: 1100rpx;
  346. margin: 0 auto;
  347. position: relative;
  348. background: linear-gradient(to bottom, #fc335f 0%, #fb7224 80%, #ffffff 100%);
  349. .share-btn {
  350. width: 80%;
  351. height: 80rpx;
  352. background-color: #f0370e;
  353. color: #fff;
  354. border-radius: 60rpx;
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. padding: 16rpx;
  359. margin-top: 60rpx;
  360. box-sizing: border-box;
  361. }
  362. .lottery_time {
  363. top: 0rpx;
  364. left: 35rpx;
  365. z-index: 1;
  366. width: 700rpx;
  367. color: #ffffff;
  368. display: block;
  369. height: 40rpx;
  370. font-size: 24rpx;
  371. line-height: 40rpx;
  372. text-align: center;
  373. position: absolute;
  374. border-radius: 10rpx;
  375. background-color: rgba(0, 0, 0, 0.15);
  376. }
  377. .lottery_info {
  378. width: 750rpx;
  379. overflow: hidden;
  380. margin: 0rpx auto;
  381. position: relative;
  382. margin-bottom: 40rpx;
  383. .lottery_logo {
  384. float: left;
  385. width: 750rpx;
  386. height: 240rpx;
  387. display: block;
  388. }
  389. .lottery_rule_btn {
  390. top: 50%;
  391. right: 0rpx;
  392. width: 120rpx;
  393. height: 60rpx;
  394. color: #ffffff;
  395. overflow: hidden;
  396. font-size: 24rpx;
  397. text-align: center;
  398. line-height: 60rpx;
  399. position: absolute;
  400. padding: 0rpx 0rpx;
  401. border-top-left-radius: 30rpx;
  402. border-bottom-left-radius: 30rpx;
  403. border-top-right-radius: 0rpx;
  404. border-bottom-right-radius: 0rpx;
  405. background-color: rgba(0, 0, 0, 0.3);
  406. }
  407. .lottery_rule_btn::after {
  408. border: 0rpx solid transparent;
  409. }
  410. }
  411. .record_box {
  412. display: block;
  413. height: 120rpx;
  414. overflow: hidden;
  415. position: relative;
  416. margin-top: 40rpx;
  417. .score_info {
  418. display: block;
  419. overflow: auto;
  420. .custom_score {
  421. height: 60rpx;
  422. font-size: 28rpx;
  423. text-align: center;
  424. line-height: 60rpx;
  425. }
  426. .need_score {
  427. height: 60rpx;
  428. font-size: 32rpx;
  429. text-align: center;
  430. line-height: 60rpx;
  431. }
  432. }
  433. .lottery_record {
  434. top: 0rpx;
  435. right: 0rpx;
  436. width: 120rpx;
  437. height: 120rpx;
  438. overflow: hidden;
  439. text-align: center;
  440. position: absolute;
  441. padding: 0rpx 0rpx;
  442. background-color: transparent;
  443. .lottery_record_img {
  444. width: 60rpx;
  445. height: 60rpx;
  446. display: block;
  447. margin: 0rpx auto;
  448. }
  449. .lottery_record_text {
  450. color: #ffffff;
  451. display: block;
  452. height: 40rpx;
  453. width: 120rpx;
  454. font-size: 24rpx;
  455. line-height: 40rpx;
  456. }
  457. }
  458. .lottery_record::after {
  459. border: none;
  460. }
  461. }
  462. }
  463. .lottery_rule_box {
  464. width: 500rpx;
  465. display: block;
  466. overflow: hidden;
  467. background: #ffffff;
  468. font-size: 26rpx;
  469. margin: 0rpx auto;
  470. line-height: 50rpx;
  471. border-radius: 10rpx;
  472. padding: 0rpx 25rpx;
  473. padding-bottom: 20rpx;
  474. background-color: #fc335f;
  475. .lottery_rule_title {
  476. color: #ffffff;
  477. height: 60rpx;
  478. font-size: 32rpx;
  479. line-height: 60rpx;
  480. text-align: center;
  481. margin-bottom: 10rpx;
  482. .close_btn {
  483. float: right;
  484. width: 40rpx;
  485. height: 40rpx;
  486. font-size: 24rpx;
  487. margin-top: 9rpx;
  488. line-height: 40rpx;
  489. border-radius: 50%;
  490. border: 1rpx solid #ffffff;
  491. }
  492. }
  493. .lottery_rule_info {
  494. display: block;
  495. height: 500rpx;
  496. font-size: 24rpx;
  497. line-height: 40rpx;
  498. border-radius: 10rpx;
  499. padding: 20rpx 20rpx;
  500. box-sizing: border-box;
  501. background-color: #ffffff;
  502. .rich_text {
  503. white-space: break-spaces;
  504. }
  505. }
  506. }
  507. .lottery_record_box {
  508. display: block;
  509. color: #deb887;
  510. height: 700rpx;
  511. padding: 10rpx 25rpx;
  512. background-color: #faebd7;
  513. .lottery_record_title {
  514. color: #000000;
  515. height: 80rpx;
  516. font-weight: bold;
  517. font-size: 32rpx;
  518. line-height: 80rpx;
  519. text-align: center;
  520. margin-bottom: 20rpx;
  521. .close_btn {
  522. float: right;
  523. width: 40rpx;
  524. height: 40rpx;
  525. color: #deb887;
  526. font-size: 24rpx;
  527. margin-top: 9rpx;
  528. line-height: 40rpx;
  529. border-radius: 50%;
  530. border: 2rpx solid #deb887;
  531. }
  532. }
  533. .lottery_record_none {
  534. display: block;
  535. height: 200rpx;
  536. color: #deb887;
  537. font-size: 26rpx;
  538. text-align: center;
  539. line-height: 200rpx;
  540. }
  541. .lottery_record_list {
  542. display: block;
  543. height: 500rpx;
  544. .lottery_record_item {
  545. height: 80rpx;
  546. display: block;
  547. font-size: 26rpx;
  548. overflow: hidden;
  549. line-height: 80rpx;
  550. .reward_time {
  551. float: left;
  552. width: 300rpx;
  553. }
  554. .reward_name {
  555. float: left;
  556. width: 200rpx;
  557. }
  558. .reward_state {
  559. float: right;
  560. }
  561. }
  562. }
  563. }
  564. .popup {
  565. overflow: hidden;
  566. .popup_title {
  567. display: block;
  568. overflow: hidden;
  569. margin: 0rpx auto;
  570. font-size: 36rpx;
  571. height: 120rpx;
  572. line-height: 120rpx;
  573. padding: 0rpx 20rpx;
  574. border-bottom: 10rpx solid #f8f8f8;
  575. .to_addr_page {
  576. float: right;
  577. color: #f59a23;
  578. display: block;
  579. height: 120rpx;
  580. line-height: 120rpx;
  581. font-size: 26rpx;
  582. padding: 0rpx 10rpx;
  583. }
  584. }
  585. .addr_list {
  586. width: 730rpx;
  587. display: block;
  588. overflow: hidden;
  589. margin: 0rpx auto;
  590. min-height: 500rpx;
  591. .addr_item {
  592. display: block;
  593. font-size: 24rpx;
  594. overflow: hidden;
  595. line-height: 40rpx;
  596. padding: 15rpx 10rpx;
  597. border-radius: 15rpx;
  598. border-bottom: 2rpx solid #dddddd;
  599. .radio_label {
  600. width: 40rpx;
  601. float: left;
  602. height: 50rpx;
  603. padding-top: 30rpx;
  604. margin-right: 20rpx;
  605. .radio_icon {
  606. float: left;
  607. width: 40rpx;
  608. height: 40rpx;
  609. }
  610. }
  611. .contact_user {
  612. float: left;
  613. width: 640rpx;
  614. display: block;
  615. height: 50rpx;
  616. font-size: 24rpx;
  617. line-height: 50rpx;
  618. .contact_name {
  619. font-size: 26rpx;
  620. font-weight: bold;
  621. margin-right: 16rpx;
  622. }
  623. .contact_default {
  624. color: #f59a23;
  625. font-size: 20rpx;
  626. margin-left: 16rpx;
  627. border: 1rpx solid #f59a23;
  628. }
  629. .contact_shop {
  630. float: right;
  631. font-size: 26rpx;
  632. margin-right: 16rpx;
  633. }
  634. }
  635. .contact_addr {
  636. float: left;
  637. width: 640rpx;
  638. display: block;
  639. font-size: 24rpx;
  640. line-height: 30rpx;
  641. padding: 10rpx 5rpx;
  642. }
  643. }
  644. }
  645. .create_box {
  646. height: 140rpx;
  647. display: block;
  648. .create_addr {
  649. width: 700rpx;
  650. height: 80rpx;
  651. display: block;
  652. color: #ffffff;
  653. font-size: 30rpx;
  654. overflow: hidden;
  655. line-height: 80rpx;
  656. padding: 0rpx 0rpx;
  657. text-align: center;
  658. margin: 0rpx auto;
  659. margin-top: 20rpx;
  660. border-radius: 40rpx;
  661. background-color: #e03519;
  662. }
  663. }
  664. }
  665. </style>