recharge.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div class="assets">
  3. <div class="head">
  4. <img @click="back" src="@/assets/images/back.png" class="arrow_img" />
  5. <span>{{ $t('lang138') }}</span>
  6. </div>
  7. <div class="pd">
  8. <div class="">
  9. <div class="total_box">
  10. <div>
  11. <span class="text">{{ $t('lang147') }}</span>
  12. </div>
  13. <div class="total">
  14. <span>{{ Math.floor(assets * 100) / 100 || 0 }}</span>
  15. </div>
  16. <div class="bo">
  17. <!-- <img src="@/assets/images/chance.png" class="icon" />
  18. <span>{{ $t('lang121') }}</span> -->
  19. </div>
  20. <div @click="navigation('rechargeRecord')" class="mx">{{ $t('lang122') }}</div>
  21. </div>
  22. <div class="list">
  23. <div class="box">
  24. <div class="box_item">
  25. <span class="left">{{ $t('lang124') }}</span>
  26. <span>{{ $t('lang126') }}(BEP20)</span>
  27. </div>
  28. <div class="box_item">
  29. <span class="left">{{ $t('lang477') }}</span>
  30. <span class="walletbalance">{{ walletBalance }}</span>
  31. </div>
  32. <div class="box_item">
  33. <span class="left">{{ $t('lang148') }}</span>
  34. <van-field v-model="amount" :placeholder="$t('lang119')" type="number" class="input" input-align="right" />
  35. </div>
  36. <!-- <div class="box_item">
  37. <span class="left">{{ $t('lang125') }}</span>
  38. <van-field v-model="value" :placeholder="$t('lang118')" class="input" input-align="right" />
  39. </div> -->
  40. </div>
  41. </div>
  42. <div class="buy" @click="submit">
  43. <van-button class="buy_btn" type="primary">{{ $t('lang149') }}</van-button>
  44. </div>
  45. <div class="tips">
  46. <div>{{ $t('lang116') }}</div>
  47. <div v-html="tip"></div>
  48. </div>
  49. </div>
  50. </div>
  51. <van-overlay :show="show">
  52. <div class="wrapper" @click.stop>
  53. <van-loading type="spinner" class="loading" />
  54. </div>
  55. </van-overlay>
  56. </div>
  57. </template>
  58. <script>
  59. import { homeApi } from '@/api/index';
  60. import { dateFormat } from '@/utils/formatTool.js';
  61. import packApi from '@/methods/pack.js';
  62. import { getErc20Contract } from '@/utils/contractHelp';
  63. import usdt from '@/methods/usdt.js';
  64. import { formatAmount } from '@/utils/format.js';
  65. import { Dialog, Notify, Toast } from 'vant';
  66. export default {
  67. data() {
  68. return {
  69. assets: 0,
  70. amount: '',
  71. payToken: undefined, //支付币种
  72. walletBalance: 0,
  73. show: false,
  74. pay_address: '',
  75. tip: '',
  76. };
  77. },
  78. mounted() {
  79. this.getUserInfo();
  80. this.getAddress();
  81. },
  82. methods: {
  83. //返回上一页
  84. back() {
  85. this.$router.back();
  86. },
  87. navigation(name) {
  88. this.$router.push({ name });
  89. },
  90. getAddress() {
  91. homeApi.getAddress().then(res => {
  92. if (res.code == 200) {
  93. console.log(res.data);
  94. this.pay_address = res.data.value;
  95. this.tip = res.data.name;
  96. } else {
  97. }
  98. });
  99. },
  100. getUserInfo() {
  101. homeApi.getUserInfo().then(res => {
  102. if (res.code == 200) {
  103. this.assets = res.data.balance;
  104. this.account = res.data.address;
  105. this.getPayToken(); //获取支付币种
  106. }
  107. });
  108. },
  109. getPayToken() {
  110. packApi.getPayToken(this.account).then(res => {
  111. this.payToken = res;
  112. // this.handleApproveBtnShow(); //获取授权余额
  113. this.getWalletBalance(); //获取钱包余额
  114. });
  115. },
  116. // 查询链上钱包余额
  117. async getWalletBalance() {
  118. const erc20Contract = getErc20Contract(this.payToken);
  119. let bal = await erc20Contract.methods.balanceOf(this.account).call();
  120. this.walletBalance = (formatAmount(bal, 18) * 1).toFixed(5);
  121. },
  122. submit() {
  123. if (!this.amount) {
  124. return this.$toast(this.$t('lang160'));
  125. }
  126. if (Number(this.walletBalance) < Number(this.amount)) {
  127. return this.$toast(this.$t('lang159').replace('XX', this.amount).replace('CC', this.walletBalance));
  128. }
  129. this.show = true;
  130. usdt
  131. .transfer(this.account, this.pay_address, this.amount, this.payToken)
  132. .then(res => {
  133. // 调回调接口
  134. let params = {
  135. amount: this.amount,
  136. tx_hash: res,
  137. };
  138. homeApi
  139. .updateOrder(params)
  140. .then(res => {
  141. if (res.code == 200) {
  142. this.amount = '';
  143. this.show = false;
  144. Notify({ type: 'success', message: this.$t('lang152') });
  145. this.getUserInfo();
  146. } else {
  147. this.show = false;
  148. Toast({ message: `${res.msg}` });
  149. }
  150. })
  151. .catch(err => {
  152. this.show = false;
  153. this.$toast(err.msg);
  154. return;
  155. });
  156. })
  157. .catch(err => {
  158. this.show = false;
  159. this.$toast(err.message);
  160. return;
  161. });
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="less" scoped>
  167. .head {
  168. position: fixed;
  169. top: 0;
  170. left: 0;
  171. width: 100%;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. color: rgba(#000, 0.8);
  176. letter-spacing: 1.5px;
  177. font-weight: 550;
  178. background: #fff;
  179. padding: 15px 0;
  180. // z-index: 99;
  181. .arrow_img {
  182. position: absolute;
  183. left: 20px;
  184. width: 10px;
  185. height: 16px;
  186. // transform: translate(0, -50%);
  187. }
  188. }
  189. .f-sb {
  190. display: flex;
  191. align-items: center;
  192. justify-content: space-between;
  193. }
  194. .f-sa {
  195. display: flex;
  196. align-items: center;
  197. justify-content: space-around;
  198. }
  199. .f-sb-n {
  200. display: flex;
  201. align-items: flex-end;
  202. justify-content: space-between;
  203. }
  204. .f-col {
  205. display: flex;
  206. flex-direction: column;
  207. }
  208. .assets {
  209. min-height: 100vh;
  210. padding: 50px 0 0;
  211. // background-color: #fafbfc;
  212. .top {
  213. color: #000;
  214. padding-bottom: 16px;
  215. margin: 0 6px;
  216. }
  217. .pd {
  218. padding: 4px;
  219. margin-top: 4px;
  220. // background-color: #fff;
  221. }
  222. .total_box {
  223. position: relative;
  224. display: flex;
  225. // align-items: center;
  226. flex-direction: column;
  227. justify-content: space-between;
  228. // position: relative;
  229. font-size: 13px;
  230. color: #fff;
  231. height: 140px;
  232. // border-radius: 16px;
  233. padding: 20px 20px;
  234. box-sizing: border-box;
  235. border-radius: 10px;
  236. margin: 10px;
  237. background: linear-gradient(to right, #1ab986, #25d7bb);
  238. .total {
  239. font-size: 28px;
  240. // text-align: center;
  241. padding-top: 10px;
  242. }
  243. .bo {
  244. font-size: 12px;
  245. display: flex;
  246. align-items: center;
  247. color: rgba(#fff, 0.8);
  248. margin: 10px 10px 0 0;
  249. .icon {
  250. width: 20px;
  251. height: 20px;
  252. margin-right: 6px;
  253. border-radius: 50%;
  254. padding: 4px;
  255. background-color: rgba(#000, 0.1);
  256. }
  257. }
  258. .mx {
  259. position: absolute;
  260. right: 20px;
  261. width: fit-content;
  262. font-size: 11px;
  263. color: rgba(#f7f7f7, 0.9);
  264. padding: 2px 12px;
  265. border-radius: 10px;
  266. background-color: rgba(#000, 0.1);
  267. }
  268. .text {
  269. color: rgba(#fff, 0.8);
  270. }
  271. .buy {
  272. position: absolute;
  273. right: 14px;
  274. bottom: 14px;
  275. &_btn {
  276. color: #29b286;
  277. height: 30px;
  278. line-height: 30px;
  279. font-size: 14px;
  280. background-color: #ffffff;
  281. border: none;
  282. padding: 0 16px;
  283. white-space: nowrap;
  284. border-radius: 30px;
  285. }
  286. }
  287. }
  288. .bare {
  289. text-align: center;
  290. font-size: 14px;
  291. padding: 60px 14px;
  292. color: #888;
  293. }
  294. .list {
  295. border-radius: 20px;
  296. padding: 0 20px;
  297. margin-top: 16px;
  298. background-color: #fff;
  299. margin: 16px 6px;
  300. .box {
  301. width: 100%;
  302. color: rgba(51, 51, 51, 1);
  303. font-size: 14px;
  304. padding: 18px 0 18px;
  305. .box_item:last-child {
  306. border-bottom: none;
  307. }
  308. &_item {
  309. display: flex;
  310. align-items: center;
  311. justify-content: space-between;
  312. padding: 16px 0;
  313. border-bottom: 0.5px solid rgba(190, 190, 190, 0.15);
  314. .key {
  315. color: #aaa;
  316. font-size: 12px;
  317. }
  318. .left {
  319. font-size: 13px;
  320. }
  321. .walletbalance::after {
  322. content: ' USDT';
  323. font-size: 12px;
  324. }
  325. .mobile {
  326. font-size: 14px;
  327. color: #000;
  328. font-weight: 550;
  329. }
  330. .input {
  331. width: 180px;
  332. }
  333. }
  334. }
  335. }
  336. .buy {
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. margin-top: 30px;
  341. &_btn {
  342. width: 80%;
  343. height: 46px;
  344. line-height: 46px;
  345. font-size: 14px;
  346. background-color: #29b286;
  347. border: none;
  348. padding: 0 10px;
  349. white-space: nowrap;
  350. border-radius: 30px;
  351. }
  352. }
  353. .tips {
  354. color: #aaa;
  355. font-size: 12px;
  356. line-height: 180%;
  357. padding: 14px;
  358. }
  359. }
  360. .wrapper {
  361. // display: flex;
  362. // justify-content: center;
  363. .loading {
  364. position: absolute;
  365. left: 46%;
  366. top: 46%;
  367. }
  368. }
  369. </style>