auctionModal.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <template>
  2. <div class="game-notice-mask">
  3. <div class="game-auction-modal">
  4. <div class="auction-boder-wrap">
  5. <div class="auction-title">
  6. <!-- <i></i> -->
  7. {{$t('auction.title')}}
  8. <i class="auction-help-icon" @click="explainShow = true"></i>
  9. </div>
  10. <i class="close-icon" @click="closemodal"></i>
  11. <div class="game-modal">
  12. <div class="win-wrap">
  13. <template v-if="auctionInfo">
  14. <div class="row" v-if="auctionInfo.lastTrx">{{$t('auction.text1')}}:{{auctionInfo.lastTrx.player}}</div>
  15. <div class="row" v-else>{{$t('auction.text1')}}:</div>
  16. <div class="row-bot" v-if="auctionInfo.lastTrx">{{$t('auction.text2')}} {{auctionInfo.lastTrx.gt_amount / 10000}} GT {{$t('auction.text3')}} {{auctionInfo.lastTrx.return_eos / 10000}} EOS</div>
  17. <div class="row-bot" v-else>{{$t('auction.text2')}} - GT {{$t('auction.text3')}} - EOS</div>
  18. </template>
  19. </div>
  20. <div class="auc-bg">
  21. <div class="auc-top">
  22. <span class="acu-top-left">{{$t('auction.title')}} #{{auctionInfo.actId}}</span>
  23. <span class="auc-top-tips">{{$t('auction.modalTips')}}</span>
  24. <span class="auc-time-right">
  25. <i class="time-count-icon"></i>
  26. {{timeStr}}
  27. </span>
  28. </div>
  29. <div class="auc-mid">
  30. <img class="eos-icon" src="../../assets/icon_b_eos_mii.png" alt="">
  31. <p class="amount">{{auctionInfo.prize / 10000}} EOS</p>
  32. </div>
  33. <div class="auc-bot">
  34. <div class="auc-bot-item">
  35. <p class="auc-bot-title">{{$t('auction.lastPrice')}}:</p>
  36. <div class="auc-bot-row">
  37. <template v-if="lastBid && !firstTime">
  38. <p>{{lastBid.player}}</p>
  39. <p>{{originAmount}} GT</p>
  40. <p>{{lastBid.create_time_human}}</p>
  41. </template>
  42. <template v-else>
  43. <p>---</p>
  44. <p>---</p>
  45. <p>---</p>
  46. </template>
  47. </div>
  48. </div>
  49. <div class="auc-bot-item">
  50. <p class="auc-bot-title">{{$t('auction.text4')}}:</p>
  51. <div class="auc-bot-input">
  52. <div class="auc-input-box">
  53. <input class="input-wrap" readonly @input="handleInput" type="number" v-model.number="gtAmount">
  54. <i>GT</i>
  55. </div>
  56. <button :class="{'current': btn1Click}" @click="changeAmount(1.25, 1)">+25%</button>
  57. <!-- <button :class="{'current': btn2Click}" @click="changeAmount(1.5, 2)">+50%</button> -->
  58. </div>
  59. </div>
  60. </div>
  61. <div class="auc-btn" :class="{'diasble' : disableBtn || auctionInfo.prize < 500000}" @click="confirmBtn">{{$t('auction.confirmBtn')}}</div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- 解析弹窗 -->
  67. <div class="modal-mask" v-show="explainShow">
  68. <div class="overflow-modal">
  69. <div class="title">{{$t('auction.title')}}</div>
  70. <i class="close-icon" @click="explainShow = false"></i>
  71. <div class="game-modal">
  72. <div class="list-item">
  73. <span class="order">*.</span>
  74. <div class="text-wrap">
  75. <p class="text">{{$t('auction.explain0')}}</p>
  76. </div>
  77. </div>
  78. <div class="list-item">
  79. <span class="order">1.</span>
  80. <div class="text-wrap">
  81. <p class="text">{{$t('auction.explain1')}}</p>
  82. </div>
  83. </div>
  84. <div class="list-item">
  85. <span class="order">2.</span>
  86. <div class="text-wrap">
  87. <p class="text">{{$t('auction.explain2')}}</p>
  88. </div>
  89. </div>
  90. <div class="list-item">
  91. <span class="order">3.</span>
  92. <p class="item-text">{{$t('auction.explain3')}}</p>
  93. </div>
  94. <div class="list-item">
  95. <span class="order">4.</span>
  96. <p class="item-text">{{$t('auction.explain4')}}</p>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </template>
  103. <script>
  104. import NP from 'number-precision'
  105. import { showError } from '../../util/util.js'
  106. import Bus from '../../js/bus'
  107. import API from '@/api'
  108. import { mapState } from 'vuex'
  109. export default {
  110. name: 'auction',
  111. data () {
  112. return {
  113. gtAmount: null, // 出价
  114. originAmount: null, // 原价
  115. lastBid: null,
  116. btn1Click: false,
  117. btn2Click: false,
  118. timeStr: '',
  119. rewardShow: false, // 领取奖励提示框
  120. rewardRec: null, // 用户获奖记录
  121. explainShow: false, // 说明弹窗
  122. firstTime: true
  123. }
  124. },
  125. computed: {
  126. eos () {
  127. return this.$store.state.eos
  128. },
  129. account () {
  130. return this.$store.state.account
  131. },
  132. gt () {
  133. return this.$store.state.gt
  134. },
  135. identity () {
  136. return { authorization: [`${this.account.name}@${this.account.authority}`] }
  137. },
  138. disableBtn () {
  139. if (!this.firstTime) {
  140. if (this.originAmount && this.gtAmount) {
  141. return Number(this.gtAmount) < NP.times(this.originAmount, 1.25)
  142. } else {
  143. return true
  144. }
  145. } else {
  146. return false
  147. }
  148. },
  149. ...mapState({
  150. eos: state => state.eos,
  151. account: state => state.account,
  152. gt: state => state.gt,
  153. auctionInfo: state => state.auctionInfo
  154. })
  155. },
  156. watch: {
  157. auctionInfo (to, from) {
  158. this.lastBid = to.lastBid
  159. let toGtAmount = to.lastBid.gt_amount / 10000
  160. if (toGtAmount !== this.originAmount) {
  161. this.gtAmount = toGtAmount
  162. this.originAmount = Number(toGtAmount)
  163. this.btn1Click = false
  164. this.btn2Click = false
  165. }
  166. if (!to.lastBid.player) {
  167. this.firstTime = true
  168. } else {
  169. this.firstTime = false
  170. }
  171. }
  172. },
  173. methods: {
  174. handleInput (e) {
  175. let val = e.target.value
  176. if (val === NP.times(this.originAmount, 1.25)) {
  177. this.btn1Click = true
  178. return
  179. }
  180. if (val === NP.times(this.originAmount, 1.5)) {
  181. this.btn2Click = true
  182. return
  183. }
  184. this.btn1Click = false
  185. this.btn2Click = false
  186. },
  187. closemodal () {
  188. this.$emit('closeaucmodal')
  189. },
  190. changeAmount (per, type) {
  191. if (type === 1) {
  192. if (!this.btn1Click) {
  193. this.gtAmount = Math.ceil(NP.times(this.originAmount, per))
  194. this.btn1Click = true
  195. this.btn2Click = false
  196. } else {
  197. this.gtAmount = this.originAmount
  198. this.btn1Click = false
  199. }
  200. }
  201. if (type === 2) {
  202. if (!this.btn2Click) {
  203. this.gtAmount = Math.ceil(NP.times(this.originAmount, per))
  204. this.btn2Click = true
  205. this.btn1Click = false
  206. } else {
  207. this.gtAmount = this.originAmount
  208. this.btn2Click = false
  209. }
  210. }
  211. },
  212. // 确认竞拍
  213. confirmBtn () {
  214. if (!this.account.name) {
  215. this.$store.dispatch('doScatterLogin')
  216. return
  217. }
  218. if (this.gtAmount > this.gt) {
  219. this.$showTips(this.$t('noMoney'))
  220. return
  221. }
  222. var doAction = (params) => {
  223. API.auction.sendTrx(params)
  224. .then(({ data }) => {
  225. this.$hideLoading()
  226. if (data.code === 0) {
  227. this.$store.commit('updateGt', -this.gtAmount)
  228. this.$showTips(this.$t('auction.success'))
  229. this.btn1Click = false
  230. this.btn2Click = false
  231. this.getAuctionInfo()
  232. } else if (data.code === 5) {
  233. this.$store.dispatch('doGameLogin').then(data => {
  234. this.confirmBtn()
  235. })
  236. }
  237. }).catch(() => {
  238. this.$hideLoading()
  239. })
  240. }
  241. this.$showLoading()
  242. let chargeAmount = this.gtAmount.toFixed(4) + ' GT'
  243. let memo = 'auction|' + this.lastBid.act_id
  244. window.EOS.contract('eosgetgtoken').then(contract => {
  245. contract.transfer(this.account.name, 'eosgetadmin1', chargeAmount, memo, this.identity)
  246. .then(trx => {
  247. doAction({
  248. transaction_id: trx.transaction_id,
  249. block_num: trx.processed.block_num ? trx.processed.block_num : '',
  250. player: this.account.name
  251. })
  252. })
  253. .catch(msg => {
  254. this.$hideLoading()
  255. if (msg.type === 'signature_rejected') {
  256. return
  257. }
  258. let json = JSON.parse(msg)
  259. let details = json.error.details
  260. showError(details[0].message)
  261. })
  262. })
  263. },
  264. // 获取奖池信息
  265. getAuctionInfo () {
  266. let params = {
  267. player: this.account.name || null
  268. }
  269. API.auction.getAuctionInfo(params).then(({ data }) => {
  270. if (data.code === 0) {
  271. this.lastBid = data.data.lastBid
  272. this.gtAmount = data.data.lastBid.gt_amount / 10000
  273. this.originAmount = Number(this.gtAmount)
  274. if (data.data.lastBid.player) {
  275. this.firstTime = false
  276. }
  277. } else if (data.code === -5) {
  278. this.$store.dispatch('doGameLogin').then(data => {
  279. this.getAuctionInfo()
  280. })
  281. }
  282. })
  283. }
  284. },
  285. created () {
  286. this.getAuctionInfo()
  287. // 倒计时
  288. Bus.$on('update:time', (time, ttl) => {
  289. this.timeStr = time
  290. if (ttl < 0) {
  291. this.timeStr = '结算中'
  292. }
  293. })
  294. },
  295. beforeDestroy () {
  296. Bus.$off('update:time')
  297. }
  298. }
  299. </script>
  300. <style lang="scss">
  301. .game-notice-mask{
  302. overflow-y: auto;
  303. }
  304. .game-auction-modal{
  305. background-color: #1b1b1a;
  306. position: absolute;
  307. left: 50%;
  308. margin-left: -px2rem(365);
  309. // width: px2rem(820);
  310. width: px2rem(730);
  311. top: px2rem(60);
  312. @media #{$phone} {
  313. top: px2rem(200);
  314. }
  315. .auc-btn{
  316. width: px2rem(112);
  317. height: px2rem(46);
  318. background: url('../../assets/but_y01_1.png') no-repeat;
  319. background-size: 100%;
  320. line-height: px2rem(50);
  321. text-align: center;
  322. color: #50370b;
  323. font-size: px2rem(24);
  324. margin: px2rem(20) auto 0 auto;
  325. border-radius: 6px;
  326. cursor: pointer;
  327. &:hover{
  328. background: url('../../assets/but_y01_2.png') no-repeat;
  329. background-size: 100%;
  330. }
  331. &.diasble{
  332. pointer-events: none;
  333. background-color: #a1a1a1;
  334. background-image: none;
  335. color: #ffffff;
  336. }
  337. }
  338. .auc-bg{
  339. background: url('../../assets/bg_gold.png') center bottom no-repeat;
  340. width: px2rem(730);
  341. background-size: contain;
  342. margin: 0 auto px2rem(20) auto;
  343. overflow: hidden;
  344. padding: 0 px2rem(30);
  345. box-sizing: border-box;
  346. // @media #{$phone} {
  347. // padding: 0 px2rem(10);
  348. // }
  349. .auc-top{
  350. font-size: px2rem(18);
  351. margin-top: px2rem(10);
  352. height: px2rem(36);
  353. color: #999999;
  354. position: relative;
  355. .auc-top-tips{
  356. position: absolute;
  357. left: px2rem(100);
  358. right: px2rem(100);
  359. bottom: 0;
  360. text-align: center;
  361. height: px2rem(36);
  362. line-height: px2rem(36);
  363. }
  364. }
  365. .auc-mid{
  366. text-align: center;
  367. position: relative;
  368. }
  369. .eos-icon{
  370. display: block;
  371. width: px2rem(180);
  372. margin: 0 auto;
  373. }
  374. .amount{
  375. position: absolute;
  376. bottom: -px2rem(10);
  377. left: 0;
  378. right: 0;
  379. font-size: px2rem(36);
  380. color: #d7ac68;
  381. }
  382. }
  383. .auc-input-box{
  384. position: relative;
  385. display: inline-block;
  386. vertical-align: top;
  387. >i{
  388. position: absolute;
  389. top: px2rem(14);
  390. right: px2rem(14);
  391. font-style: normal;
  392. font-size: px2rem(24);
  393. color: #fff;
  394. line-height: 1;
  395. }
  396. }
  397. .auc-bot{
  398. // margin-top: px2rem(20);
  399. &-item{
  400. font-size: px2rem(18);
  401. margin-bottom: px2rem(10);
  402. .auc-bot-title{
  403. color: #999999;
  404. margin-bottom: px2rem(6);
  405. }
  406. p{
  407. color: #ffffff;
  408. }
  409. }
  410. &-row{
  411. background-color: rgba($color: #000000, $alpha: .6);
  412. border: 1px solid #594a34;
  413. height: px2rem(44);
  414. line-height: px2rem(44);
  415. display: flex;
  416. padding: 0 px2rem(14);
  417. margin-top: px2rem(4);
  418. p{
  419. flex: 1;
  420. text-align: center;
  421. &:first-child{
  422. text-align: left;
  423. }
  424. &:last-child{
  425. text-align: right;
  426. }
  427. }
  428. }
  429. }
  430. .auc-time-right{
  431. width: px2rem(120);
  432. height: px2rem(36);
  433. line-height: px2rem(36);
  434. text-align: center;
  435. color: #999999;
  436. font-size: px2rem(20);
  437. float: right;
  438. .time-count-icon{
  439. display: inline-block;
  440. vertical-align: middle;
  441. background: url('../../assets/iocn_time.png') no-repeat;
  442. background-size: 100%;
  443. width: px2rem(26);
  444. height: px2rem(36);
  445. }
  446. }
  447. .acu-top-left{
  448. display: inline-block;
  449. height: px2rem(36);
  450. line-height: px2rem(36);
  451. // margin-top: px2rem(6);
  452. }
  453. .game-modal{
  454. height: auto;
  455. margin-top: 0;
  456. overflow: hidden;
  457. padding-left: 0;
  458. padding-right: 0;
  459. }
  460. .auction-help-icon{
  461. display: inline-block;
  462. vertical-align: middle;
  463. background: url('img/icon_question.png');
  464. background-size: 100%;
  465. width: px2rem(24);
  466. height: px2rem(24);
  467. right: px2rem(300);
  468. top: px2rem(30);
  469. cursor: pointer;
  470. @media #{$phone} {
  471. display: none;
  472. }
  473. }
  474. .title{
  475. font-size: px2rem(30);
  476. i{
  477. display: inline-block;
  478. vertical-align: middle;
  479. background: url('img/icon_jingpai.png') no-repeat;
  480. margin-right: px2rem(10);
  481. background-size: 100%;
  482. width: px2rem(35);
  483. height: px2rem(33);
  484. }
  485. }
  486. .win-wrap{
  487. width: px2rem(666);
  488. height: px2rem(80);
  489. line-height: 1;
  490. margin: 0 auto;
  491. background-color: #161615;
  492. border: 1px solid #262625;
  493. padding: px2rem(18) px2rem(30);
  494. box-sizing: border-box;
  495. font-size: px2rem(18);
  496. .row{
  497. color: #999999;
  498. margin-bottom: px2rem(12);
  499. }
  500. .row-bot{
  501. color: #d7ac68;
  502. }
  503. }
  504. .auction-title{
  505. height: px2rem(50);
  506. line-height: px2rem(50);
  507. border-bottom: 1px solid #d7ac68;
  508. text-align: center;
  509. font-size: px2rem(24);
  510. color: #ffffff;
  511. }
  512. .auc-bot-input{
  513. font-size: 0;
  514. line-height: 1;
  515. .input-wrap{
  516. display: inline-block;
  517. vertical-align: top;
  518. background-color: rgba($color: #000000, $alpha: .6);
  519. height: px2rem(44);
  520. line-height: px2rem(44);
  521. border: 1px solid #594a34;
  522. box-sizing: border-box;
  523. outline: none;
  524. width: px2rem(440);
  525. font-size: px2rem(24);
  526. color: #fff;
  527. padding-left: px2rem(16);
  528. }
  529. button{
  530. outline: none;
  531. text-align: center;
  532. color: #ffffff;
  533. background-color: rgba($color: #000000, $alpha: .8);
  534. border: 1px solid #594a34;
  535. height: px2rem(44);
  536. line-height: px2rem(44);
  537. width: px2rem(220);
  538. font-size: px2rem(24);
  539. margin-left: px2rem(8);
  540. cursor: pointer;
  541. &.current{
  542. background-color: #a48642;
  543. }
  544. // &:last-child{
  545. // border-top-right-radius: 6px;
  546. // border-bottom-right-radius: 6px;
  547. // }
  548. }
  549. }
  550. }
  551. .auction-boder-wrap{
  552. // border: 6px solid #19274e;
  553. // border-radius: 12px;
  554. }
  555. .game-notice-mask{
  556. position: fixed;
  557. top: 0;
  558. left: 0;
  559. right: 0;
  560. bottom: 0;
  561. z-index: 199;
  562. background-color: rgba($color: #000000, $alpha: .8);
  563. .game-modal{
  564. padding-top: px2rem(10);
  565. // margin-top: px2rem(20);
  566. overflow-y: auto;
  567. box-sizing: border-box;
  568. width: 100%;
  569. position: relative;
  570. &::-webkit-scrollbar {
  571. width: 10px;
  572. }
  573. &::-webkit-scrollbar-thumb {
  574. border-radius: 12px;
  575. background: rgba(#222222, 0.6);
  576. }
  577. }
  578. .close-icon{
  579. position: absolute;
  580. z-index: 10;
  581. cursor: pointer;
  582. background: url('../../assets/关闭@2x.png') center center no-repeat;
  583. background-size: px2rem(20) px2rem(20);
  584. width: px2rem(40);
  585. height: px2rem(40);
  586. background-color: rgba($color: #000000, $alpha: .6);
  587. top: px2rem(4);
  588. right: px2rem(4);
  589. &:hover{
  590. background-color: rgba($color: #000000, $alpha: .4);
  591. }
  592. }
  593. .title{
  594. position: absolute;
  595. width: px2rem(254);
  596. height: px2rem(70);
  597. background-size: 100%;
  598. top: px2rem(6);
  599. left: 50%;
  600. margin-left: -px2rem(127);
  601. font-size: px2rem(24);
  602. color: #ffffff;
  603. text-align: center;
  604. line-height: px2rem(70);
  605. z-index: 10;
  606. }
  607. }
  608. .modal-mask{
  609. position: fixed;
  610. top: 0;
  611. left: 0;
  612. right: 0;
  613. bottom: 0;
  614. z-index: 199;
  615. background-color: rgba($color: #000000, $alpha: .8);
  616. .overflow-modal{
  617. position: absolute;
  618. left: 50%;
  619. top: 50%;
  620. background: url('img/modal-board.png') no-repeat;
  621. background-size: 100%;
  622. width: px2rem(1188);
  623. height: px2rem(547);
  624. transform: translate(-50%, -50%);
  625. }
  626. .game-modal{
  627. padding: px2rem(80) px2rem(70);
  628. height: px2rem(500);
  629. margin-top: px2rem(20);
  630. overflow-y: auto;
  631. box-sizing: border-box;
  632. width: 100%;
  633. position: relative;
  634. &::-webkit-scrollbar {
  635. width: 10px;
  636. }
  637. &::-webkit-scrollbar-thumb {
  638. border-radius: 12px;
  639. background: rgba(#222222, 0.6);
  640. }
  641. }
  642. .close-icon{
  643. position: absolute;
  644. z-index: 10;
  645. cursor: pointer;
  646. background: url('img/but_closed01_up.png') center center no-repeat;
  647. background-size: 100%;
  648. width: px2rem(88);
  649. height: px2rem(58);
  650. top: px2rem(33);
  651. right: -px2rem(78);
  652. &:hover{
  653. background: url('img/but_closed01_down.png') center center no-repeat;
  654. background-size: 100%;
  655. }
  656. }
  657. .title{
  658. position: absolute;
  659. background: url('img/tit_01.png');
  660. width: px2rem(254);
  661. height: px2rem(70);
  662. background-size: 100%;
  663. top: px2rem(6);
  664. left: 50%;
  665. margin-left: -px2rem(127);
  666. font-size: px2rem(30);
  667. color: #ffffff;
  668. text-align: center;
  669. line-height: px2rem(70);
  670. z-index: 10;
  671. }
  672. .counter-title{
  673. text-align: center;
  674. color: #ffffff;
  675. margin-bottom: 20px;
  676. p{
  677. font-size: 30px;
  678. font-weight: bold;
  679. display: inline-block;
  680. padding: 0 5px;
  681. border-bottom: 2px solid #ffffff;
  682. }
  683. }
  684. .list-item{
  685. display: flex;
  686. font-size: px2rem(24);
  687. color: #ffffff;
  688. margin-bottom: 8px;
  689. line-height: 1.6;
  690. text-align: left;
  691. .order{
  692. width: 26px;
  693. }
  694. .item-text{
  695. flex: 1;
  696. }
  697. .text-wrap{
  698. flex: 1;
  699. a{
  700. color: #f1e000;
  701. }
  702. }
  703. }
  704. }
  705. </style>