lottery.vue 15 KB

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