catchDoll.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view>
  3. <scroll-view
  4. class="scroll-wrapper"
  5. :style="{ top: top + 'px' }"
  6. scroll-y
  7. refresher-enabled
  8. refresher-default-style="white"
  9. @refresherrefresh="pullRefresh"
  10. :refresher-triggered="refreshing"
  11. >
  12. <view class="rule-btn" @click="$refs.rule.show()">
  13. <image :src="ossurl.welfare.toys.rule" class="width100 height100" />
  14. </view>
  15. <view class="win-btn" @click="winRecord()">
  16. <image :src="ossurl.welfare.toys.record" class="width100 height100" />
  17. </view>
  18. <view class="doll_all_win" @click.stop="onAllWin">
  19. <image :src="ossurl.welfare.toys.reward" class="width100 height100" />
  20. </view>
  21. <view class="toysBox">
  22. <image :src="ossurl.welfare.toys.toys" class="toysBoxImage" mode="widthFix" />
  23. <view class="molibiBox">
  24. <view class="molibi">
  25. 源力币:
  26. <span class="num">{{ molibi }}</span>
  27. </view>
  28. <view class="btn" @click.stop="addMolibi">
  29. <image :src="ossurl.welfare.toys.get" class="width100 height100" />
  30. </view>
  31. </view>
  32. <view class="ballsBox">
  33. <view
  34. class="ball"
  35. :animation="ballsAnimationData[item]"
  36. v-for="item in 50"
  37. :key="item"
  38. :style="poslist[item]"
  39. >
  40. <image :src="ossurl.welfare.toys.ball" class="width100 height100" />
  41. </view>
  42. </view>
  43. <view class="ballBox" :animation="ballAnimationData">
  44. <image :src="ossurl.welfare.toys.ball" class="width100 height100" />
  45. </view>
  46. <view class="switchBox" :animation="switchAnimationData" @click="setBallAnimation(),setSwitch()">
  47. <image :src="ossurl.welfare.toys.switch" class="width100 height100" />
  48. </view>
  49. </view>
  50. <view class="btnBottom">
  51. <view class="btn" @click="pressOneLeave">
  52. <image :src="ossurl.welfare.toys.one" class="width100 height100" />
  53. <view>消耗1源力币</view>
  54. </view>
  55. <view class="btn" @click="pressFiveLeave">
  56. <image :src="ossurl.welfare.toys.five" class="width100 height100" />
  57. <view>消耗5源力币</view>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. <catch-rule ref="rule" />
  62. <win-record ref="winRecordRef" />
  63. <doll-result ref="dollResultRef" />
  64. <doll-prize ref="dollPrizeRef" />
  65. <press-sure ref="pressSureRef" @press="onPress" />
  66. <lack-molib ref="lackMolibRef" />
  67. </view>
  68. </template>
  69. <script>
  70. import resource from '@/utils/resource'
  71. import ossurl from '@/utils/ossurl'
  72. import catchRule from './catch_rule'
  73. import winRecord from './catch_record.vue'
  74. import dollResult from './doll_result.vue'
  75. import dollPrize from './doll_allPrize.vue'
  76. import pressSure from './doll_press_sure.vue'
  77. import lackMolib from './lackMolib.vue'
  78. export default {
  79. components: { catchRule, winRecord, dollResult, dollPrize, pressSure, lackMolib },
  80. props: {
  81. statusBarHeight: Number
  82. },
  83. data() {
  84. return {
  85. resource,
  86. ossurl,
  87. data: null,
  88. pressOneFlag: false,
  89. pressFiveFlag: false,
  90. refreshing: false,
  91. prizeListThree: [], // 前三奖品
  92. molibi: 0, // 源力币
  93. ballAnimationData: null,
  94. switchAnimationData: null,
  95. ballsAnimationData: [],
  96. poslist: [],
  97. lotteryFlag: false,
  98. zhuashouImg: resource.zhuashou,
  99. dollHandleList: [
  100. resource.doll_handle1,
  101. resource.doll_handle2,
  102. resource.doll_handle3,
  103. resource.doll_handle4,
  104. resource.doll_handle5,
  105. resource.doll_handle6,
  106. resource.doll_handle7,
  107. resource.doll_handle8
  108. ]
  109. }
  110. },
  111. computed: {
  112. top() {
  113. return this.statusBarHeight + uni.upx2px(72) + 45
  114. }
  115. },
  116. mounted() {
  117. this.onAllWin('three')
  118. this.getMolibi()
  119. this.setBallAnimation()
  120. this.getPosition()
  121. },
  122. methods: {
  123. getPosition() {
  124. this.poslist = []
  125. for (let i = 0; i < 50; i++) {
  126. let bottom = Math.random() * 80 + 'px'
  127. let left = Math.random() * 172 + 'px'
  128. let style = `bottom:${bottom};left:${left}`
  129. this.poslist.push(style)
  130. }
  131. },
  132. setBallAnimation() {
  133. this.ballsAnimationData = []
  134. for (let i = 0; i < 50; i++) {
  135. let bottom = (Math.random()-0.8) * 100
  136. let left = (Math.random()-0.5) * 20
  137. let animation = wx.createAnimation({
  138. duration: 300,
  139. timingFunction: 'linear'
  140. })
  141. this.animation = animation
  142. bottom = (Math.random()-0.5) * 200
  143. left = (Math.random()-0.5) * 50
  144. animation.translate(left, bottom).rotate(Math.random()*90).step({
  145. duration: 200,
  146. timingFunction: 'linear'
  147. })
  148. bottom = (Math.random()-0.5) * 200
  149. left = (Math.random()-0.5) * 50
  150. animation.translate(left, bottom).rotate(Math.random()*360).step({
  151. duration: 300,
  152. timingFunction: 'ease'
  153. })
  154. animation.translate(Math.random()*50, Math.random()*50).rotate(Math.random()*90).step({
  155. duration: 300,
  156. timingFunction: 'linear'
  157. })
  158. this.ballsAnimationData.push(animation.export())
  159. }
  160. },
  161. setBall() {
  162. let animation = wx.createAnimation({
  163. duration: 1000,
  164. timingFunction: 'ease'
  165. })
  166. this.animation = animation
  167. animation.scale(1, 1).rotate(45).opacity(1).step()
  168. this.ballAnimationData = animation.export()
  169. setTimeout(
  170. function () {
  171. animation.opacity(0).scale(0, 0).step()
  172. animation.opacity(0).step()
  173. this.ballAnimationData = animation.export()
  174. }.bind(this),
  175. 2000
  176. )
  177. },
  178. setSwitch() {
  179. let animation = wx.createAnimation({
  180. duration: 500,
  181. timingFunction: 'ease'
  182. })
  183. this.animation = animation
  184. animation.rotate(90).step()
  185. this.switchAnimationData = animation.export()
  186. setTimeout(
  187. function () {
  188. animation.rotate(0).step()
  189. this.switchAnimationData = animation.export()
  190. }.bind(this),
  191. 1000
  192. )
  193. },
  194. pullRefresh() {
  195. this.refreshing = true
  196. this.onAllWin('three')
  197. this.getMolibi()
  198. setTimeout(() => {
  199. this.refreshing = false
  200. }, 1000)
  201. },
  202. winRecord() {
  203. this.$refs.winRecordRef.show()
  204. },
  205. onExchange() {
  206. this.$router.push('exchange')
  207. },
  208. async onAllWin(type) {
  209. this.$service.weal.catchDollDetail().then((res) => {
  210. if (res.code === '0') {
  211. if (type === 'three') {
  212. this.prizeListThree = res.data.luckWheelGoodsList.slice(0, 3)
  213. } else {
  214. this.$refs.dollPrizeRef.show(res.data.luckWheelGoodsList)
  215. }
  216. } else {
  217. this.$message.error(res.msg)
  218. }
  219. })
  220. },
  221. async getMolibi() {
  222. const res = await this.$service.wallet.info('MAGIC_POWER_COIN')
  223. res && (this.molibi = res.balance)
  224. },
  225. pressOne() {
  226. this.pressOneFlag = true
  227. },
  228. pressOneLeave() {
  229. this.pressOneFlag = false
  230. if (this.lotteryFlag) {
  231. this.$message.warn('请不要重复点击')
  232. return
  233. } else {
  234. if (this.molibi == 0) {
  235. this.$refs.lackMolibRef.show()
  236. } else {
  237. this.$refs.pressSureRef.show(1)
  238. }
  239. }
  240. },
  241. pressFive() {
  242. this.pressFiveFlag = true
  243. },
  244. pressFiveLeave() {
  245. this.pressFiveFlag = false
  246. if (this.lotteryFlag) {
  247. this.$message.warn('请不要重复点击')
  248. return
  249. } else {
  250. if (this.molibi < 5) {
  251. this.$refs.lackMolibRef.show()
  252. } else {
  253. this.$refs.pressSureRef.show(5)
  254. }
  255. }
  256. },
  257. onPress(pressType) {
  258. this.pressSubmit(pressType)
  259. },
  260. pressSubmit(quantity) {
  261. this.lotteryFlag = true
  262. this.$service.weal.dollLottery({ quantity }).then((res) => {
  263. if (res.code === '0') {
  264. this.getMolibi()
  265. // this.animateClaw()
  266. this.setSwitch()
  267. setTimeout(() => {
  268. this.setBallAnimation()
  269. }, 500)
  270. setTimeout(() => {
  271. this.setBall()
  272. }, 800)
  273. setTimeout(() => {
  274. this.$refs.dollResultRef.show(res.data)
  275. this.lotteryFlag = false
  276. }, 2000)
  277. } else {
  278. this.$message.error(res.msg)
  279. this.lotteryFlag = false
  280. }
  281. })
  282. },
  283. addMolibi() {
  284. this.$router.switchTab('award')
  285. },
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. .scroll-wrapper {
  291. position: fixed;
  292. left: 0;
  293. right: 0;
  294. bottom: 0;
  295. }
  296. .doll_all_win {
  297. position: fixed;
  298. left: 0;
  299. top: 250rpx;
  300. width: 58rpx;
  301. height: 128rpx;
  302. z-index: 99;
  303. }
  304. .rule-btn {
  305. position: fixed;
  306. right: 0;
  307. top: 250rpx;
  308. width: 58rpx;
  309. height: 84rpx;
  310. text-align: center;
  311. z-index: 99;
  312. }
  313. .win-btn {
  314. position: fixed;
  315. right: 0;
  316. top:360rpx;
  317. width: 58rpx;
  318. height: 128rpx;
  319. font-size: 24rpx;
  320. line-height: 24px;
  321. text-align: center;
  322. z-index: 99;
  323. }
  324. .btnBottom {
  325. position: fixed;
  326. bottom: 20rpx;
  327. z-index: 99;
  328. width: 100%;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. .btn {
  333. padding: 0 20rpx;
  334. text-align: center;
  335. font-size: 20rpx;
  336. font-family: Source Han Sans, Source Han Sans;
  337. font-weight: 350;
  338. color: #c74104;
  339. image {
  340. width: 306rpx;
  341. height: 96rpx;
  342. }
  343. }
  344. }
  345. .toysBox {
  346. width: 100vw;
  347. text-align: center;
  348. position: relative;
  349. .toysBoxImage {
  350. width: 750rpx;
  351. position: relative;
  352. z-index: 2;
  353. }
  354. .molibiBox {
  355. position: absolute;
  356. top: 700rpx;
  357. width: 100%;
  358. display: flex;
  359. align-items: center;
  360. justify-content: space-between;
  361. padding: 0 100rpx;
  362. padding-top: 8rpx;
  363. z-index: 5;
  364. .molibi {
  365. font-size: 22rpx;
  366. font-family: Source Han Sans, Source Han Sans;
  367. font-weight: 350;
  368. color: #ffffff;
  369. line-height: 32rpx;
  370. .num {
  371. font-size: 32rpx;
  372. font-family: Source Han Sans, Source Han Sans;
  373. font-weight: 700;
  374. color: #ffffff;
  375. line-height: 46rpx;
  376. }
  377. }
  378. .btn {
  379. width: 160rpx;
  380. height: 60rpx;
  381. }
  382. }
  383. .ballBox {
  384. position: absolute;
  385. top: 878rpx;
  386. left: 180rpx;
  387. width: 132rpx;
  388. height: 132rpx;
  389. transform: scale(0);
  390. z-index: 3;
  391. }
  392. .switchBox {
  393. position: absolute;
  394. top: 878rpx;
  395. right: 206rpx;
  396. height: 120rpx;
  397. width: 120rpx;
  398. z-index: 3;
  399. }
  400. .ballsBox {
  401. width: 476rpx;
  402. height: 476rpx;
  403. background-color: #5e62ca;
  404. position: absolute;
  405. top: 90rpx;
  406. left: 140rpx;
  407. z-index: 1;
  408. overflow: hidden;
  409. .ball {
  410. position: absolute;
  411. bottom: 10rpx;
  412. left: 10rpx;
  413. width: 132rpx;
  414. height: 132rpx;
  415. }
  416. }
  417. }
  418. </style>