lottery.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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">当前积分:{{ scoreInfo.score }}</view>
  22. <view class="need_score" v-if="lotteryInfo.id">每次抽奖消耗{{ lotteryInfo.need_score }}积分</view>
  23. <view class="need_score" v-if="!lotteryInfo.id">暂无可参与的活动</view>
  24. </view>
  25. <button class="lottery_record" @click="showRecord" v-if="lotteryInfo.id">
  26. <image class="lottery_record_img" src="https://mall.findit.ltd/uploads/images/default/lottery_record.png" mode=""></image>
  27. <text class="lottery_record_text">中奖记录</text>
  28. </button>
  29. </view>
  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 class="radio_icon" :src="item.id == checkedAddr.id ? '../../static/icon/radioed.png' : '../../static/icon/radio.png'"></image>
  65. </view>
  66. <view class="contact_user">
  67. <text class="contact_name">{{ item.contact_name }}</text>
  68. <text class="contact_phone">{{ item.contact_phone }}</text>
  69. <text class="contact_default" v-if="item.is_default">默认</text>
  70. <text class="contact_shop">{{ item.contact_shop }}</text>
  71. </view>
  72. <view class="contact_addr"> {{ item.contact_province }} {{ item.contact_city }} {{ item.contact_area }} {{ item.contact_addr }} </view>
  73. </view>
  74. </view>
  75. <view class="create_box">
  76. <navigator url="/pages/addr/index?notify=addr&type=create" class="create_addr">新建收货地址</navigator>
  77. </view>
  78. </uni-popup>
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. data() {
  84. return {
  85. height: "",
  86. // 奖项列表,
  87. prizeList: [],
  88. // 中奖记录
  89. recordList: [],
  90. // 地址列表
  91. addrList: [],
  92. // 抽奖信息
  93. lotteryInfo: {
  94. id: 0,
  95. name: "",
  96. logo: "",
  97. need_score: "",
  98. start_date: "",
  99. end_date: "",
  100. start_time: "",
  101. end_time: "",
  102. rule: "",
  103. },
  104. // 积分信息
  105. scoreInfo: {
  106. score: 0,
  107. use_score: 0,
  108. wait_score: 0,
  109. },
  110. // 更新积分信息
  111. newScore: {
  112. score: 0,
  113. use_score: 0,
  114. wait_score: 0,
  115. },
  116. recordId: 0,
  117. };
  118. },
  119. onLoad() {
  120. // 窗口信息
  121. var sysinfo = uni.getWindowInfo();
  122. // 获取屏幕可用高度
  123. this.height = "height:" + sysinfo.windowHeight + "px;";
  124. // 监听地址变动
  125. uni.$on("addr_list_change", (data) => {
  126. // 地址列表
  127. this.addrList = data.list;
  128. });
  129. // #ifdef MP-WEIXIN
  130. //分享按钮
  131. uni.showShareMenu({
  132. withShareTicket: true,
  133. menus: ["shareAppMessage", "shareTimeline"],
  134. });
  135. // #endif
  136. },
  137. onShareAppMessage(obj) {
  138. // 获取分享信息
  139. let shareList = getApp().globalData.shareList;
  140. // 获取分享信息
  141. let shareObj = {
  142. title: "学生征订",
  143. path: "/pages/score/lottery",
  144. imageUrl: "",
  145. };
  146. // 循环列表
  147. for (let i in shareList) {
  148. if (shareList[i].pages == "pages/score/lottery") {
  149. shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
  150. shareObj.title = shareList[i].title ? shareList[i].title : shareObj.title;
  151. shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
  152. }
  153. }
  154. // 返回分享信息
  155. return shareObj;
  156. },
  157. onShow() {
  158. // 没有数据的话,或者请求中,不允许刷新
  159. if (this.isReqing) return;
  160. // 登录提示
  161. if (!this.$checkAccess.alterLogin()) return;
  162. // 设置请求中
  163. this.isReqing = true;
  164. // 请求
  165. this.$http.request("api/lottery_score/get_detail").then((re) => {
  166. // 设置非请求中
  167. this.isReqing = false;
  168. // 成功结果
  169. if (re.code == "success") {
  170. this.lotteryInfo = re.data;
  171. this.prizeList = re.data.reward_list;
  172. }
  173. });
  174. // 请求列表
  175. this.$http.request("/api/custom_score/get_info", {}).then((re) => {
  176. // 设置非请求中
  177. this.isReqing = false;
  178. // 成功结果
  179. if (re.code == "success") {
  180. this.scoreInfo = re.data;
  181. this.newScore = re.data;
  182. }
  183. });
  184. },
  185. methods: {
  186. onDone(index) {
  187. // 奖项
  188. let prize = this.prizeList[index];
  189. // 如果是实物
  190. this.scoreInfo = this.newScore;
  191. uni.showModal({
  192. title: prize.id == 0 ? "很遗憾" : "恭喜您",
  193. content: (prize.id != 0 ? `获得` : "") + prize.name + (prize.reward_type == 5 ? ",请在中奖记录中填写收货地址" : ""),
  194. showCancel: false,
  195. success: (re) => {
  196. if (re.confirm && prize.reward_type == 5) {
  197. // 显示中奖列表
  198. this.showRecord();
  199. }
  200. },
  201. });
  202. },
  203. onClick() {
  204. // 活动是否开始
  205. if (!this.lotteryInfo.id) {
  206. uni.showToast({
  207. title: "暂无可参与活动",
  208. icon: "none",
  209. });
  210. return;
  211. }
  212. // 活动是否开始
  213. if (this.lotteryInfo.start_time * 1000 > new Date().getTime()) {
  214. uni.showToast({
  215. title: "活动还没开始哦",
  216. icon: "none",
  217. });
  218. return;
  219. }
  220. // 活动是否结束
  221. if (this.lotteryInfo.end_time * 1000 <= new Date().getTime()) {
  222. uni.showToast({
  223. title: "活动已结束了哦",
  224. icon: "none",
  225. });
  226. return;
  227. }
  228. // 积分不足
  229. if (this.scoreInfo.score < this.lotteryInfo.need_score) {
  230. uni.showToast({
  231. title: "积分不足",
  232. icon: "none",
  233. });
  234. return;
  235. }
  236. // 积分操作
  237. this.scoreInfo.score = this.scoreInfo.score - this.lotteryInfo.need_score;
  238. // 请求列表
  239. this.$http.request("/api/lottery_score/get_reward", { lottery_id: this.lotteryInfo.id }).then((re) => {
  240. // 设置非请求中
  241. this.isReqing = false;
  242. // 成功结果
  243. if (re.code == "success") {
  244. // 奖品列表更新
  245. this.prizeList = re.data.reward_list;
  246. this.newScore = re.data.custom_score;
  247. // 奖品的索引
  248. return this.$refs.dialer.run(re.data.reward_index);
  249. } else {
  250. uni.showToast({
  251. title: re.msg,
  252. icon: "none",
  253. });
  254. // 积分操作
  255. this.scoreInfo.score = this.scoreInfo.score + this.lotteryInfo.need_score;
  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_score_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_score_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. .lottery_time {
  337. top: 0rpx;
  338. left: 35rpx;
  339. z-index: 1;
  340. width: 700rpx;
  341. color: #ffffff;
  342. display: block;
  343. height: 40rpx;
  344. font-size: 24rpx;
  345. line-height: 40rpx;
  346. text-align: center;
  347. position: absolute;
  348. border-radius: 10rpx;
  349. background-color: rgba(0, 0, 0, 0.15);
  350. }
  351. .lottery_info {
  352. width: 750rpx;
  353. overflow: hidden;
  354. margin: 0rpx auto;
  355. position: relative;
  356. margin-bottom: 40rpx;
  357. .lottery_logo {
  358. float: left;
  359. width: 750rpx;
  360. display: block;
  361. }
  362. .lottery_rule_btn {
  363. top: 50%;
  364. right: 0rpx;
  365. width: 120rpx;
  366. height: 60rpx;
  367. color: #ffffff;
  368. overflow: hidden;
  369. font-size: 24rpx;
  370. text-align: center;
  371. line-height: 60rpx;
  372. position: absolute;
  373. padding: 0rpx 0rpx;
  374. border-top-left-radius: 30rpx;
  375. border-bottom-left-radius: 30rpx;
  376. border-top-right-radius: 0rpx;
  377. border-bottom-right-radius: 0rpx;
  378. background-color: rgba(0, 0, 0, 0.3);
  379. }
  380. .lottery_rule_btn::after {
  381. border: 0rpx solid transparent;
  382. }
  383. }
  384. .record_box {
  385. display: block;
  386. height: 120rpx;
  387. overflow: hidden;
  388. position: relative;
  389. margin-top: 40rpx;
  390. .score_info {
  391. display: block;
  392. overflow: auto;
  393. .custom_score {
  394. height: 60rpx;
  395. font-size: 28rpx;
  396. text-align: center;
  397. line-height: 60rpx;
  398. }
  399. .need_score {
  400. height: 60rpx;
  401. font-size: 32rpx;
  402. text-align: center;
  403. line-height: 60rpx;
  404. }
  405. }
  406. .lottery_record {
  407. top: 0rpx;
  408. right: 0rpx;
  409. width: 120rpx;
  410. height: 120rpx;
  411. overflow: hidden;
  412. text-align: center;
  413. position: absolute;
  414. padding: 0rpx 0rpx;
  415. background-color: transparent;
  416. .lottery_record_img {
  417. width: 60rpx;
  418. height: 60rpx;
  419. display: block;
  420. margin: 0rpx auto;
  421. }
  422. .lottery_record_text {
  423. color: #ffffff;
  424. display: block;
  425. height: 40rpx;
  426. width: 120rpx;
  427. font-size: 24rpx;
  428. line-height: 40rpx;
  429. }
  430. }
  431. .lottery_record::after {
  432. border: none;
  433. }
  434. }
  435. }
  436. .lottery_rule_box {
  437. width: 500rpx;
  438. display: block;
  439. overflow: hidden;
  440. background: #ffffff;
  441. font-size: 26rpx;
  442. margin: 0rpx auto;
  443. line-height: 50rpx;
  444. border-radius: 10rpx;
  445. padding: 0rpx 25rpx;
  446. padding-bottom: 20rpx;
  447. background-color: #fc335f;
  448. .lottery_rule_title {
  449. color: #ffffff;
  450. height: 60rpx;
  451. font-size: 32rpx;
  452. line-height: 60rpx;
  453. text-align: center;
  454. margin-bottom: 10rpx;
  455. .close_btn {
  456. float: right;
  457. width: 40rpx;
  458. height: 40rpx;
  459. font-size: 24rpx;
  460. margin-top: 9rpx;
  461. line-height: 40rpx;
  462. border-radius: 50%;
  463. border: 1rpx solid #ffffff;
  464. }
  465. }
  466. .lottery_rule_info {
  467. display: block;
  468. height: 500rpx;
  469. font-size: 24rpx;
  470. line-height: 40rpx;
  471. border-radius: 10rpx;
  472. padding: 20rpx 20rpx;
  473. box-sizing: border-box;
  474. background-color: #ffffff;
  475. .rich_text {
  476. white-space: break-spaces;
  477. }
  478. }
  479. }
  480. .lottery_record_box {
  481. display: block;
  482. color: #deb887;
  483. height: 700rpx;
  484. padding: 10rpx 25rpx;
  485. background-color: #faebd7;
  486. .lottery_record_title {
  487. color: #000000;
  488. height: 80rpx;
  489. font-weight: bold;
  490. font-size: 32rpx;
  491. line-height: 80rpx;
  492. text-align: center;
  493. margin-bottom: 20rpx;
  494. .close_btn {
  495. float: right;
  496. width: 40rpx;
  497. height: 40rpx;
  498. color: #deb887;
  499. font-size: 24rpx;
  500. margin-top: 9rpx;
  501. line-height: 40rpx;
  502. border-radius: 50%;
  503. border: 2rpx solid #deb887;
  504. }
  505. }
  506. .lottery_record_none {
  507. display: block;
  508. height: 200rpx;
  509. color: #deb887;
  510. font-size: 26rpx;
  511. text-align: center;
  512. line-height: 200rpx;
  513. }
  514. .lottery_record_list {
  515. display: block;
  516. height: 500rpx;
  517. .lottery_record_item {
  518. height: 80rpx;
  519. display: block;
  520. font-size: 26rpx;
  521. overflow: hidden;
  522. line-height: 80rpx;
  523. .reward_time {
  524. float: left;
  525. width: 300rpx;
  526. }
  527. .reward_name {
  528. float: left;
  529. width: 200rpx;
  530. }
  531. .reward_state {
  532. float: right;
  533. }
  534. }
  535. }
  536. }
  537. .popup {
  538. overflow: hidden;
  539. .popup_title {
  540. display: block;
  541. overflow: hidden;
  542. margin: 0rpx auto;
  543. font-size: 36rpx;
  544. height: 120rpx;
  545. line-height: 120rpx;
  546. padding: 0rpx 20rpx;
  547. border-bottom: 10rpx solid #f8f8f8;
  548. .to_addr_page {
  549. float: right;
  550. color: #f59a23;
  551. display: block;
  552. height: 120rpx;
  553. line-height: 120rpx;
  554. font-size: 26rpx;
  555. padding: 0rpx 10rpx;
  556. }
  557. }
  558. .addr_list {
  559. width: 730rpx;
  560. display: block;
  561. overflow: hidden;
  562. margin: 0rpx auto;
  563. min-height: 500rpx;
  564. .addr_item {
  565. display: block;
  566. font-size: 24rpx;
  567. overflow: hidden;
  568. line-height: 40rpx;
  569. padding: 15rpx 10rpx;
  570. border-radius: 15rpx;
  571. border-bottom: 2rpx solid #dddddd;
  572. .radio_label {
  573. width: 40rpx;
  574. float: left;
  575. height: 50rpx;
  576. padding-top: 30rpx;
  577. margin-right: 20rpx;
  578. .radio_icon {
  579. float: left;
  580. width: 40rpx;
  581. height: 40rpx;
  582. }
  583. }
  584. .contact_user {
  585. float: left;
  586. width: 640rpx;
  587. display: block;
  588. height: 50rpx;
  589. font-size: 24rpx;
  590. line-height: 50rpx;
  591. .contact_name {
  592. font-size: 26rpx;
  593. font-weight: bold;
  594. margin-right: 16rpx;
  595. }
  596. .contact_default {
  597. color: #f59a23;
  598. font-size: 20rpx;
  599. margin-left: 16rpx;
  600. border: 1rpx solid #f59a23;
  601. }
  602. .contact_shop {
  603. float: right;
  604. font-size: 26rpx;
  605. margin-right: 16rpx;
  606. }
  607. }
  608. .contact_addr {
  609. float: left;
  610. width: 640rpx;
  611. display: block;
  612. font-size: 24rpx;
  613. line-height: 30rpx;
  614. padding: 10rpx 5rpx;
  615. }
  616. }
  617. }
  618. .create_box {
  619. height: 140rpx;
  620. display: block;
  621. .create_addr {
  622. width: 700rpx;
  623. height: 80rpx;
  624. display: block;
  625. color: #ffffff;
  626. font-size: 30rpx;
  627. overflow: hidden;
  628. line-height: 80rpx;
  629. padding: 0rpx 0rpx;
  630. text-align: center;
  631. margin: 0rpx auto;
  632. margin-top: 20rpx;
  633. border-radius: 40rpx;
  634. background-color: #e03519;
  635. }
  636. }
  637. }
  638. </style>