desktop.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="game-main-wrap">
  3. <game-header></game-header>
  4. <div class="game-desktop">
  5. <div class="game-cell-wrap">
  6. <div class="game-desk-bg" :class="`${$i18n.locale}-lang-bg`"></div>
  7. <div class="game-cell-item"
  8. v-for="(item, key) in typeMap"
  9. :key="key"
  10. :class="[`game-cell-${key}`, {'checked': typeMap[key]['amount'].length, 'opened': openArray.includes(key)}]"
  11. @click="betSelect(key, $event)"
  12. >
  13. <div class="cell-counter"
  14. :class="`counter-${getColor(item.sum)}`"
  15. v-if="item.sum">
  16. {{item.sum}}
  17. </div>
  18. </div>
  19. <div class="moblie-rule-cell" @click="showRules">
  20. <i class="game-question-icon"></i>
  21. </div>
  22. </div>
  23. <game-bet
  24. @update:betNum="updateBetNum"
  25. @update:counter="changeCounter"
  26. @update:newgame="openGame"
  27. @clearbet="clearBet"
  28. :betArray="betArray"
  29. :betSum="betSum"
  30. ref="gamebet"
  31. ></game-bet>
  32. <div class="m-bet-sum">
  33. {{$t('gtTips')}} {{gtRate}}GT
  34. <i class="gt-times-icon" v-if="gtRate > 1">X{{gtRate}}</i>
  35. <i class="gt-help-icon" @click="showGtRules"></i>
  36. <div class="right">
  37. {{$t('game.confirmTip')}}:{{betSum}}<i class="game-eos-icon"></i>,{{$t('game.winGt')}} {{gtGet}}<i class="game-gt-icon"></i>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="bet-sum">{{$t('game.confirmTip')}}:{{betSum}}<i class="game-eos-icon"></i>,{{$t('game.winGt')}} {{gtGet}}<i class="game-gt-icon"></i></div>
  42. </div>
  43. </template>
  44. <script>
  45. import gameHeader from './gameHeader'
  46. import gameBet from './gameBet'
  47. import typeMap from './typeMap.js'
  48. import NP from 'number-precision'
  49. import Rules from '@/components/popup/rules'
  50. import $ from 'jquery'
  51. import { funParabola } from '@/util/util'
  52. import { mapState } from 'vuex'
  53. export default {
  54. name: 'gameDeskTop',
  55. data () {
  56. return {
  57. typeMap,
  58. openArray: [],
  59. betArray: [],
  60. betNum: 1,
  61. gtGet: 0,
  62. isCounter: false,
  63. tenBetShow: false,
  64. isOpening: false // 开奖中禁止点击
  65. }
  66. },
  67. components: {
  68. gameHeader,
  69. gameBet
  70. },
  71. computed: {
  72. ...mapState({
  73. account: state => state.account,
  74. gtRate: state => state.gtRate,
  75. newOpen: state => state.newOpen,
  76. newOffer: state => state.newOffer
  77. }),
  78. betSum () {
  79. if (this.betArray.length) {
  80. let sum = 0
  81. this.betArray.forEach(x => {
  82. sum = NP.plus(sum, x.bet)
  83. })
  84. return sum / 10000
  85. } else {
  86. return 0
  87. }
  88. }
  89. },
  90. watch: {
  91. newOpen (to, from) {
  92. this.openArray.splice(0, this.openArray.length)
  93. if (to.player === this.account.name) {
  94. this.openArray = to.result.split('|')
  95. }
  96. },
  97. newOffer (to, from) {
  98. if (to.player === this.account.name) {
  99. this.gtGet = NP.times(this.betSum, this.gtRate)
  100. // 开奖禁止点击
  101. this.isOpening = true
  102. }
  103. }
  104. },
  105. methods: {
  106. // 下注
  107. betSelect (code, event) {
  108. if (this.$refs['gamebet'].tenBeting || this.isOpening) {
  109. return
  110. }
  111. if (this.betSum + this.betNum > 100) {
  112. this.$showTips(this.$t('moreBet'))
  113. return
  114. }
  115. this.betArray.push({
  116. code,
  117. bet: this.betNum * 10000
  118. })
  119. let target = event.currentTarget
  120. let flyEl, $cloneEl
  121. if (this.isCounter) {
  122. let id = `counter${this.betNum * 10}`
  123. let dom = document.getElementById(id)
  124. $cloneEl = $(dom).clone().attr('style', '')
  125. $('.counter-target-wrap').append($cloneEl)
  126. } else {
  127. let id = `counter${this.getColor(this.betNum)}`
  128. let dom = document.getElementById(id)
  129. $cloneEl = $(dom).clone().attr('style', '')
  130. $('.animate-counter-wrap').append($cloneEl)
  131. }
  132. flyEl = $cloneEl[0]
  133. flyEl.style.visibility = 'visible'
  134. let self = this
  135. funParabola(flyEl, target, {
  136. speed: 1200,
  137. curvature: 0.001,
  138. complete () {
  139. $(flyEl).remove()
  140. // 计算总数
  141. let arr = self.typeMap[code]['amount']
  142. arr.push(self.betNum)
  143. let sum = arr.reduce((prev, next) => {
  144. return NP.plus(prev, next)
  145. })
  146. self.$set(self.typeMap, code, {
  147. amount: arr,
  148. sum
  149. })
  150. }
  151. }).position().move()
  152. },
  153. getColor (betNum) {
  154. var color
  155. if (betNum < 0.5) {
  156. color = 'red'
  157. } else if (betNum >= 0.5 && betNum < 1) {
  158. color = 'blue'
  159. } else if (betNum >= 1 && betNum < 5) {
  160. color = 'pur'
  161. } else if (betNum >= 5 && betNum < 10) {
  162. color = 'green'
  163. } else if (betNum >= 10 && betNum < 20) {
  164. color = 'yellow'
  165. } else if (betNum >= 20) {
  166. color = 'orange'
  167. }
  168. return color
  169. },
  170. updateBetNum (newval) {
  171. this.betNum = newval
  172. },
  173. changeCounter (flag) {
  174. this.isCounter = flag
  175. },
  176. // 清除按钮
  177. clearBet () {
  178. for (let k in this.typeMap) {
  179. this.$set(this.typeMap, k, {
  180. amount: [],
  181. sum: 0
  182. })
  183. }
  184. this.betArray.splice(0, this.betArray.length)
  185. },
  186. showGtRules () {
  187. Rules.showGTRules()
  188. },
  189. showRules () {
  190. Rules.showRules()
  191. },
  192. openGame () {
  193. this.gtGet = 0
  194. this.clearBet()
  195. this.openArray.splice(0, this.openArray.length)
  196. this.isOpening = false
  197. }
  198. },
  199. mounted () {
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. @import 'style.scss';
  205. </style>