turntableTwo.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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: 100,
  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 = Math.max(8, this.availIdx.length);
  120. // 约 2.5s / 100ms
  121. let step = 0
  122. let last = -1
  123. const that = this
  124. if(this.availIdx.length <= 1) {
  125. this.light = this.targetIdx
  126. this.running = false
  127. this.isReceive = 1
  128. uni.showModal({
  129. title: '恭喜,中奖',
  130. content: this.cells[this.targetIdx].name,
  131. showCancel: false,
  132. success: function (res) {
  133. if (res.confirm) {
  134. that.$refs.turntablePopup.close()
  135. that.$emit("openAppPop")
  136. } else if (res.cancel) {
  137. that.$refs.turntablePopup.close()
  138. that.$emit("openAppPop")
  139. }
  140. }
  141. });
  142. return
  143. }
  144. this.timer = setInterval(() => {
  145. let next
  146. do {
  147. next = this.availIdx[Math.floor(Math.random() * this.availIdx.length)]
  148. } while (next === last)
  149. last = next
  150. this.light = next
  151. step++
  152. if (step >= totalSteps) {
  153. clearInterval(this.timer)
  154. this.light = this.targetIdx
  155. // 置灰
  156. this.running = false
  157. this.isReceive = 1
  158. setTimeout(()=>{
  159. uni.showModal({
  160. title: '恭喜,中奖',
  161. content: this.cells[this.targetIdx].name,
  162. showCancel: false,
  163. success: function (res) {
  164. if (res.confirm) {
  165. that.$refs.turntablePopup.close()
  166. that.$emit("openAppPop")
  167. } else if (res.cancel) {
  168. that.$refs.turntablePopup.close()
  169. that.$emit("openAppPop")
  170. }
  171. }
  172. });
  173. },500)
  174. // this.cells[this.targetIdx].isReceive = true
  175. }
  176. }, this.speed)
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped lang="scss">
  182. .gray {
  183. filter: grayscale(1); /* 1 = 100% 灰度 */
  184. }
  185. .close {
  186. width: 64rpx;
  187. height: 64rpx;
  188. position: absolute;
  189. top: 88rpx;
  190. right: 20rpx;
  191. z-index: 2;
  192. }
  193. .active {
  194. transform: scale(1.05);
  195. background: linear-gradient(0deg, #FFD44F 0%, #FFFABD 100%) !important;
  196. box-shadow: 0rpx 2rpx 0rpx 0rpx #FFFCF5 !important;
  197. }
  198. .disabled {
  199. filter: grayscale(1) brightness(0.7);
  200. opacity: 0.5;
  201. }
  202. .btn-box {
  203. width: 540rpx;
  204. height: 104rpx;
  205. position: absolute;
  206. bottom: 46rpx;
  207. left: 50%;
  208. transform: translateX(-50%);
  209. z-index: 2;
  210. image {
  211. width: 100%;
  212. height: auto;
  213. }
  214. }
  215. .turntable {
  216. width: 750rpx;
  217. height: 1056rpx;
  218. position: relative;
  219. &-bg {
  220. width: 100%;
  221. height: 100%;
  222. position: absolute;
  223. top: 0;
  224. left: 0;
  225. z-index: 1;
  226. }
  227. &-box {
  228. position: absolute;
  229. bottom: 174rpx;
  230. left: 50%;
  231. transform: translateX(-50%);
  232. z-index: 2;
  233. width: 623rpx;
  234. height: 628rpx;
  235. padding: 16rpx 0 8rpx 16rpx;
  236. box-sizing: border-box;
  237. }
  238. &-wrap {
  239. display: flex;
  240. flex-wrap: wrap;
  241. }
  242. &-item {
  243. width: 112rpx;
  244. height: 112rpx;
  245. background: linear-gradient(0deg, #FCEFCA 0%, #FFFFFF 100%);
  246. border-radius: 16rpx;
  247. font-family: PingFang SC;
  248. font-weight: 500;
  249. font-size: 20rpx;
  250. color: #333333;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. flex-direction: column;
  255. margin: 0 8rpx 8rpx 0;
  256. transition: transform 0.2s, box-shadow 0.2s;
  257. image {
  258. width: 45rpx;
  259. height: 63rpx;
  260. }
  261. .ellipsis {
  262. overflow: hidden;
  263. text-overflow: ellipsis;
  264. white-space: nowrap;
  265. }
  266. }
  267. }
  268. </style>