arWithdraw.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div>
  3. <!-- <div class="head">
  4. <img @click="back" src="@/assets/images/back.png" class="arrow_img" />
  5. <span>SMH提现</span>
  6. </div> -->
  7. <div class="lease">
  8. <div class="balance_box">
  9. <div>
  10. <span class="text_active">AR余额</span>
  11. </div>
  12. <!-- 钱包余额 -->
  13. <div class="balance">
  14. <span>{{ Math.floor(dataObj.ar * 100) / 100 || 0 }}</span>
  15. </div>
  16. <div class="universal">
  17. <div class="slider">
  18. <!-- <van-slider v-model="amount" :max="max" :min="400" bar-height="8" active-color="#238be8" button-size="16" /> -->
  19. <input type="number" v-model="withdrawAmount" placeholder="请输入提币金额" />
  20. <div class="all" @click="withdrawAmount = dataObj.ar">
  21. <span>全部</span>
  22. </div>
  23. </div>
  24. <div>
  25. <span class="hint">最小{{ dataObj.ar_min_amount || 0 }}AR起</span>
  26. </div>
  27. <div class="slider">
  28. <textarea type="text" v-model="address" :disabled="disable" placeholder="请输入提币地址" />
  29. </div>
  30. <div class="li">
  31. <span>{{ dataObj.tips }}</span>
  32. </div>
  33. </div>
  34. </div>
  35. <!-- <div class="button" v-if="tabIndex == 1">
  36. <van-button class="submit_button" type="primary" v-if="showApprove" @click="approve">授权</van-button>
  37. <van-button class="submit_button" type="primary" v-else @click="submit">提交</van-button>
  38. </div> -->
  39. <div class="button">
  40. <van-button class="submit_button" type="primary" @click="withdrawSubmit">提交</van-button>
  41. </div>
  42. </div>
  43. <!-- 加载弹窗 -->
  44. <van-popup v-model="isApprove" round style="width: 80%" :close-on-click-overlay="false">
  45. <div class="bind_box">
  46. <div style="font-weight: bold"><van-loading type="spinner" /></div>
  47. <div class="address_field">处理中...</div>
  48. </div>
  49. </van-popup>
  50. </div>
  51. </template>
  52. <script>
  53. import { homeApi } from '@/api/index';
  54. import { Notify } from 'vant';
  55. import packApi from '@/methods/pack.js';
  56. import usdt from '@/methods/usdt.js';
  57. import { useErc20Contract } from '@/utils/useContract';
  58. import { MaxUint256 } from '@ethersproject/constants';
  59. import { getErc20Contract, getJackPairContract } from '@/utils/contractHelp';
  60. import { formatAmount, parseAmount, accMul, gasProcessing } from '@/utils/format.js'; //有空看看这里 这个地方封装了bignumer处理 好
  61. import { mapState } from 'vuex';
  62. import Web3 from 'web3';
  63. import { number } from 'echarts';
  64. export default {
  65. data() {
  66. return {
  67. token: null, //余额
  68. show: true,
  69. address: '', //地址
  70. payToken: undefined, //支付币种
  71. walletBalance: 0, //钱包余额
  72. showApprove: false, //授权
  73. isApprove: false, //是否有授权
  74. tabIndex: 1, // 1:兑换 2:提现
  75. dataObj: {
  76. token: 0,
  77. ar_min_amount: 0,
  78. tips: '',
  79. },
  80. max: 0,
  81. system_money: 0, //系统余额
  82. min: 0,
  83. allowanceV2: 0, // 授权额度
  84. withdrawAmount: null,
  85. disable: false,
  86. exchangeAmount: null,
  87. };
  88. },
  89. created() {
  90. this.init();
  91. },
  92. watch: {
  93. account() {
  94. this.init();
  95. },
  96. amount(e) {
  97. if (String(e).indexOf('.') != -1) {
  98. this.amount = Math.trunc(e);
  99. }
  100. // if (/[^1-9]/g.test(e)) {
  101. // return false;
  102. // }
  103. },
  104. },
  105. computed: {
  106. ...mapState(['account']),
  107. },
  108. methods: {
  109. init() {
  110. homeApi.arInfo().then(res => {
  111. console.log(res);
  112. if (res.code == 200) {
  113. this.dataObj = res.data;
  114. this.address = res.data.address;
  115. this.address ? (this.disable = true) : (this.disable = false);
  116. }
  117. });
  118. },
  119. changeTab(e) {
  120. this.tabIndex = e;
  121. },
  122. //返回上一页
  123. back() {
  124. this.$router.back();
  125. },
  126. withdrawSubmit() {
  127. if (!this.withdrawAmount) {
  128. this.$toast('请输入金额');
  129. return;
  130. }
  131. if (this.withdrawAmount < Number(this.dataObj.ar_min_amount)) {
  132. this.$toast(`最小${this.dataObj.ar_min_amount}SMH`);
  133. return;
  134. }
  135. if (this.withdrawAmount > Number(this.dataObj.ar)) {
  136. this.$toast('余额不足');
  137. return;
  138. }
  139. if (!this.address) {
  140. this.$toast('请输入提币地址');
  141. return;
  142. }
  143. let web3 = new Web3(window.web3.currentProvider);
  144. web3.eth.personal.sign(web3.utils.fromUtf8('EtcWithdraw'), this.account, (err, res) => {
  145. let params = {
  146. amount: this.withdrawAmount,
  147. sign: res,
  148. address: this.address,
  149. };
  150. homeApi.arSubmit(params).then(res => {
  151. if (res.code == 200) {
  152. Notify({ type: 'primary', message: res.msg });
  153. this.withdrawAmount = '';
  154. this.init();
  155. } else {
  156. Notify({ message: res.msg });
  157. }
  158. });
  159. });
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="less" scoped>
  165. .head {
  166. position: fixed;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. color: rgba(#000, 0.8);
  171. letter-spacing: 1.5px;
  172. font-weight: 550;
  173. padding: 14px 0;
  174. top: 0;
  175. width: 100%;
  176. background: #fff;
  177. .arrow_img {
  178. position: absolute;
  179. left: 20px;
  180. width: 10px;
  181. height: 16px;
  182. }
  183. }
  184. .lease {
  185. // min-height: 100vh;
  186. padding: 0 16px 0;
  187. .balance_box {
  188. border-radius: 16px;
  189. padding: 10px 20px 30px;
  190. overflow: hidden;
  191. box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.59);
  192. background-color: rgba(255, 255, 255, 0.3);
  193. .caption {
  194. display: flex;
  195. justify-content: space-around;
  196. font-size: 14px;
  197. color: rgba(102, 102, 102, 1);
  198. .system_text {
  199. padding: 0 6px 5px;
  200. border-bottom: 2px solid rgb(255, 255, 255);
  201. }
  202. .text_active {
  203. color: rgba(35, 139, 232, 1);
  204. padding: 0 6px 5px;
  205. border-bottom: 2px solid rgba(35, 139, 232, 1);
  206. }
  207. }
  208. .text_active {
  209. font-size: 14px;
  210. color: rgba(35, 139, 232, 1);
  211. }
  212. .balance {
  213. font-size: 20px;
  214. font-weight: bold;
  215. color: #000;
  216. margin: 12px 0 16px;
  217. }
  218. .universal {
  219. display: flex;
  220. // align-items: center;
  221. flex-direction: column;
  222. // justify-content: space-between;
  223. font-size: 14px;
  224. color: rgba(102, 102, 102, 1);
  225. margin-top: 12px;
  226. .li {
  227. display: flex;
  228. flex-direction: column;
  229. line-height: 150%;
  230. letter-spacing: 1px;
  231. font-size: 13px;
  232. padding-top: 6px;
  233. // align-items: center;
  234. .li_amount {
  235. // font-weight: bold;
  236. color: #000;
  237. margin-top: 8px;
  238. }
  239. }
  240. }
  241. .slider {
  242. margin: 10px 0 18px;
  243. display: flex;
  244. align-items: center;
  245. input {
  246. border: 0;
  247. background-color: #f1f1f1;
  248. width: 100%;
  249. padding: 10px 10px;
  250. border-radius: 6px;
  251. font-size: 14px;
  252. color: #000;
  253. }
  254. textarea {
  255. border: 0;
  256. background-color: #f1f1f1;
  257. width: 100%;
  258. padding: 10px 10px;
  259. border-radius: 6px;
  260. font-size: 14px;
  261. color: #000;
  262. resize: none;
  263. }
  264. .danwei {
  265. font-size: 13px;
  266. padding-left: 6px;
  267. }
  268. }
  269. .hint {
  270. font-size: 12px;
  271. color: rgba(102, 102, 102, 1);
  272. padding-left: 6px;
  273. }
  274. }
  275. .button {
  276. display: flex;
  277. justify-content: center;
  278. .submit_button {
  279. color: rgba(#fff, 0.95);
  280. background: #2f46d4;
  281. border: 0;
  282. border-radius: 12px;
  283. padding: 12px 0;
  284. width: 100%;
  285. margin-top: 30px;
  286. letter-spacing: 1.5px;
  287. }
  288. }
  289. }
  290. .bind_box {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. padding: 50px 0;
  295. .address_field {
  296. padding-top: 16px;
  297. }
  298. }
  299. .all {
  300. font-size: 10px;
  301. white-space: nowrap;
  302. padding: 6px;
  303. border: 1px solid #238be8;
  304. border-radius: 10px;
  305. margin-left: 10px;
  306. }
  307. </style>