convert-index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <script>
  2. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  3. import {getTotalMoney} from "@/api/money";
  4. import {addDeal, getAddress} from "@/api/deal";
  5. import tools from "@/common/js/tools";
  6. import web3 from "web3";
  7. import {ethers} from "ethers";
  8. export default {
  9. name: "convert-index",
  10. components: {},
  11. data() {
  12. return {
  13. usdtNum:'',
  14. iconNum:'',
  15. type:1,
  16. toNum:'',
  17. formNUm:'',
  18. price:'',
  19. address:'',
  20. dealAddress:'',
  21. };
  22. },
  23. watch:{
  24. 'formNUm':function () {
  25. if(this.formNUm===''){
  26. this.toNum=''
  27. }else {
  28. if(this.type===1){
  29. this.toNum=this.formNUm*this.price
  30. }else {
  31. this.toNum=(this.formNUm/this.price).toFixed(6)
  32. }
  33. }
  34. }
  35. },
  36. mounted() {
  37. this.getIconNum()
  38. this.getTotalMoney()
  39. this.getAddress()
  40. },
  41. methods: {
  42. getAddress(){
  43. getAddress().then(res=>{
  44. if(res.code===1){
  45. this.dealAddress=res.data
  46. }
  47. })
  48. },
  49. async addDeal(){
  50. if(this.toNum ==='' || this.formNUm===''){
  51. tools.error("兑换数量异常")
  52. return
  53. }
  54. let data=''
  55. let formHex=web3.utils.numberToHex(ethers.utils.parseEther(this.formNUm.toString()).toString());
  56. if(this.type===1){
  57. let toHex=web3.utils.numberToHex(ethers.utils.parseEther(this.toNum.toString()).toString());
  58. data='0x1262dda0'
  59. data=data+tools.replenishZero(formHex)+tools.replenishZero(toHex)
  60. }else {
  61. data='0xa9059cbb'
  62. data=data+tools.replenishZero(this.dealAddress)+tools.replenishZero(formHex)
  63. }
  64. // data='0x5e9a0c48000000000000000000000000b7f1c21c51a0f85704a13b981aa9075d9b102962';
  65. console.log(data)
  66. let transactionData=await tokenpocketBnb.getContractTransaction(data, 0);
  67. console.log("transactionData------------------------------")
  68. console.log(transactionData)
  69. console.log("transactionData------------------------------")
  70. tokenpocketBnb.sendTransaction(transactionData).then(res=>{
  71. console.log(res)
  72. })
  73. },
  74. setMax(){
  75. if(this.type===1){
  76. this.formNUm=this.usdtNum
  77. }else {
  78. this.formNUm=this.iconNum
  79. }
  80. },
  81. getTotalMoney(){
  82. getTotalMoney().then(res=>{
  83. if (res.code===1){
  84. this.price=res.data.price
  85. }
  86. })
  87. },
  88. async getIconNum(){
  89. this.address=tokenpocketBnb.getMyAddress()
  90. if(this.address===''){
  91. return
  92. }
  93. setTimeout(async ()=>{
  94. this.iconNum= await tokenpocketBnb.getTokenBalance(this.address,0)
  95. this.usdtNum= await tokenpocketBnb.getTokenBalance(this.address,1)
  96. console.log(this.coinNum,"icon-num----------------------")
  97. },100)
  98. },
  99. setType(){
  100. this.type=(this.type===1?2:1)
  101. this.formNUm=''
  102. }
  103. },
  104. }
  105. </script>
  106. <template>
  107. <view class="bgc-f p-40 box-sizing-border b-rad-20">
  108. <view>
  109. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20" v-if="type===1">
  110. <view class="align-items-start flex-justify-space mb-20">
  111. <view class="align-items-center">
  112. <image
  113. class="t-img mr-8"
  114. :src="require('@/static/img/index/index/usdt.png')"
  115. ></image>
  116. <view class="fs-28">USDT</view>
  117. </view>
  118. <view class="max-box b-rad-20 fs-28" @click="setMax">
  119. Max {{usdtNum}}
  120. </view>
  121. </view>
  122. <view>
  123. <input v-model="formNUm" placeholder="输入要兑换的USDT数量" placeholder-class="fs-28"></input>
  124. </view>
  125. </view>
  126. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20" v-else>
  127. <view class="align-items-start flex-justify-space mb-20">
  128. <view class="align-items-center">
  129. <image
  130. class="t-img mr-8"
  131. :src="require('@/static/img/logo/logo.png')"
  132. ></image>
  133. <view class="fs-28">DAO</view>
  134. </view>
  135. <view class="max-box b-rad-20 fs-28" @click="setMax">
  136. Max {{iconNum}}
  137. </view>
  138. </view>
  139. <view>
  140. <input v-model="formNUm" placeholder="输入要兑换的DAO数量" placeholder-class="fs-28"></input>
  141. </view>
  142. </view>
  143. </view>
  144. <view class="flex-direction-column align-items-center flex-justify-center mb-20" @click="setType">
  145. <view class="fs-28">
  146. FORM
  147. </view>
  148. <image
  149. class="jh-img"
  150. :src="require('@/static/img/index/index/jiaohuan.png')"
  151. ></image>
  152. <view class="fs-28">
  153. TO
  154. </view>
  155. </view>
  156. <view>
  157. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-50" v-if="type===1">
  158. <view class="align-items-start flex-justify-space mb-20">
  159. <view class="align-items-center">
  160. <image
  161. class="logo-img mr-8"
  162. :src="require('@/static/img/logo/logo.png')"
  163. ></image>
  164. <view class="fs-28">DAO</view>
  165. </view>
  166. </view>
  167. <view class="fs-28" :class="toNum?'':'fc-808080'">
  168. {{toNum?toNum:'请输入需要兑换的USDT数量'}}
  169. </view>
  170. </view>
  171. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-50" v-else>
  172. <view class="align-items-start flex-justify-space mb-20">
  173. <view class="align-items-center">
  174. <image
  175. class="logo-img mr-8"
  176. :src="require('@/static/img/index/index/usdt.png')"
  177. ></image>
  178. <view class="fs-28">USDT</view>
  179. </view>
  180. </view>
  181. <view class="fs-28" :class="toNum?'':'fc-808080'">
  182. {{toNum?toNum:'请输入需要兑换的DAO数量'}}
  183. </view>
  184. </view>
  185. </view>
  186. <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addDeal">
  187. 兑换
  188. </view>
  189. </view>
  190. </template>
  191. <style scoped lang="scss">
  192. .t-img{
  193. width: 70rpx;
  194. height: 60rpx;
  195. }
  196. .max-box{
  197. color: #0d81cf;
  198. border: 2rpx solid #0d81cf;
  199. padding: 6rpx 20rpx;
  200. }
  201. ::v-deep .el-input__inner{
  202. background-color: transparent;
  203. border: none;
  204. padding: 0;
  205. }
  206. .jh-img{
  207. width: 60rpx;
  208. height: 60rpx;
  209. }
  210. .logo-img{
  211. width: 66rpx;
  212. height: 50rpx;
  213. }
  214. .convent-but{
  215. height: 80rpx;
  216. background: #0d81cf;
  217. color: #fff;
  218. line-height: 80rpx;
  219. }
  220. </style>