lottery.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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
  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. need_score: "",
  101. start_date: "",
  102. end_date: "",
  103. start_time: "",
  104. end_time: "",
  105. rule: "",
  106. },
  107. // 积分信息
  108. scoreInfo: {
  109. score: 0,
  110. use_score: 0,
  111. wait_score: 0,
  112. },
  113. // 更新积分信息
  114. newScore: {
  115. score: 0,
  116. use_score: 0,
  117. wait_score: 0,
  118. },
  119. recordId: 0,
  120. };
  121. },
  122. onLoad() {
  123. // 窗口信息
  124. var sysinfo = uni.getWindowInfo();
  125. // 获取屏幕可用高度
  126. this.height = "height:" + sysinfo.windowHeight + "px;";
  127. // 监听地址变动
  128. uni.$on("addr_list_change", (data) => {
  129. // 地址列表
  130. this.addrList = data.list;
  131. });
  132. // #ifdef MP-WEIXIN
  133. //分享按钮
  134. uni.showShareMenu({
  135. withShareTicket: true,
  136. menus: ["shareAppMessage", "shareTimeline"],
  137. });
  138. // #endif
  139. },
  140. onShareAppMessage(obj) {
  141. // 获取分享信息
  142. let shareList = getApp().globalData.shareList;
  143. // 获取分享信息
  144. let shareObj = {
  145. title: "999智控终端平台\n药优惠 得积分 兑豪礼",
  146. path: "/pages/score/lottery",
  147. imageUrl: "",
  148. };
  149. // 循环列表
  150. for (let i in shareList) {
  151. if (shareList[i].pages == "pages/score/lottery") {
  152. shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
  153. shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
  154. shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
  155. }
  156. }
  157. // 返回分享信息
  158. return shareObj;
  159. },
  160. onShow() {
  161. // 没有数据的话,或者请求中,不允许刷新
  162. if (this.isReqing) return;
  163. // 登录提示
  164. if (!this.$checkAccess.alterLogin()) return;
  165. // 设置请求中
  166. this.isReqing = true;
  167. // 请求
  168. this.$http.request("api/lottery_score/get_detail").then((re) => {
  169. // 设置非请求中
  170. this.isReqing = false;
  171. // 成功结果
  172. if (re.code == "success") {
  173. this.lotteryInfo = re.data;
  174. this.prizeList = re.data.reward_list;
  175. }
  176. });
  177. // 请求列表
  178. this.$http.request("/api/custom_score/get_info", {}).then((re) => {
  179. // 设置非请求中
  180. this.isReqing = false;
  181. // 成功结果
  182. if (re.code == "success") {
  183. this.scoreInfo = re.data;
  184. this.newScore = re.data;
  185. }
  186. });
  187. },
  188. methods: {
  189. onDone(index) {
  190. // 奖项
  191. let prize = this.prizeList[index];
  192. // 如果是实物
  193. this.scoreInfo = this.newScore;
  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.scoreInfo.score < this.lotteryInfo.need_score) {
  233. uni.showToast({
  234. title: "积分不足",
  235. icon: "none",
  236. });
  237. return;
  238. }
  239. // 积分操作
  240. this.scoreInfo.score = this.scoreInfo.score - this.lotteryInfo.need_score;
  241. // 请求列表
  242. this.$http.request("/api/lottery_score/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. this.newScore = re.data.custom_score;
  250. // 奖品的索引
  251. return this.$refs.dialer.run(re.data.reward_index);
  252. } else {
  253. uni.showToast({
  254. title: re.msg,
  255. icon: "none",
  256. });
  257. // 积分操作
  258. this.scoreInfo.score = this.scoreInfo.score + this.lotteryInfo.need_score;
  259. return;
  260. }
  261. });
  262. },
  263. showRule() {
  264. this.$refs.lotteryRule.open("center");
  265. },
  266. closeRule() {
  267. this.$refs.lotteryRule.close();
  268. },
  269. showRecord() {
  270. // 活动是否开始
  271. if (this.lotteryInfo.id) {
  272. // 请求列表
  273. this.$http.request("/api/lottery_score_record/get_list", { lottery_id: this.lotteryInfo.id }).then((re) => {
  274. // 设置非请求中
  275. this.isReqing = false;
  276. // 成功结果
  277. if (re.code == "success") {
  278. this.recordList = re.data;
  279. }
  280. });
  281. }
  282. this.$refs.lotteryRecord.open("bottom");
  283. },
  284. closeRecord() {
  285. this.$refs.lotteryRecord.close();
  286. },
  287. openAddr(index) {
  288. // 选择的下标
  289. this.recordIndex = index;
  290. // 地址列表
  291. this.getAddrList(true);
  292. },
  293. // 选择地址
  294. checkedAddrItem(item) {
  295. // 判断数据
  296. this.$http.request("api/lottery_score_record/set_addr", { id: this.recordList[this.recordIndex].id, addr_id: item.id }, "post").then((callback) => {
  297. // 获取成功
  298. if (callback.code == "success") {
  299. this.recordList[this.recordIndex].status = 1;
  300. this.recordList[this.recordIndex].state = "进行中";
  301. }
  302. this.$refs.addrPopup.close();
  303. });
  304. },
  305. getAddrList(showPopup = false) {
  306. // 判断数据
  307. this.$http.request("api/custom_addr/get_list").then((callback) => {
  308. // 获取成功
  309. if (callback.code == "success") {
  310. this.addrList = callback.data;
  311. // 如果有的话
  312. if (this.addrList.length) {
  313. // 获取默认的
  314. for (let i in this.addrList) {
  315. // 如果是默认的
  316. if (this.addrList[i].is_default) this.checkedAddr = this.addrList[i];
  317. }
  318. // 如果没有默认的话
  319. if (!this.checkedAddr.id) {
  320. this.checkedAddr = this.addrList[this.addrList.length - 1];
  321. }
  322. }
  323. // 弹出地址层
  324. if (showPopup) this.$refs.addrPopup.open("bottom");
  325. }
  326. });
  327. },
  328. },
  329. };
  330. </script>
  331. <style lang="less">
  332. .lottery_box {
  333. display: block;
  334. width: 750rpx;
  335. height: 1100rpx;
  336. margin: 0 auto;
  337. position: relative;
  338. background: linear-gradient(to bottom, #fc335f 0%, #fb7224 80%, #ffffff 100%);
  339. .lottery_time {
  340. top: 0rpx;
  341. left: 35rpx;
  342. z-index: 1;
  343. width: 700rpx;
  344. color: #ffffff;
  345. display: block;
  346. height: 40rpx;
  347. font-size: 24rpx;
  348. line-height: 40rpx;
  349. text-align: center;
  350. position: absolute;
  351. border-radius: 10rpx;
  352. background-color: rgba(0, 0, 0, 0.15);
  353. }
  354. .lottery_info {
  355. width: 750rpx;
  356. overflow: hidden;
  357. margin: 0rpx auto;
  358. position: relative;
  359. margin-bottom: 40rpx;
  360. .lottery_logo {
  361. float: left;
  362. width: 750rpx;
  363. display: block;
  364. }
  365. .lottery_rule_btn {
  366. top: 50%;
  367. right: 0rpx;
  368. width: 120rpx;
  369. height: 60rpx;
  370. color: #ffffff;
  371. overflow: hidden;
  372. font-size: 24rpx;
  373. text-align: center;
  374. line-height: 60rpx;
  375. position: absolute;
  376. padding: 0rpx 0rpx;
  377. border-top-left-radius: 30rpx;
  378. border-bottom-left-radius: 30rpx;
  379. border-top-right-radius: 0rpx;
  380. border-bottom-right-radius: 0rpx;
  381. background-color: rgba(0, 0, 0, 0.3);
  382. }
  383. .lottery_rule_btn::after {
  384. border: 0rpx solid transparent;
  385. }
  386. }
  387. .record_box {
  388. display: block;
  389. height: 120rpx;
  390. overflow: hidden;
  391. position: relative;
  392. margin-top: 40rpx;
  393. .score_info {
  394. display: block;
  395. overflow: auto;
  396. .custom_score {
  397. height: 60rpx;
  398. font-size: 28rpx;
  399. text-align: center;
  400. line-height: 60rpx;
  401. }
  402. .need_score {
  403. height: 60rpx;
  404. font-size: 32rpx;
  405. text-align: center;
  406. line-height: 60rpx;
  407. }
  408. }
  409. .lottery_record {
  410. top: 0rpx;
  411. right: 0rpx;
  412. width: 120rpx;
  413. height: 120rpx;
  414. overflow: hidden;
  415. text-align: center;
  416. position: absolute;
  417. padding: 0rpx 0rpx;
  418. background-color: transparent;
  419. .lottery_record_img {
  420. width: 60rpx;
  421. height: 60rpx;
  422. display: block;
  423. margin: 0rpx auto;
  424. }
  425. .lottery_record_text {
  426. color: #ffffff;
  427. display: block;
  428. height: 40rpx;
  429. width: 120rpx;
  430. font-size: 24rpx;
  431. line-height: 40rpx;
  432. }
  433. }
  434. .lottery_record::after {
  435. border: none;
  436. }
  437. }
  438. }
  439. .lottery_rule_box {
  440. width: 500rpx;
  441. display: block;
  442. overflow: hidden;
  443. background: #ffffff;
  444. font-size: 26rpx;
  445. margin: 0rpx auto;
  446. line-height: 50rpx;
  447. border-radius: 10rpx;
  448. padding: 0rpx 25rpx;
  449. padding-bottom: 20rpx;
  450. background-color: #fc335f;
  451. .lottery_rule_title {
  452. color: #ffffff;
  453. height: 60rpx;
  454. font-size: 32rpx;
  455. line-height: 60rpx;
  456. text-align: center;
  457. margin-bottom: 10rpx;
  458. .close_btn {
  459. float: right;
  460. width: 40rpx;
  461. height: 40rpx;
  462. font-size: 24rpx;
  463. margin-top: 9rpx;
  464. line-height: 40rpx;
  465. border-radius: 50%;
  466. border: 1rpx solid #ffffff;
  467. }
  468. }
  469. .lottery_rule_info {
  470. display: block;
  471. height: 500rpx;
  472. font-size: 24rpx;
  473. line-height: 40rpx;
  474. border-radius: 10rpx;
  475. padding: 20rpx 20rpx;
  476. box-sizing: border-box;
  477. background-color: #ffffff;
  478. .rich_text {
  479. white-space: break-spaces;
  480. }
  481. }
  482. }
  483. .lottery_record_box {
  484. display: block;
  485. color: #deb887;
  486. height: 700rpx;
  487. padding: 10rpx 25rpx;
  488. background-color: #faebd7;
  489. .lottery_record_title {
  490. color: #000000;
  491. height: 80rpx;
  492. font-weight: bold;
  493. font-size: 32rpx;
  494. line-height: 80rpx;
  495. text-align: center;
  496. margin-bottom: 20rpx;
  497. .close_btn {
  498. float: right;
  499. width: 40rpx;
  500. height: 40rpx;
  501. color: #deb887;
  502. font-size: 24rpx;
  503. margin-top: 9rpx;
  504. line-height: 40rpx;
  505. border-radius: 50%;
  506. border: 2rpx solid #deb887;
  507. }
  508. }
  509. .lottery_record_none {
  510. display: block;
  511. height: 200rpx;
  512. color: #deb887;
  513. font-size: 26rpx;
  514. text-align: center;
  515. line-height: 200rpx;
  516. }
  517. .lottery_record_list {
  518. display: block;
  519. height: 500rpx;
  520. .lottery_record_item {
  521. height: 80rpx;
  522. display: block;
  523. font-size: 26rpx;
  524. overflow: hidden;
  525. line-height: 80rpx;
  526. .reward_time {
  527. float: left;
  528. width: 300rpx;
  529. }
  530. .reward_name {
  531. float: left;
  532. width: 200rpx;
  533. }
  534. .reward_state {
  535. float: right;
  536. }
  537. }
  538. }
  539. }
  540. .popup {
  541. overflow: hidden;
  542. .popup_title {
  543. display: block;
  544. overflow: hidden;
  545. margin: 0rpx auto;
  546. font-size: 36rpx;
  547. height: 120rpx;
  548. line-height: 120rpx;
  549. padding: 0rpx 20rpx;
  550. border-bottom: 10rpx solid #f8f8f8;
  551. .to_addr_page {
  552. float: right;
  553. color: #f59a23;
  554. display: block;
  555. height: 120rpx;
  556. line-height: 120rpx;
  557. font-size: 26rpx;
  558. padding: 0rpx 10rpx;
  559. }
  560. }
  561. .addr_list {
  562. width: 730rpx;
  563. display: block;
  564. overflow: hidden;
  565. margin: 0rpx auto;
  566. min-height: 500rpx;
  567. .addr_item {
  568. display: block;
  569. font-size: 24rpx;
  570. overflow: hidden;
  571. line-height: 40rpx;
  572. padding: 15rpx 10rpx;
  573. border-radius: 15rpx;
  574. border-bottom: 2rpx solid #dddddd;
  575. .radio_label {
  576. width: 40rpx;
  577. float: left;
  578. height: 50rpx;
  579. padding-top: 30rpx;
  580. margin-right: 20rpx;
  581. .radio_icon {
  582. float: left;
  583. width: 40rpx;
  584. height: 40rpx;
  585. }
  586. }
  587. .contact_user {
  588. float: left;
  589. width: 640rpx;
  590. display: block;
  591. height: 50rpx;
  592. font-size: 24rpx;
  593. line-height: 50rpx;
  594. .contact_name {
  595. font-size: 26rpx;
  596. font-weight: bold;
  597. margin-right: 16rpx;
  598. }
  599. .contact_default {
  600. color: #f59a23;
  601. font-size: 20rpx;
  602. margin-left: 16rpx;
  603. border: 1rpx solid #f59a23;
  604. }
  605. .contact_shop {
  606. float: right;
  607. font-size: 26rpx;
  608. margin-right: 16rpx;
  609. }
  610. }
  611. .contact_addr {
  612. float: left;
  613. width: 640rpx;
  614. display: block;
  615. font-size: 24rpx;
  616. line-height: 30rpx;
  617. padding: 10rpx 5rpx;
  618. }
  619. }
  620. }
  621. .create_box {
  622. height: 140rpx;
  623. display: block;
  624. .create_addr {
  625. width: 700rpx;
  626. height: 80rpx;
  627. display: block;
  628. color: #ffffff;
  629. font-size: 30rpx;
  630. overflow: hidden;
  631. line-height: 80rpx;
  632. padding: 0rpx 0rpx;
  633. text-align: center;
  634. margin: 0rpx auto;
  635. margin-top: 20rpx;
  636. border-radius: 40rpx;
  637. background-color: #e03519;
  638. }
  639. }
  640. }
  641. </style>