lottery.vue 15 KB

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