index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <page ref="pageRef" title="天降红包" nav-color="transparent" light>
  3. <un v-if="!ongoing" @refresh="refresh"></un>
  4. <rain v-else :left-second="leftSecond" @lottery="lottery"></rain>
  5. <view class="index" @click="$router.index()">首页</view>
  6. <!-- <view class="rule" @click="showRule">规则</view> -->
  7. <rule ref="ruleRef" />
  8. <result ref="resultRef" />
  9. </page>
  10. </template>
  11. <script>
  12. import un from './un.vue'
  13. import rain from './rain.vue'
  14. import rule from './rule'
  15. import result from './result'
  16. export default {
  17. components: { un, rain, rule, result },
  18. data() {
  19. return {
  20. redData: null,
  21. ongoing: false,
  22. leftSecond: 0
  23. }
  24. },
  25. onShow() {
  26. this.getData()
  27. },
  28. onHide() {
  29. this.stopTimer()
  30. },
  31. methods: {
  32. refresh() {
  33. this.getData(true)
  34. },
  35. async getData(loading = false) {
  36. const res = await this.$service.weal.redPacketRain(loading)
  37. if (res) {
  38. this.ongoing = res.ongoing
  39. this.leftSecond = res.leftSecond
  40. if (this.ongoing && this.leftSecond > 0) {
  41. this.startTimer()
  42. } else {
  43. this.stopTimer()
  44. }
  45. }
  46. },
  47. startTimer() {
  48. this.stopTimer()
  49. this.timer = setInterval(() => {
  50. this.leftSecond -= 1
  51. if (this.leftSecond <= 0) {
  52. this.stopTimer()
  53. setTimeout(() => {
  54. this.getData()
  55. }, 0)
  56. }
  57. }, 1000)
  58. },
  59. stopTimer() {
  60. if (this.timer) {
  61. clearInterval(this.timer)
  62. this.timer = null
  63. }
  64. },
  65. showRule() {
  66. this.$refs.ruleRef.show()
  67. },
  68. async lottery() {
  69. const res = await this.$service.weal.redPacketRainJoin()
  70. if (res) {
  71. this.$refs.resultRef.show(res)
  72. }
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .index {
  79. position: fixed;
  80. top: 180rpx;
  81. right: 0;
  82. width: 96rpx;
  83. height: 48rpx;
  84. background: linear-gradient(315deg, #0bd1ce 0%, #3ba1ff 100%);
  85. border-radius: 200rpx 0px 0px 200rpx;
  86. line-height: 48rpx;
  87. text-align: center;
  88. color: #fff;
  89. font-size: 28rpx;
  90. z-index: 100;
  91. }
  92. .rule {
  93. position: fixed;
  94. top: 260rpx;
  95. right: 0;
  96. width: 96rpx;
  97. height: 48rpx;
  98. background: linear-gradient(315deg, #ff345a 0%, #ffa25e 100%);
  99. border-radius: 200rpx 0px 0px 200rpx;
  100. line-height: 48rpx;
  101. text-align: center;
  102. color: #fff;
  103. font-size: 28rpx;
  104. z-index: 100;
  105. }
  106. </style>