lottery.vue 18 KB

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