turntableTwo.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <uni-popup ref="turntablePopup" type="center" :is-mask-click="false">
  3. <view class="turntable">
  4. <image class="turntable-bg" src="https://cos.his.cdwjyyh.com/fs/20250910/de386927c5f44e02ab3ecc480ddb9797.png" mode="aspectFit"></image>
  5. <view class="turntable-box">
  6. <view class="turntable-wrap">
  7. <view class="turntable-item" :class="{ active: idx == light,disabled: item.isReceive }"
  8. v-for="(item,idx) in cells" :key="idx">
  9. <image :src="item.iconUrl" mode="aspectFit"></image>
  10. <view class="ellipsis">{{item.name}}</view>
  11. </view>
  12. </view>
  13. </view>
  14. <image class="close" src="https://cos.his.cdwjyyh.com/fs/20250910/93608bad8ad1479a854ec26e8eaaacea.png" @click="close"></image>
  15. <view class="btn-box">
  16. <image src="https://cos.his.cdwjyyh.com/fs/20250910/fe230bfdf74f4f0dac88af53f709d6c5.png" mode="widthFix" :class="isReceive==1 ?'gray':''" @click="start"></image>
  17. </view>
  18. </view>
  19. </uni-popup>
  20. </template>
  21. <script>
  22. import {getVideoRewardRules} from "@/api/course.js"
  23. export default {
  24. data() {
  25. return {
  26. baseUrl: uni.getStorageSync('requestImagesPath'),
  27. light: -1,
  28. running: false,
  29. targetIdx: -1,
  30. total: 0,
  31. speed: 150,
  32. cells:[],
  33. timer: null,
  34. isReceive: 0,
  35. }
  36. },
  37. computed: {
  38. // 剩余可用索引
  39. availIdx() {
  40. return this.cells.map((_, i) => i).filter(i => !this.cells[i].isReceive)
  41. },
  42. // 是否全部抽完
  43. allDone() {
  44. return this.availIdx.length === 0
  45. }
  46. },
  47. methods: {
  48. getVideoRewardRules(urlOption) {
  49. const param = {
  50. type: 4,
  51. ...urlOption
  52. }
  53. getVideoRewardRules(param).then(res=>{
  54. if(res.code == 200) {
  55. this.cells = res.data || []
  56. this.total = this.cells.length
  57. this.isReceive = this.cells.every(item => item.isReceive == true)? 1 :0
  58. }else {
  59. uni.showToast({
  60. title: res.msg,
  61. icon: 'none'
  62. })
  63. }
  64. })
  65. },
  66. open(urlOption) {
  67. this.$refs.turntablePopup.open()
  68. this.getVideoRewardRules(urlOption)
  69. },
  70. close(type) {
  71. if(type=='close') {
  72. this.running = false
  73. clearInterval(this.timer)
  74. }
  75. if (this.running) {
  76. uni.showToast({
  77. title: '抽取中,请勿关闭',
  78. icon: 'none'
  79. })
  80. return
  81. }
  82. this.$refs.turntablePopup.close()
  83. },
  84. start() {
  85. if (this.running) {
  86. uni.showToast({
  87. title: '抽取中',
  88. icon: 'none'
  89. })
  90. return
  91. }
  92. if(this.isReceive == 1) return
  93. this.running = true
  94. clearInterval(this.timer)
  95. let last = -1
  96. if(this.availIdx.length >1) {
  97. this.timer = setInterval(() => {
  98. let next;
  99. do {
  100. next = this.availIdx[Math.floor(Math.random() * this.availIdx.length)];
  101. } while (next === last);
  102. last = next;
  103. this.light = next;
  104. }, this.speed)
  105. }
  106. this.$emit('sendRewardFun',4)
  107. },
  108. endSuccess(code) {
  109. this.targetIdx = this.cells.findIndex(it=>it.code == code)
  110. clearInterval(this.timer)
  111. this.timer = null
  112. if(this.targetIdx==-1) {
  113. uni.showToast({
  114. title: '抽奖失败',
  115. icon: 'none'
  116. })
  117. return
  118. }
  119. const totalSteps = 2 // 约 3s / 80ms
  120. let step = 0
  121. let last = -1
  122. const that = this
  123. if(this.availIdx.length <= 1) {
  124. this.light = this.targetIdx
  125. this.running = false
  126. this.isReceive = 1
  127. uni.showModal({
  128. title: '恭喜,中奖',
  129. content: this.cells[this.targetIdx].name,
  130. showCancel: false,
  131. success: function (res) {
  132. if (res.confirm) {
  133. that.$refs.turntablePopup.close()
  134. that.$emit("openAppPop")
  135. } else if (res.cancel) {
  136. that.$refs.turntablePopup.close()
  137. that.$emit("openAppPop")
  138. }
  139. }
  140. });
  141. return
  142. }
  143. this.timer = setInterval(() => {
  144. let next
  145. do {
  146. next = this.availIdx[Math.floor(Math.random() * this.availIdx.length)]
  147. } while (next === last)
  148. last = next
  149. this.light = next
  150. step++
  151. if (step >= totalSteps) {
  152. clearInterval(this.timer)
  153. this.light = this.targetIdx
  154. // 置灰
  155. this.running = false
  156. this.isReceive = 1
  157. setTimeout(()=>{
  158. uni.showModal({
  159. title: '恭喜,中奖',
  160. content: this.cells[this.targetIdx].name,
  161. showCancel: false,
  162. success: function (res) {
  163. if (res.confirm) {
  164. that.$refs.turntablePopup.close()
  165. that.$emit("openAppPop")
  166. } else if (res.cancel) {
  167. that.$refs.turntablePopup.close()
  168. that.$emit("openAppPop")
  169. }
  170. }
  171. });
  172. },500)
  173. // this.cells[this.targetIdx].isReceive = true
  174. }
  175. }, this.speed)
  176. }
  177. }
  178. }
  179. </script>
  180. <style scoped lang="scss">
  181. .gray {
  182. filter: grayscale(1); /* 1 = 100% 灰度 */
  183. }
  184. .close {
  185. width: 64rpx;
  186. height: 64rpx;
  187. position: absolute;
  188. top: 88rpx;
  189. right: 20rpx;
  190. z-index: 2;
  191. }
  192. .active {
  193. transform: scale(1.05);
  194. background: linear-gradient(0deg, #FFD44F 0%, #FFFABD 100%) !important;
  195. box-shadow: 0rpx 2rpx 0rpx 0rpx #FFFCF5 !important;
  196. }
  197. .disabled {
  198. filter: grayscale(1) brightness(0.7);
  199. opacity: 0.5;
  200. }
  201. .btn-box {
  202. width: 540rpx;
  203. height: 104rpx;
  204. position: absolute;
  205. bottom: 46rpx;
  206. left: 50%;
  207. transform: translateX(-50%);
  208. z-index: 2;
  209. image {
  210. width: 100%;
  211. height: auto;
  212. }
  213. }
  214. .turntable {
  215. width: 750rpx;
  216. height: 1056rpx;
  217. position: relative;
  218. &-bg {
  219. width: 100%;
  220. height: 100%;
  221. position: absolute;
  222. top: 0;
  223. left: 0;
  224. z-index: 1;
  225. }
  226. &-box {
  227. position: absolute;
  228. bottom: 174rpx;
  229. left: 50%;
  230. transform: translateX(-50%);
  231. z-index: 2;
  232. width: 623rpx;
  233. height: 628rpx;
  234. padding: 16rpx 0 8rpx 16rpx;
  235. box-sizing: border-box;
  236. }
  237. &-wrap {
  238. display: flex;
  239. flex-wrap: wrap;
  240. }
  241. &-item {
  242. width: 112rpx;
  243. height: 112rpx;
  244. background: linear-gradient(0deg, #FCEFCA 0%, #FFFFFF 100%);
  245. border-radius: 16rpx;
  246. font-family: PingFang SC;
  247. font-weight: 500;
  248. font-size: 20rpx;
  249. color: #333333;
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. flex-direction: column;
  254. margin: 0 8rpx 8rpx 0;
  255. transition: transform 0.2s, box-shadow 0.2s;
  256. image {
  257. width: 45rpx;
  258. height: 63rpx;
  259. }
  260. .ellipsis {
  261. overflow: hidden;
  262. text-overflow: ellipsis;
  263. white-space: nowrap;
  264. }
  265. }
  266. }
  267. </style>