lottery.vue 16 KB

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