lottery.vue 18 KB

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