index.vue 14 KB

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