smhExchange.vue 7.4 KB

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