lottery.vue 18 KB

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