index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <template>
  2. <view class="goods-lucky">
  3. <!-- 转盘 -->
  4. <view class="spinning" :style="{backgroundImage:'url('+bigWheelConfig.big_wheel_bg+')'}">
  5. <view class="spinning-title" style="opacity: 0;">
  6. <text>{{drawInfo.draw_template.name?drawInfo.draw_template.name:"幸运大轮盘"}}</text>
  7. </view>
  8. <view style="width:0px;height:0px;"><image src="http://t9.9026.com/imgs/step01.png" style="width: 285rpx;height: 341rpx;transform: translate(232rpx, 167rpx);"/></view>
  9. <!-- <q-turntable isRenderImage ref="turntable" :areaNumber='9' @start="turntableStart" @success="turntableSuccess">
  10. </q-turntable> -->
  11. <q-turntable ref="turntable" :isValid="drawInfo.id && isValid" @start="turntableStart" :big_wheel_disc="bigWheelConfig.big_wheel_disc" :big_wheel_button="bigWheelConfig.big_wheel_button"/>
  12. </view>
  13. <view style="background-color: #f9f9f9; padding-bottom: 136rpx;">
  14. <!-- 产品信息 -->
  15. <view class="produce">
  16. <view class="produce-title">奖品信息</view>
  17. <view class="produce-main" v-for="(item,index) in drawInfo.draw_template.draw_config" :key="item.id">
  18. <image style="width: 132rpx;height: 132rpx;border-radius: 10rpx;" :src="item.product.img_urls?item.product.img_urls:item.prize_img"
  19. mode=""></image>
  20. <view class="produce-main-text">
  21. <text class="produce-main-text-top">{{item.name}}</text>
  22. <text class="produce-main-text-bom">{{item.product.name ? item.product.name : (item.integral?item.integral+"积分":"")}}</text>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 活动规则 -->
  27. <view class="rule">
  28. <view class="rule-title">
  29. 活动规则
  30. </view>
  31. <view class="rule-content">
  32. <view class="introduce-top">
  33. <text class="introduce-top-rule1"></text>
  34. <text style="margin: 0 8rpx;">活动规则</text>
  35. <text class="introduce-top-rule2"></text>
  36. </view>
  37. <view class="introduce-text">
  38. <u-parse
  39. :content="drawInfo.draw_template.rule"
  40. ></u-parse>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 我的奖品 -->
  45. <view class="prize">
  46. <view class="prize-title">
  47. 我的奖品
  48. </view>
  49. <view class="prize-main" v-for="item in drawRecord" :key="item.id">
  50. <view class="prize-main-left">
  51. <text class="prize-main-left-top">{{item.remark}}</text>
  52. <text class="prize-main-left-bom">{{item.created_at}}</text>
  53. </view>
  54. <view v-if="!item.integral" :class="item.status==1 ? 'prize-main-rightSelect' : 'prize-main-right' ">
  55. <text v-if="item.status==1" @click="goExchangePhy(item.id)">立即兑换</text>
  56. <text v-else-if="item.status==2">已兑换</text>
  57. <text v-else-if="item.status==3">已过期</text>
  58. <text v-else-if="item.status==4">未开始</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 中奖弹窗 -->
  64. <uni-popup ref="codePurchase" type="center">
  65. <view class="code-purchase">
  66. <view class="img">
  67. <image style="width: 80rpx;height: 82rpx" src="/static/icon/gift01.png"></image>
  68. <view class="text">
  69. <text>恭喜您抽中了<text>{{drawResultProduct.name}}</text></text>
  70. <text>{{drawResult.name?drawResult.name:drawResultProduct.integral+'积分'}}</text>
  71. <text v-if="drawResult.name">请尽快去奖品中心兑奖</text>
  72. </view>
  73. </view>
  74. <view class="btn">
  75. <view class="cancel" @click="dialogClose"><text>待会儿</text></view>
  76. <view class="download" @click="dialogConfirm"><text>去兑奖</text></view>
  77. </view>
  78. </view>
  79. </uni-popup>
  80. <!-- 未中奖弹窗 -->
  81. <uni-popup ref="codePurchaseNone" type="center">
  82. <view class="code-purchase">
  83. <view class="img">
  84. <image style="width: 108rpx;height: 68rpx" src="/static/icon/gift02.png"></image>
  85. <view class="text">
  86. <text>很遗憾您没有抽中奖品</text>
  87. <text>下次再来哟</text>
  88. </view>
  89. </view>
  90. <view class="btn">
  91. <view class="know" @click="dialogClose"><text>知道了</text></view>
  92. </view>
  93. </view>
  94. </uni-popup>
  95. <uni-popup ref="dialogError" type="center">
  96. <view style="
  97. width: 600rpx;
  98. max-width: 100%;
  99. text-align: center;
  100. background: #fff;
  101. height: 300rpx;
  102. border-radius: 20rpx
  103. ">
  104. <view style="
  105. height: 70%;
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  110. ">
  111. {{error.info}}
  112. </view>
  113. <navigator style="height: 30%;display: flex;justify-content: center;align-items: center;" open-type="exit" target="miniProgram">退出</navigator>
  114. </view>
  115. </uni-popup>
  116. </view>
  117. </template>
  118. <script>
  119. import QTurntable from '@/components/q-turntable'
  120. export default {
  121. components: {
  122. QTurntable
  123. },
  124. data() {
  125. return {
  126. error:{
  127. info: ""
  128. },
  129. big_wheel:{},
  130. //中奖等级
  131. prizeLevel:'',
  132. isexchange: true,
  133. backImageUrl: 'http://t9.9026.com/imgs/banner02.png',
  134. award: 1,
  135. // 顺时针对应每个奖项
  136. drawInfo:{
  137. draw_no: ''
  138. },
  139. drawRecord:[],
  140. drawResult:{},
  141. drawResultProduct: {},
  142. bigWheelConfig:{},
  143. isValid: true
  144. }
  145. },
  146. onLoad(params){
  147. const {draw_no} = params
  148. this.drawInfo.draw_no = draw_no;
  149. this.getBackgroundConfig()
  150. },
  151. onShow(){
  152. if(!this.$store.getters.userInfo){
  153. uni.navigateTo({
  154. url: '/pages/login/login'
  155. })
  156. return;
  157. }
  158. // this.judageIsDraw(); //判断是否有权限访问
  159. this.getDrawInfo(); //获取抽奖信息
  160. this.getDrawRecord(); //获取获奖记录
  161. },
  162. computed:{
  163. recordMsg:(status)=>{
  164. const di = ['未中奖','未兑换','已兑换'];
  165. return di[status];
  166. },
  167. },
  168. methods: {
  169. getBackgroundConfig(){
  170. this.$api.document.allSet().then(res => {
  171. this.bigWheelConfig = res.data.big_wheel.value
  172. })
  173. },
  174. judageIsDraw(){
  175. if(!this.drawInfo.draw_no){
  176. uni.showToast({
  177. icon: 'error',
  178. title: "暂无权限",
  179. success:()=>{
  180. uni.reLaunch({
  181. url:'/pages/index/index'
  182. })
  183. }
  184. })
  185. }
  186. },
  187. getDrawInfo(){
  188. if(!this.drawInfo.draw_no){
  189. uni.showToast({
  190. icon: 'error',
  191. title: "暂无权限"
  192. })
  193. return;
  194. }
  195. this.$api.draw.drawInfo({
  196. draw_no: this.drawInfo.draw_no
  197. }).then(res=>{
  198. if(res.code == 0){
  199. this.drawInfo = res.data;
  200. // this.$refs.turntable.init(this.drawInfo.draw_template.draw_config);
  201. if(this.drawInfo.draw_template.draw_config && this.drawInfo.draw_template.draw_config.length > 3){
  202. let tres = true;
  203. this.drawInfo.draw_template.draw_config.forEach(item => {
  204. if(!item.reward_odds){
  205. tres = false;
  206. }
  207. })
  208. if(tres){
  209. this.$refs.turntable.init(this.drawInfo.draw_template.draw_config);
  210. }else{
  211. this.error.info = "活动未开启";
  212. this.$refs.dialogError.open()
  213. }
  214. }else{
  215. this.error.info = "活动未开放";
  216. this.$refs.dialogError.open()
  217. }
  218. }else{
  219. this.error.info = res.msg ? res.msg : "暂无权限";
  220. this.$refs.dialogError.open()
  221. }
  222. }).catch(err=>{
  223. // uni.showToast({
  224. // icon: 'error',
  225. // title: "网络繁忙"
  226. // })
  227. this.error.info = "网络繁忙";
  228. this.$refs.dialogError.open()
  229. })
  230. },
  231. getDrawRecord(page = 1){
  232. if(page == 1){
  233. this.drawRecord = []
  234. }
  235. this.$api.draw.drawRecord({
  236. page:page
  237. }).then(res=>{
  238. if(res.code == 0){
  239. res.data.data.forEach(item => {
  240. if(item.source == 2 && (item.integral>0 || item.product_id>0)){
  241. this.drawRecord.push(item);
  242. }
  243. })
  244. if(res.data.length >= 15){
  245. this.getDrawRecord(page + 1);
  246. }
  247. }
  248. })
  249. },
  250. //中奖去兑换按钮
  251. dialogConfirm() {
  252. this.$utils.jump({
  253. jump_type: 4,
  254. jump_config: '/pages/my/prize/prize'
  255. })
  256. },
  257. //中奖待会按钮
  258. dialogClose() {
  259. this.drawResult = {};
  260. this.$refs.codePurchaseNone.close();
  261. this.$refs.codePurchase.close();
  262. setTimeout(()=>{
  263. this.drawResult = {};
  264. this.drawResultProduct = {};
  265. this.$refs.turntable.reset();
  266. }, 500)
  267. },
  268. // 用户点击开始抽奖
  269. turntableStart() {
  270. // if(this.isDrawing) return;
  271. // this.isDrawing = true
  272. // let index = Math.floor(Math.random() * 6 + 1) //前端随机数,这里应该后台返回中奖结果
  273. // // this.award = index
  274. // this.award = 2
  275. // this.$refs.turntable.begin(this.award);
  276. this.$api.draw.luckyDraw({
  277. draw_no: this.drawInfo.draw_no,
  278. }).then(res => {
  279. if(res.code != 0 || !res.data){
  280. this.isValid = false;
  281. uni.showToast({
  282. icon: 'error',
  283. title: res.msg?res.msg:"网络繁忙",
  284. })
  285. this.$refs.turntable.end(0).then(_=>{
  286. this.$refs.turntable.reset();
  287. });
  288. return;
  289. }
  290. this.drawResult = res.data;
  291. const draw_config = this.drawInfo.draw_template.draw_config;
  292. for(let i=0;i<draw_config.length;i++){
  293. if(draw_config[i].id == this.drawResult.draw_config_id){
  294. this.drawResultProduct = draw_config[i];
  295. setTimeout(()=>{
  296. this.$refs.turntable.end(i).then(_=>{
  297. if(this.drawResultProduct.integral<=0 && !this.drawResultProduct.product){
  298. this.$refs.codePurchaseNone.open()
  299. }else{
  300. this.$refs.codePurchase.open()
  301. }
  302. });
  303. if(this.drawResult.draw_type){
  304. this.getDrawRecord(1)
  305. }
  306. }, 5000)
  307. break;
  308. }
  309. }
  310. }).catch(err => {
  311. uni.showToast({
  312. icon: 'none',
  313. title: res.msg?res.msg:"网络繁忙",
  314. })
  315. this.$refs.turntable.end(0).then(_=>{
  316. this.$refs.turntable.reset();
  317. });
  318. });
  319. },
  320. // 抽奖完成后操作
  321. turntableSuccess() {
  322. let timer = setInterval(()=>{
  323. if(this.isDrawing){
  324. return;
  325. }
  326. if(this.drawResult.status == 1){
  327. this.$refs.codePurchase.open()
  328. }else{
  329. this.$refs.codePurchaseNone.open()
  330. }
  331. clearInterval(timer);
  332. }, 50)
  333. // const index = this.award - 1;
  334. // console.log('bind:success', this.awardList[index]);
  335. // if(this.awardList[index].title == '谢谢参与'){
  336. // this.$refs.codePurchaseNone.open()
  337. // }else{
  338. // let o = this.awardList[index].title
  339. // console.log(this.awardList[index].title);
  340. // this.prizeLevel = o
  341. // this.$refs.codePurchase.open()
  342. // }
  343. // uni.showToast({
  344. // title: `恭喜你获得${this.awardList[index].title}`,
  345. // icon: 'none'
  346. // });
  347. },
  348. goExchangePhy(id){
  349. uni.navigateTo({
  350. url: `/pages/my/prize/exchangePrize?id=${id}&isPhy=1`
  351. })
  352. }
  353. }
  354. }
  355. </script>
  356. <style lang="scss" scoped>
  357. $pageColor:#F9F9F9;
  358. $bgColor:#FFFFFF;
  359. @mixin flexlayout {
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. }
  364. page {
  365. height: 100% !important;
  366. background: #F9F9F9 !important;
  367. }
  368. .goods-lucky {
  369. height: 100%;
  370. background: #F9F9F9;
  371. }
  372. .code-purchase {
  373. width: 620rpx;
  374. // height: 357rpx;
  375. background: #fff;
  376. border-radius: 20rpx;
  377. padding-top: 44rpx;
  378. box-sizing: border-box;
  379. .img {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. justify-content: center;
  384. }
  385. .text{
  386. margin-top: 26rpx;
  387. display: flex;
  388. flex-direction: column;
  389. align-items: center;
  390. justify-content: center;
  391. font-weight: 400;
  392. color: #333333;
  393. font-size: 32rpx;
  394. line-height: 44rpx;
  395. }
  396. .btn {
  397. margin-top: 26rpx;
  398. width: 100%;
  399. height: 90rpx;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. border-top:2rpx solid #E5E5E5;
  404. .cancel{
  405. flex: 1;
  406. display: flex;
  407. align-items: center;
  408. justify-content: center;
  409. font-weight: 400;
  410. color: #333333;
  411. font-size: 32rpx;
  412. }
  413. .download{
  414. flex: 1;
  415. height: 90rpx;
  416. display: flex;
  417. align-items: center;
  418. justify-content: center;
  419. border-left:2rpx solid #E5E5E5;
  420. font-weight: 400;
  421. color: #FF6200;
  422. font-size: 32rpx;
  423. }
  424. .know{
  425. font-weight: 400;
  426. color: #FF6200;
  427. font-size: 32rpx;
  428. }
  429. }
  430. }
  431. .prize {
  432. margin-top: 24rpx;
  433. background: #FFFFFF;
  434. border-radius: 16rpx;
  435. padding: 40rpx 30rpx 40rpx;
  436. .prize-title {
  437. font-weight: bold;
  438. color: #080F18;
  439. font-size: 30rpx;
  440. }
  441. .prize-main {
  442. margin-top: 40rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: space-between;
  446. border-bottom: 2rpx solid #F0F0F0;
  447. padding-bottom: 40rpx;
  448. &:last-child {
  449. border-bottom: none;
  450. padding-bottom: 0rpx;
  451. }
  452. .prize-main-left {
  453. display: flex;
  454. flex-direction: column;
  455. align-items: flex-start;
  456. justify-content: center;
  457. .prize-main-left-top {
  458. font-size: 32rpx;
  459. font-weight: bold;
  460. color: #333333;
  461. }
  462. .prize-main-left-bom {
  463. font-weight: 500;
  464. color: #999999;
  465. font-size: 24rpx;
  466. margin-top: 24rpx;
  467. }
  468. }
  469. .prize-main-right {
  470. flex: none;
  471. width: 148rpx;
  472. height: 60rpx;
  473. background: #FFFFFF;
  474. border-radius: 30rpx;
  475. border: 2rpx solid #D0D0D0;
  476. display: flex;
  477. align-items: center;
  478. justify-content: center;
  479. color: #D0D0D0;
  480. font-size: 26rpx;
  481. }
  482. .prize-main-rightSelect {
  483. flex: none;
  484. width: 148rpx;
  485. height: 60rpx;
  486. background: #FFFFFF;
  487. border-radius: 30rpx;
  488. border: 2rpx solid #FF6200;
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. color: #FF6200;
  493. font-size: 26rpx;
  494. }
  495. }
  496. }
  497. .rule {
  498. margin-top: 24rpx;
  499. background: #FFFFFF;
  500. border-radius: 16rpx;
  501. padding: 40rpx 30rpx 32rpx;
  502. .rule-title {
  503. font-weight: bold;
  504. color: #080F18;
  505. font-size: 30rpx;
  506. }
  507. .rule-content {
  508. margin-top: 32rpx;
  509. background: #FFFFFF;
  510. border-radius: 4rpx;
  511. border: 2rpx solid #999999;
  512. padding: 48rpx 20rpx 34rpx;
  513. .introduce-top {
  514. height: 32rpx;
  515. display: flex;
  516. align-items: center;
  517. justify-content: center;
  518. font-size: 32rpx;
  519. font-weight: bold;
  520. letter-spacing: 2rpx;
  521. .introduce-top-rule1 {
  522. width: 56rpx;
  523. height: 4rpx;
  524. background: linear-gradient(90deg, #FFFFFF 0%, #D9A94D 100%);
  525. }
  526. .introduce-top-rule2 {
  527. width: 56rpx;
  528. height: 4rpx;
  529. background: linear-gradient(-90deg, #FFFFFF 0%, #D9A94D 100%);
  530. }
  531. }
  532. .introduce-text {
  533. margin-top: 72rpx;
  534. font-weight: bold;
  535. color: #333333;
  536. font-size: 28rpx;
  537. line-height: 56rpx;
  538. }
  539. }
  540. }
  541. .produce {
  542. position: relative;
  543. top: -10rpx;
  544. background: #FFFFFF;
  545. border-radius: 16rpx;
  546. padding: 48rpx 30rpx 0rpx;
  547. .produce-title {
  548. font-weight: bold;
  549. color: #080F18;
  550. font-size: 30rpx;
  551. margin-bottom: 40rpx;
  552. }
  553. .produce-main {
  554. display: flex;
  555. align-items: center;
  556. justify-content: space-between;
  557. border-bottom: 2rpx solid #F0F0F0;
  558. padding-bottom: 32rpx;
  559. margin-bottom: 32rpx;
  560. &:last-child {
  561. border: none;
  562. margin-bottom: 0;
  563. }
  564. .produce-main-text {
  565. margin-left: 24rpx;
  566. flex: 1;
  567. display: flex;
  568. flex-direction: column;
  569. align-items: flex-start;
  570. justify-content: center;
  571. .produce-main-text-top {
  572. font-weight: 500;
  573. color: #080F18;
  574. font-size: 28rpx;
  575. }
  576. .produce-main-text-bom {
  577. font-weight: 500;
  578. color: #666666;
  579. font-size: 24rpx;
  580. margin-top: 14rpx;
  581. }
  582. }
  583. }
  584. }
  585. .spinning {
  586. padding-top: 64rpx;
  587. width: 100%;
  588. height: 790rpx;
  589. background-repeat: no-repeat;
  590. background-size: 100% 100%;
  591. .spinning-title {
  592. margin-bottom: 20rpx;
  593. display: flex;
  594. align-items: center;
  595. justify-content: center;
  596. font-weight: bold;
  597. color: #FFFFFF;
  598. font-size: 64rpx;
  599. }
  600. }
  601. </style>