lottery.vue 15 KB

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