gameBet.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <!-- 下注 -->
  3. <div class="game-bet" :class="{'en-lang': $i18n.locale == 'en','kr-lang': $i18n.locale == 'kr'}">
  4. <!-- 开奖结果提示框 -->
  5. <div class="game-result-show" v-show="resultTipShow">
  6. <div class="game-reuslt-content">
  7. {{$t('game.resultTip.bet')}}<span class="bet-amount"> {{betSum}} </span>EOS,{{$t('game.resultTip.win')}}<span class="win-amount"> {{(winAmount > 0 ? winAmount/10000 : 0)}} </span>EOS
  8. <span class="closeResultModal" @click="resultTipShow = false">{{$t('game.resultTip.close')}}({{resultTipTime}})</span>
  9. </div>
  10. </div>
  11. <div class="bet-center-box">
  12. <div class="gt-tips">
  13. {{$t('gtTips')}} {{gtRate}} GT
  14. <i class="gt-times-icon" v-if="gtRate > 1">X{{gtRate}}</i>
  15. <i class="gt-help-icon" @click="showGtRules"></i>
  16. </div>
  17. <div class="bet-left-box">
  18. <span class="bet-tips">{{$t('game.betTip')}}</span>
  19. <div class="bet-input-wrap">
  20. <input class="bet-input" v-model.number="betNum" @input="oninput" @focus="onFocus" type="number" placeholder="請輸入籌碼">
  21. </div>
  22. </div>
  23. </div>
  24. <div class="bet-limit">
  25. <p>{{$t('k3.limit')}}:</p>
  26. <p>100 EOS</p>
  27. </div>
  28. <div class="animate-counter-wrap">
  29. <i class="animate-counter counter-pur" id="counterpur">{{this.betNum}}</i>
  30. <i class="animate-counter counter-red" id="counterred">{{this.betNum}}</i>
  31. <i class="animate-counter counter-blue" id="counterblue">{{this.betNum}}</i>
  32. <i class="animate-counter counter-green" id="countergreen">{{this.betNum}}</i>
  33. <i class="animate-counter counter-yellow" id="counteryellow">{{this.betNum}}</i>
  34. <i class="animate-counter counter-orange" id="counterorange">{{this.betNum}}</i>
  35. </div>
  36. <div class="counter-item-wrap">
  37. <div class="counter"
  38. v-for="(item, key) in counterList"
  39. :key="key"
  40. :class="[{'current': counterNum === item}, `counter-${counterColor(item)}`]"
  41. @click="changeInput(item)">
  42. {{item}}
  43. </div>
  44. </div>
  45. <div class="counter-target-wrap">
  46. <div class="counter counter-red counter-target" id="counter1">0.1</div>
  47. <div class="counter counter-blue counter-target" id="counter5">0.5</div>
  48. <div class="counter counter-pur counter-target" id="counter10">1</div>
  49. <div class="counter counter-green counter-target" id="counter50">5</div>
  50. <div class="counter counter-yellow counter-target" id="counter100">10</div>
  51. <div class="counter counter-orange counter-target" id="counter200">20</div>
  52. </div>
  53. <div class="bet-btn-wrap">
  54. <div class="clear-btn pub-btn" @click="$emit('clearbet')" :class="{'disabled': !betArray.length}">{{$t('game.clearBtn')}}</div>
  55. <div class="confirm-btn pub-btn" :class="{loading: disabledConfirm}" @click="confirmBet(1)">{{disabledConfirm ? 'Loading...' : $t('game.confirmBtn')}}</div>
  56. <div class="continute-btn pub-btn" v-if="!tenBeting" :class="{loading: disabledTen}" @click="confirmBet(10)">{{disabledTen? 'Loading...' : $t('k3.tenBet')}}</div>
  57. <div class="ten-beting-btn pub-btn" :class="{'en-btn': $i18n.locale == 'en'}" v-else>{{$t('k3.tenBetting')}}<span>{{tenTime}}/10</span></div>
  58. </div>
  59. <transition name="msgbox-fade">
  60. <ten-bet
  61. v-if="tenResult"
  62. @update:visible="endTenBet"
  63. @nextbet="nextBet"
  64. :result="tenResult"
  65. >
  66. </ten-bet>
  67. </transition>
  68. </div>
  69. </template>
  70. <script>
  71. import Rules from '@/components/popup/rules'
  72. import { mapState } from 'vuex'
  73. import { showError } from '@/util/util'
  74. import API from '@/api'
  75. import NP from 'number-precision'
  76. import tenBet from './tenBet'
  77. export default {
  78. name: 'gameMain',
  79. props: ['betArray', 'betSum'],
  80. data () {
  81. return {
  82. counterList: [0.1, 0.5, 1, 5, 10, 20],
  83. disabledConfirm: false,
  84. disabledTen: false,
  85. betNum: 1,
  86. counterNum: 0,
  87. winAmount: 0, // 赢的钱
  88. resultTipShow: false, // 提示框
  89. resultTipTime: 3, // 倒计时
  90. tenTime: 1, // 连投次数
  91. tenBeting: false,
  92. tenResult: null // 十连投结果
  93. }
  94. },
  95. components: {
  96. tenBet
  97. },
  98. computed: {
  99. ...mapState({
  100. account: state => state.account,
  101. invitee: state => state.invitee,
  102. toAccount: state => state.toAccount,
  103. gtRate: state => state.gtRate,
  104. newOpen: state => state.newOpen
  105. }),
  106. balance () {
  107. return this.$store.state.balance ? NP.divide(this.$store.state.balance, 10000) : 0
  108. }
  109. },
  110. watch: {
  111. newOpen (to, from) {
  112. if (to.player === this.account.name) {
  113. // 十连投
  114. if (to.is_finish === 1 && to.times === 10) {
  115. // 结束
  116. this.tenResult = to
  117. }
  118. if (to.times === 10) {
  119. this.tenTime = to.index
  120. this.$store.commit('updateBalance', to.win_int)
  121. }
  122. // 普通下注
  123. if (to.index === to.times && to.index === 1) {
  124. this.$hideTips()
  125. this.winAmount = to.win_int
  126. this.$store.commit('updateBalance', to.win_int)
  127. this.showResult()
  128. }
  129. }
  130. }
  131. },
  132. methods: {
  133. showGtRules () {
  134. Rules.showGTRules()
  135. },
  136. showResult () {
  137. this.resultTipShow = true
  138. let timer = setInterval(() => {
  139. this.resultTipTime--
  140. if (this.resultTipTime === 0) {
  141. this.resultTipShow = false
  142. this.resultTipTime = 3
  143. this.$emit('update:newgame')
  144. clearInterval(timer)
  145. }
  146. }, 1000)
  147. },
  148. counterColor (num) {
  149. let key = num.toString()
  150. let colorMap = {
  151. '0.1': 'red',
  152. '0.5': 'blue',
  153. '1': 'pur',
  154. '5': 'green',
  155. '10': 'yellow',
  156. '20': 'orange'
  157. }
  158. return colorMap[key]
  159. },
  160. oninput (e) {
  161. let bet = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || ''
  162. this.betNum = bet ? Number(bet) : ''
  163. if (this.betNum) {
  164. this.$emit('update:betNum', this.betNum)
  165. }
  166. },
  167. onFocus () {
  168. this.counterNum = 0
  169. this.$emit('update:counter', false)
  170. },
  171. confirmBet (time) {
  172. if (!this.account.name) {
  173. this.$store.dispatch('doScatterLogin')
  174. return
  175. }
  176. if (this.betArray.length) {
  177. time === 1 ? this.disabledConfirm = true : this.disabledTen = true // 禁止点击
  178. // 下注组合
  179. let codeArr = []
  180. let mergeObj = {}
  181. this.betArray.forEach(v => {
  182. let bet = v.bet
  183. let type = v.code
  184. // 合并处理
  185. if (mergeObj.hasOwnProperty(type)) {
  186. mergeObj[type] = mergeObj[type] + bet
  187. } else {
  188. mergeObj[type] = bet
  189. }
  190. })
  191. for (let k in mergeObj) {
  192. codeArr.push(k)
  193. codeArr.push(mergeObj[k])
  194. }
  195. let codeStr = codeArr.join('|')
  196. this.eosBet(codeStr, time)
  197. } else {
  198. this.$showTips(this.$t('noBet'))
  199. }
  200. },
  201. changeInput (item) {
  202. this.counterNum = item
  203. this.betNum = item
  204. this.$emit('update:betNum', item)
  205. this.$emit('update:counter', true)
  206. },
  207. // EOS下注
  208. eosBet (codeStr, time) {
  209. // 余额不足
  210. if (this.balance < NP.times(this.betSum, time)) {
  211. this.$showTips(this.$t('noMoney'))
  212. time === 1 ? this.disabledConfirm = false : this.disabledTen = false
  213. return
  214. }
  215. let invitee = this.invitee || 0
  216. let memo = `k3|${invitee}|${time}|${codeStr}`
  217. let EOS = NP.times(this.betSum, time).toFixed(4)
  218. let identity = { authorization: [`${this.account.name}@${this.account.authority}`] }
  219. this.$showLoading()
  220. // 调起转账
  221. window.EOS.transfer(this.account.name, 'eosgetdice12', EOS + ' EOS', memo, identity).then(trx => {
  222. let param = {
  223. transaction_id: trx.transaction_id,
  224. block_num: trx.processed.block_num ? trx.processed.block_num : '',
  225. player: this.account.name
  226. }
  227. let oneAmount = NP.times(this.betSum, 10000)
  228. let balanceAmount = NP.times(oneAmount, time)
  229. API.game.sendTrx(param).then(({ data }) => {
  230. if (data.result === 1) {
  231. // 数目增减
  232. this.$store.commit('updateBalance', -balanceAmount)
  233. let eosAmount = NP.divide(balanceAmount, 10000)
  234. this.$store.commit('updateGt', NP.times(this.gtRate, eosAmount))
  235. // 十连投
  236. if (time === 10) {
  237. this.tenBeting = true
  238. } else {
  239. this.$showTips(this.$t('waiting'), false)
  240. }
  241. }
  242. }).finally(() => {
  243. time === 1 ? this.disabledConfirm = false : this.disabledTen = false
  244. this.$hideLoading()
  245. })
  246. }).catch(msg => {
  247. time === 1 ? this.disabledConfirm = false : this.disabledTen = false
  248. this.$hideLoading()
  249. if (msg.type === 'signature_rejected') {
  250. this.$showTips(this.$t('failBet'))
  251. } else {
  252. let json = JSON.parse(msg)
  253. let details = json.error.details
  254. showError(details[0].message)
  255. }
  256. // 十连投继续下注拒绝处理
  257. if (this.tenBeting) {
  258. this.endTenBet()
  259. localStorage.removeItem('ten_ben_checked')
  260. }
  261. })
  262. },
  263. endTenBet () {
  264. this.tenResult = null
  265. this.tenBeting = false
  266. this.tenTime = 1
  267. this.$emit('update:newgame')
  268. },
  269. nextBet () {
  270. this.tenResult = null
  271. this.tenTime = 1
  272. this.confirmBet(10)
  273. }
  274. }
  275. }
  276. </script>