charge.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <transition name="msgbox-fade">
  3. <div class="popup-wrap" v-if="showCharge">
  4. <div class="popup-modal"></div>
  5. <div class="popup-box">
  6. <div class="popup-hd">
  7. <div class="popup-hd-title"><em>{{$t('popupCharge.title1')}}</em></div>
  8. <span class="popup-close" @click="showCharge = false"></span>
  9. </div>
  10. <div class="popup-bd">
  11. <div class="charge-wrap">
  12. <h3>{{$t('popupCharge.title1')}}EOS</h3>
  13. <div class="c-input">
  14. <input type="text" v-model="amount" @input="onInput">
  15. <span>EOS</span>
  16. </div>
  17. <p class="c-tips1">
  18. 1. {{$t('popupCharge.content1')}}.<br/>
  19. 2. {{$t('popupCharge.content2')}}.
  20. </p>
  21. <div class="c-ctrl">
  22. <span class="btn-confirm" @click="confirmCharge()">{{$t('popupCharge.btn1')}}</span>
  23. </div>
  24. <p class="c-tips2">
  25. <span @click="showDetail()">{{$t('popupCharge.btn2')}}</span>
  26. </p>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="popup-wrap" v-if="showWallet">
  32. <div class="popup-modal"></div>
  33. <div class="popup-box">
  34. <div class="popup-hd">
  35. <div class="popup-hd-title"><em>{{$t('popupCharge.text1')}}</em></div>
  36. <span class="popup-close" @click="showWallet = false"></span>
  37. </div>
  38. <div class="popup-bd">
  39. <div class="wallet-wrap">
  40. <div class="wallet-hd">
  41. <p>{{account.name}}</p>
  42. </div>
  43. <div class="wallet-bd">
  44. <div class="bd-con">
  45. <h4>{{$t('popupCharge.text1')}}</h4>
  46. <p><i></i>{{money}}</p>
  47. </div>
  48. <p class="bd-tips">{{$t('popupCharge.content3')}}{{leftTimes}}</p>
  49. </div>
  50. <div class="wallet-ft">
  51. <div class="ft-row1">
  52. <span class="btn-out" @click="handleWithDraw()">{{$t('popupCharge.btn3')}}</span>
  53. <span class="btn-in" @click="handleCharge()">{{$t('popupCharge.title1')}}</span>
  54. </div>
  55. <div class="ft-row2">
  56. <span @click="showDetail()">{{$t('popupCharge.btn2')}}</span>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </transition>
  64. </template>
  65. <script>
  66. import { mapState } from 'vuex'
  67. import API from '@/api'
  68. import Detail from '@/components/popup/detail'
  69. // import NP from 'number-precision'
  70. import { MessageBox } from 'element-ui'
  71. // import { showError } from '@/util/util.js'
  72. // import { deposit } from '@/util/contract.js'
  73. export default {
  74. name: 'popupCharge',
  75. data () {
  76. return {
  77. amount: null, // 用户输入的充值金额
  78. leftTimes: null, // 用户每天剩余的提现次数
  79. showWallet: false,
  80. showCharge: false
  81. }
  82. },
  83. computed: {
  84. ...mapState({
  85. eos: state => state.eos,
  86. account: state => state.account,
  87. balance: state => state.balance / 10000,
  88. money: state => state.money / 10000,
  89. gt: state => state.gt,
  90. toAccount: state => state.toAccount
  91. })
  92. },
  93. created () {
  94. API.eos.getLeftTimes({ player: this.account.name }).then(({ data }) => {
  95. if (data.code === 0) {
  96. this.leftTimes = data.data
  97. }
  98. })
  99. },
  100. methods: {
  101. onInput (e) {
  102. let bet = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || ''
  103. bet = bet ? Number(bet) : ''
  104. this.amount = bet > this.balance ? this.balance : bet
  105. },
  106. confirmCharge () {
  107. if (this.amount > this.balance) {
  108. return
  109. }
  110. this.$showLoading()
  111. this.$store.dispatch('doDeposit', {
  112. amount: this.amount,
  113. callback: () => {
  114. this.$hideLoading()
  115. this.amount = null
  116. this.handleWallet()
  117. localStorage.setItem('showFTips', 0)
  118. },
  119. cancel: () => {
  120. this.$hideLoading()
  121. }
  122. })
  123. },
  124. handleWithDraw () {
  125. if (!this.money) {
  126. return
  127. }
  128. let that = this
  129. this.$showLoading()
  130. API.game.getBalance({
  131. player: this.account.name
  132. }).then(({ data }) => {
  133. this.$store.commit('setMoney', data.data.balance)
  134. // let amount = this.money
  135. // this.$store.dispatch('doWithDraw', {
  136. // callback: () => {
  137. // this.$hideLoading()
  138. // MessageBox.confirm(`成功提现 ${amount} EOS`, '提示', {
  139. // showCancelButton: false,
  140. // showConfirmButton: true,
  141. // center: true,
  142. // callback () {
  143. // }
  144. // })
  145. // this.leftTimes -= 1
  146. // localStorage.setItem('showFTips', 0)
  147. // },
  148. // cancel: () => {
  149. // this.$hideLoading()
  150. // }
  151. // })
  152. let tranFormAmount = data.data.balance
  153. let param = {
  154. player: this.account.name,
  155. amount: tranFormAmount,
  156. appid: this.$store.state.appid
  157. }
  158. this.$showLoading()
  159. API.eos.withDraw(param).then(({ data }) => {
  160. this.$hideLoading()
  161. console.log(data.code)
  162. if (data.code === 0) {
  163. MessageBox.confirm(`成功提现 ${this.money} EOS`, '提示', {
  164. showCancelButton: false,
  165. showConfirmButton: true,
  166. center: true,
  167. callback () {
  168. that.$store.commit('updateBalance', tranFormAmount)
  169. that.$store.commit('updateMoney', -tranFormAmount)
  170. that.leftTimes -= 1
  171. }
  172. })
  173. localStorage.setItem('showFTips', 0)
  174. } else if (data.code === -90001) {
  175. // 用户未关闭自动下注,弹窗提示
  176. that.showWarn()
  177. }
  178. }).catch(() => {
  179. this.$hideLoading()
  180. })
  181. })
  182. },
  183. /**
  184. * 显示充值界面
  185. */
  186. handleCharge () {
  187. this.showWallet = false
  188. this.showCharge = true
  189. },
  190. /**
  191. * 显示余额界面
  192. */
  193. handleWallet () {
  194. this.showWallet = true
  195. this.showCharge = false
  196. },
  197. /**
  198. * 隐藏所有
  199. */
  200. hide () {
  201. this.showWallet = false
  202. this.showCharge = false
  203. },
  204. /**
  205. * 显示明细列表
  206. */
  207. showDetail () {
  208. this.hide()
  209. Detail.show()
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss">
  215. @import "./style.scss";
  216. </style>