index.vue 14 KB

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