index.vue 15 KB

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