auctionIcon.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="auction-icon-wrap">
  3. <div @click="handleClick" class="auction-icon" :class="{'moblie-auction-icon' : isMoblie}">
  4. <span v-if="!isMoblie">{{timeStr}}</span>
  5. </div>
  6. <auction-modal @closeaucmodal="auctionShow = false" v-if="auctionShow"></auction-modal>
  7. <take-reward
  8. @closeEosReward="rewardRec = null"
  9. @closeGtReward="rewardGt = null"
  10. v-if="rewardRec || rewardGt"
  11. :rewardRec="rewardRec"
  12. :rewardGt="rewardGt"
  13. ></take-reward>
  14. </div>
  15. </template>
  16. <script>
  17. import Bus from '../../js/bus'
  18. import API from '@/api'
  19. import takeReward from './takeReward'
  20. export default {
  21. name: 'auctionIcon',
  22. data () {
  23. return {
  24. timeStr: '',
  25. auctionShow: false,
  26. rewardRec: null, // eos获奖信息
  27. rewardGt: null, // gt获奖信息1
  28. ttl: 0,
  29. timer: null,
  30. isMoblie: /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)
  31. }
  32. },
  33. components: {
  34. auctionModal: () => import('../auction/auctionModal'),
  35. takeReward
  36. },
  37. computed: {
  38. account () {
  39. return this.$store.state.account
  40. }
  41. },
  42. watch: {
  43. account (to, from) {
  44. this.getAuctionInfo()
  45. }
  46. },
  47. methods: {
  48. updateTime () {
  49. if (this.ttl > 0 && this.prize >= 500000) {
  50. this.ttl -= 1
  51. let ttl = this.ttl
  52. let M = Math.floor(ttl % 3600 / 60)
  53. M = M < 10 ? '0' + M : M
  54. let S = Math.floor(ttl % 3600 % 60)
  55. S = S < 10 ? '0' + S : S
  56. this.timeStr = `${M}:${S}`
  57. }
  58. if (this.prize < 500000) {
  59. this.timeStr = this.$t('auction.ready')
  60. }
  61. Bus.$emit('update:time', this.timeStr, this.ttl)
  62. Bus.$emit('update:timeAuction', this.timeStr)
  63. },
  64. handleClick () {
  65. this.auctionShow = true
  66. },
  67. // 获取奖池信息
  68. getAuctionInfo () {
  69. let params = {
  70. player: this.account.name || null
  71. }
  72. API.auction.getAuctionInfo(params).then(({ data }) => {
  73. this.ttl = data.data.ttl
  74. this.prize = data.data.prize
  75. if (data.data.rewardList.length) {
  76. this.rewardRec = data.data.rewardList[0]
  77. }
  78. if (data.data.lastFailBid) {
  79. this.rewardGt = data.data.lastFailBid
  80. }
  81. this.$store.commit('setAuction', data.data)
  82. })
  83. }
  84. },
  85. created () {
  86. setInterval(() => {
  87. this.updateTime()
  88. }, 1000)
  89. // 获取奖池信息
  90. this.getAuctionInfo()
  91. Bus.$on('update:auctionShow', (data) => {
  92. this.auctionShow = true
  93. })
  94. // 竞拍接口请求
  95. Bus.$on('update:auctioninfo', (data) => {
  96. this.getAuctionInfo()
  97. })
  98. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .auction-icon{
  103. background: url('img/but_jinpai.png');
  104. background-size: 100%;
  105. width: 46px;
  106. height: 46px;
  107. margin-right: px2rem(20);
  108. cursor: pointer;
  109. position: relative;
  110. &:hover{
  111. background: url('img/but_jinpai_down.png');
  112. background-size: 100%;
  113. }
  114. span{
  115. position: absolute;
  116. top: 24px;
  117. left: 0;
  118. right: 0;
  119. text-align: center;
  120. font-size: 12px;
  121. color: #ffffff;
  122. }
  123. }
  124. .moblie-auction-icon{
  125. width: px2rem(46);
  126. height: px2rem(46);
  127. }
  128. </style>