smhWithdraw.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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">SMH余额</span>
  11. </div>
  12. <!-- 钱包余额 -->
  13. <div class="balance">
  14. <span>{{ Math.floor(dataObj.smh * 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="#7938cf" button-size="16" /> -->
  19. <input type="number" v-model="withdrawAmount" placeholder="请输入提币金额" />
  20. <div class="all" @click="withdrawAmount = dataObj.smh">
  21. <span>全部</span>
  22. </div>
  23. </div>
  24. <div>
  25. <span class="hint">最小提现{{ dataObj.smh_min_amount || 0 }}SMH起</span>
  26. <span class="hint">手续费:{{ dataObj.smh_fee_rate * 100 || 0 }}%</span>
  27. </div>
  28. <div class="slider">
  29. <textarea type="text" v-model="address" :disabled="disable" placeholder="请输入提币地址" />
  30. </div>
  31. <div class="li">
  32. <span>{{ dataObj.tips }}</span>
  33. </div>
  34. </div>
  35. </div>
  36. <!-- <div class="button" v-if="tabIndex == 1">
  37. <van-button class="submit_button" type="primary" v-if="showApprove" @click="approve">授权</van-button>
  38. <van-button class="submit_button" type="primary" v-else @click="submit">提交</van-button>
  39. </div> -->
  40. <div class="button">
  41. <van-button class="submit_button" type="primary" @click="withdrawSubmit">提交</van-button>
  42. </div>
  43. </div>
  44. <!-- 加载弹窗 -->
  45. <van-popup v-model="isApprove" round style="width: 80%" :close-on-click-overlay="false">
  46. <div class="bind_box">
  47. <div style="font-weight: bold"><van-loading type="spinner" /></div>
  48. <div class="address_field">处理中...</div>
  49. </div>
  50. </van-popup>
  51. </div>
  52. </template>
  53. <script>
  54. import { homeApi } from '@/api/index';
  55. import { Notify } from 'vant';
  56. import packApi from '@/methods/pack.js';
  57. import usdt from '@/methods/usdt.js';
  58. import { useErc20Contract } from '@/utils/useContract';
  59. import { MaxUint256 } from '@ethersproject/constants';
  60. import { getErc20Contract, getJackPairContract } from '@/utils/contractHelp';
  61. import { formatAmount, parseAmount, accMul, gasProcessing } from '@/utils/format.js'; //有空看看这里 这个地方封装了bignumer处理 好
  62. import { mapState } from 'vuex';
  63. import Web3 from 'web3';
  64. import { number } from 'echarts';
  65. export default {
  66. data() {
  67. return {
  68. token: null, //余额
  69. show: true,
  70. address: '', //地址
  71. payToken: undefined, //支付币种
  72. walletBalance: 0, //钱包余额
  73. showApprove: false, //授权
  74. isApprove: false, //是否有授权
  75. tabIndex: 1, // 1:兑换 2:提现
  76. dataObj: {
  77. token: 0,
  78. smh_min_amount: 0,
  79. tips: '提示提示提示提示',
  80. },
  81. max: 0,
  82. system_money: 0, //系统余额
  83. min: 0,
  84. allowanceV2: 0, // 授权额度
  85. withdrawAmount: null,
  86. disable: false,
  87. exchangeAmount: null,
  88. };
  89. },
  90. created() {
  91. this.init();
  92. },
  93. watch: {
  94. account() {
  95. this.init();
  96. },
  97. amount(e) {
  98. if (String(e).indexOf('.') != -1) {
  99. this.amount = Math.trunc(e);
  100. }
  101. // if (/[^1-9]/g.test(e)) {
  102. // return false;
  103. // }
  104. },
  105. },
  106. computed: {
  107. ...mapState(['account']),
  108. },
  109. methods: {
  110. init() {
  111. homeApi.smhInfo().then(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.smh_min_amount)) {
  132. this.$toast(`最小${this.dataObj.smh_min_amount}SMH`);
  133. return;
  134. }
  135. if (this.withdrawAmount > Number(this.dataObj.smh)) {
  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.smhSubmit(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: #7938cf;
  204. padding: 0 6px 5px;
  205. border-bottom: 2px solid #7938cf;
  206. }
  207. }
  208. .text_active {
  209. font-size: 14px;
  210. color: #7938cf;
  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 10px;
  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: #7938cf;
  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 #7938cf;
  304. border-radius: 10px;
  305. margin-left: 10px;
  306. }
  307. </style>