zhuanpan.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="page">
  3. <!-- <image class="bg" :src="'/static/img/DM_20240409173533_003.jpg'"></image>-->
  4. <view class="rule" @click="goRule">
  5. <text>规则</text>
  6. </view>
  7. <view class="flex-col content">
  8. <view class="flex-row justify-end">
  9. <view class="flex-row justify-end record" @click="goRecord">
  10. <text class="record-left">中奖记录</text>
  11. <u-icon name="/static/img/DM_20240409173533_004.png" size="45rpx"></u-icon>
  12. </view>
  13. </view>
  14. <view>
  15. <LuckyWheel ref="myLucky" width="500rpx" height="500rpx"
  16. :blocks="blocks" :prizes="prizes" :buttons="buttons"
  17. @start="startCallBack" @end="endCallBack"/>
  18. </view>
  19. <view class="count">
  20. <text>您有{{drawCount}}次抽奖机会</text>
  21. </view>
  22. <view id="rollId" class="roll">
  23. <wfScroll :scrollHeight="scrollHeight" :scrollTimer="true" :listAr="winningRecordList"></wfScroll>
  24. </view>
  25. </view>
  26. <uni-popup ref="winningResult" type="center" :animation="false">
  27. <view class="result">
  28. <view class="winningResultView">
  29. <image :src="'/static/img/1.png'" mode="widthFix" class="winningTitleBac"></image>
  30. <view class="flex-row justify-center winning">
  31. <view class="flex-col">
  32. <text class="" v-if="winningName !== '谢谢参与'">恭喜获得</text>
  33. <text class="">{{winningName}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="flex-row justify-center">
  38. <image :src="'/static/img/2.png'" mode="widthFix" class="ox" @click="closeWinningResult"></image>
  39. </view>
  40. </view>
  41. </uni-popup>
  42. </view>
  43. </template>
  44. <script>
  45. import wfScroll from "../../components/WF-scroll/WF-scroll";
  46. import LuckyWheel from "../../components/@lucky-canvas/uni/lucky-wheel";
  47. export default {
  48. components: {LuckyWheel,wfScroll},
  49. data() {
  50. return {
  51. userId:'',
  52. drawCount:0,
  53. winningName:'',
  54. scrollHeight:0,
  55. winningRecordList:[],
  56. blocks: [
  57. { padding: '40rpx'},
  58. {imgs:[{src:'static/img/zpbg.png',width:'500rpx',height:'500rpx',top:'-40rpx',rotate:true}]}
  59. ],
  60. prizes: [
  61. // { fonts: [{ text: '一等奖', top: '10%',fontSize:'25rpx' }],imgs:[{src:'static/img/DM_20240409173533_004.png',top:'40%'}], background: '#fff9d9' },
  62. // { fonts: [{ text: '小米手机', top: '10%',fontSize:'25rpx' }], background: '#f6ecb4' },
  63. // { fonts: [{ text: '大彩电', top: '10%',fontSize:'25rpx' }], background: '#fff9d9' },
  64. // { fonts: [{ text: '小踩点', top: '10%',fontSize:'25rpx' }], background: '#f6ecb4' },
  65. // { fonts: [{ text: '耳机', top: '10%',fontSize:'25rpx' }], background: '#fff9d9' },
  66. // { fonts: [{ text: '收音机', top: '10%',fontSize:'25rpx' }], background: '#f6ecb4' },
  67. ],
  68. buttons: [
  69. { radius: '70rpx', background: '#fddc6a'},
  70. // {
  71. // radius: '40px', background: '#fddc6a',
  72. // pointer: true,
  73. // fonts: [{ text: '开始\n抽奖', top: '-30px',fontColor:'#fa4445',fontWeight:'700',fontSize:'40rpx',lineHeight:'50rpx' }]
  74. // },
  75. {
  76. imgs: [{src:'static/img/DM_20240409173533_001.png',width:'150rpx',height:'190rpx',top:'-110rpx'}],
  77. },
  78. ],
  79. }
  80. },
  81. mounted(){
  82. this.getScrollHeight();
  83. },
  84. onLoad(e){
  85. if (e.token){
  86. uni.setStorageSync('accessToken', e.token);
  87. console.log('获取到的token', e.token)
  88. }else {
  89. uni.setStorageSync('accessToken', null);
  90. }
  91. this.prizeList()
  92. this.winningRecord()
  93. this.getDrawCount()
  94. },
  95. methods: {
  96. getDrawCount(){
  97. this.$api.service.drawCount({
  98. userId:this.userId
  99. }).then(res=>{
  100. this.drawCount = res.data.data
  101. console.log(res.data.data)
  102. })
  103. },
  104. closeWinningResult(){
  105. this.$refs.winningResult.close()
  106. },
  107. draw(){
  108. this.$api.service.draw({
  109. userId:this.userId
  110. }).then(res=>{
  111. console.log(res)
  112. })
  113. },
  114. winningRecord(){
  115. this.$api.service.winningRecord({
  116. current: 1,
  117. size: 50,
  118. flag:false
  119. }).then(res=>{
  120. this.winningRecordList = res.data.data
  121. })
  122. },
  123. prizeList(){
  124. this.$api.service.prizeList().then(res=>{
  125. if (res.data.data.length>0){
  126. this.buildPrize(res.data.data)
  127. }
  128. console.log('奖品列表',res.data.data)
  129. })
  130. },
  131. buildPrize(prizeList){
  132. this.prizes = []
  133. for (let i = 0;i < prizeList.length ;i++){
  134. let prize = { fonts: [{ text: '一等奖', top: '10%',fontSize:'25rpx',id:''}],
  135. imgs:[{src:'static/img/DM_20240409173533_004.png',top:'40%',width:'70rpx',height:'40rpx'}],
  136. background: '#fff9d9' }
  137. prize.fonts[0].id = prizeList[i].id
  138. prize.fonts[0].text = prizeList[i].prizeName
  139. prize.imgs[0].src = prizeList[i].prizeImage
  140. if (i%2 === 0){
  141. prize.background = '#fff9d9'
  142. }else {
  143. prize.background = '#f6ecb4'
  144. }
  145. this.prizes.push(prize)
  146. }
  147. },
  148. goRecord(){
  149. uni.navigateTo({
  150. url:'/pages/lotteryRecord/lotteryRecord'
  151. })
  152. },
  153. goRule(){
  154. uni.navigateTo({
  155. url:'/pages/lotteryRule/lotteryRule'
  156. })
  157. },
  158. getScrollHeight(){
  159. const query = uni.createSelectorQuery().in(this);
  160. query.select('#rollId').boundingClientRect(data => {
  161. let sysinfo = uni.getSystemInfoSync()
  162. this.scrollHeight = (sysinfo.screenWidth/750) * data.height
  163. console.log('元素的高度:', this.scrollHeight);
  164. }).exec();
  165. },
  166. // 点击抽奖按钮触发回调
  167. startCallBack () {
  168. if (this.drawCount === 0){
  169. uni.showToast({
  170. icon: 'none',
  171. duration: 3000,
  172. title: '您当前的抽奖机会为0'
  173. });
  174. return
  175. }
  176. // 先开始旋转
  177. this.$api.service.draw({
  178. userId:'1734095760943947778'
  179. }).then(res=>{
  180. this.$refs.myLucky.play()
  181. console.log('中奖结果',res.data.data)
  182. // 使用定时器来模拟请求接口
  183. setTimeout(() => {
  184. let index = null
  185. // 假设后端返回的中奖索引是0
  186. for (let i = 0;i< this.prizes.length;i++){
  187. if (this.prizes[i].fonts[0].id == res.data.data.id){
  188. console.log(this.prizes[i].fonts[0].id)
  189. console.log(res.data.data.id)
  190. index = i
  191. }
  192. }
  193. // 调用stop停止旋转并传递中奖索引
  194. this.$refs.myLucky.stop(index)
  195. }, 2000)
  196. }).catch(err=>{
  197. this.$refs.myLucky.stop()
  198. uni.$u.toast(err.data.msg)
  199. })
  200. },
  201. // 抽奖结束触发回调
  202. endCallBack (prize) {
  203. // 奖品详情
  204. console.log('奖品详情',prize)
  205. this.winningRecord()
  206. this.getDrawCount()
  207. this.winningName = prize.fonts[0].text
  208. this.$refs.winningResult.open()
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. @import './index.rpx.scss';
  215. </style>