convert-index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <script>
  2. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  3. import {
  4. getTotalMoney
  5. } from "@/api/money";
  6. import {
  7. addDeal,
  8. getAddress, getDealList
  9. } from "@/api/deal";
  10. import tools from "@/common/js/tools";
  11. import web3 from "web3";
  12. import {
  13. ethers
  14. } from "ethers";
  15. import blank from "@/components/en-utils/en-blank/en-blank.vue";
  16. export default {
  17. name: "convert-index",
  18. components: {blank},
  19. data() {
  20. return {
  21. usdtNum: '',
  22. iconNum: '',
  23. type: 1,
  24. toNum: '',
  25. formNUm: '',
  26. price: '',
  27. address: '',
  28. dealAddress: '',
  29. change_num: 0,
  30. list:[],
  31. page: 1,
  32. };
  33. },
  34. watch: {
  35. 'formNUm': function() {
  36. if (this.formNUm === '') {
  37. this.toNum = ''
  38. } else {
  39. if (this.type === 1) {
  40. this.toNum = this.formNUm * this.price
  41. } else {
  42. this.toNum = (this.formNUm / this.price).toFixed(6)
  43. }
  44. }
  45. }
  46. },
  47. mounted() {
  48. this.getIconNum()
  49. this.getTotalMoney()
  50. this.getAddress()
  51. this.getDealList()
  52. },
  53. methods: {
  54. getAddress() {
  55. getAddress().then(res => {
  56. if (res.code === 1) {
  57. this.dealAddress = res.data.address
  58. this.change_num = res.data.change_num
  59. }
  60. })
  61. },
  62. async addDeal() {
  63. if (this.toNum === '' || this.formNUm === '') {
  64. tools.error("兑换数量异常")
  65. return
  66. }
  67. let data = ''
  68. let transactionData = ''
  69. let formHex = web3.utils.numberToHex(ethers.utils.parseEther(this.formNUm.toString()).toString());
  70. if (this.type === 1) {
  71. if (this.change_num > 10) {
  72. tools.error('交易已锁定')
  73. return
  74. }
  75. data = '0xa9059cbb'
  76. data = data + tools.replenishZero(this.dealAddress) + tools.replenishZero(formHex)
  77. transactionData = await tokenpocketBnb.getContractTransaction(data, 1);
  78. } else {
  79. data = '0xa9059cbb'
  80. // data='0x7472616e73666572'
  81. data = data + tools.replenishZero(this.dealAddress) + tools.replenishZero(formHex)
  82. transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  83. }
  84. console.log(transactionData)
  85. // data='0x5e9a0c48000000000000000000000000b7f1c21c51a0f85704a13b981aa9075d9b102962';
  86. tokenpocketBnb.sendTransaction(transactionData).then(res => {
  87. console.log(res)
  88. if (res) {
  89. addDeal({
  90. 'type': this.type,
  91. 'money': this.toNum,
  92. 'hash': res
  93. }).then(res => {
  94. if (res.code === 1) {
  95. tools.success(res.msg)
  96. this.toNum = ''
  97. this.getTotalMoney()
  98. this.getIconNum()
  99. } else {
  100. tools.error(res.msg)
  101. }
  102. })
  103. }
  104. })
  105. },
  106. setMax() {
  107. if (this.type === 1) {
  108. this.formNUm = this.usdtNum
  109. } else {
  110. this.formNUm = this.iconNum
  111. }
  112. },
  113. getTotalMoney() {
  114. getTotalMoney().then(res => {
  115. if (res.code === 1) {
  116. this.price = res.data.price
  117. }
  118. })
  119. },
  120. async getIconNum() {
  121. this.address = tokenpocketBnb.getMyAddress()
  122. if (this.address === '') {
  123. return
  124. }
  125. setTimeout(async () => {
  126. this.iconNum = await tokenpocketBnb.getTokenBalance(this.address, 0)
  127. this.usdtNum = await tokenpocketBnb.getTokenBalance(this.address, 1)
  128. }, 100)
  129. },
  130. setType() {
  131. return
  132. this.type = (this.type === 1 ? 2 : 1)
  133. this.formNUm = ''
  134. },
  135. abbreviateString(str) {
  136. let startLength = 4;
  137. let endLength = 4;
  138. if (str.length <= startLength + endLength + 1) {
  139. return str; // 如果字符串长度不足以被截断,则返回原字符串
  140. }
  141. return str.slice(0, startLength) + '...' + str.slice(-endLength);
  142. },
  143. getDealList(){
  144. if(this.total>=this.list.length){
  145. return
  146. }
  147. getDealList({'page': this.page}).then(res=>{
  148. if(res.code===1){
  149. this.list.push(...res.data.items)
  150. this.total = res.data.total
  151. ++this.page
  152. }
  153. })
  154. }
  155. },
  156. }
  157. </script>
  158. <template>
  159. <view class="flex-common-box box-sizing-border">
  160. <view class="top-b bgc-f plr-20 box-sizing-border align-items-center flex-justify-space">
  161. <image class="img-box" src="@/static/img/logo/logo.png"></image>
  162. <view class="fs-30">
  163. {{abbreviateString(address)}}
  164. </view>
  165. </view>
  166. <view class="p-20">
  167. <view class="bgc-f p-40 box-sizing-border b-rad-20 ">
  168. <view class="">
  169. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20" v-if="type===1">
  170. <view class="align-items-start flex-justify-space mb-20">
  171. <view class="align-items-center">
  172. <image class="t-img mr-8" :src="require('@/static/img/index/index/usdt.png')"></image>
  173. <view class="fs-28">USDT</view>
  174. </view>
  175. <view class="max-box b-rad-20 fs-28" @click="setMax">
  176. Max {{usdtNum}}
  177. </view>
  178. </view>
  179. <view>
  180. <input v-model="formNUm" placeholder="输入要兑换的USDT数量" placeholder-class="fs-28"></input>
  181. </view>
  182. </view>
  183. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20" v-else>
  184. <view class="align-items-start flex-justify-space mb-20">
  185. <view class="align-items-center">
  186. <image class="t-img mr-8" :src="require('@/static/img/logo/logo.png')"></image>
  187. <view class="fs-28">DAO</view>
  188. </view>
  189. <view class="max-box b-rad-20 fs-28" @click="setMax">
  190. Max {{iconNum}}
  191. </view>
  192. </view>
  193. <view>
  194. <input v-model="formNUm" placeholder="输入要兑换的DAO数量" placeholder-class="fs-28"></input>
  195. </view>
  196. </view>
  197. </view>
  198. <view class="flex-direction-column align-items-center flex-justify-center mb-20" @click="setType">
  199. <view class="fs-28">
  200. FORM
  201. </view>
  202. <image class="jh-img" :src="require('@/static/img/index/index/jiaohuan.png')"></image>
  203. <view class="fs-28">
  204. TO
  205. </view>
  206. </view>
  207. <view>
  208. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-50" v-if="type===1">
  209. <view class="align-items-start flex-justify-space mb-20">
  210. <view class="align-items-center">
  211. <image class="logo-img mr-8" :src="require('@/static/img/logo/logo.png')"></image>
  212. <view class="fs-28">DAO</view>
  213. </view>
  214. </view>
  215. <view class="fs-28" :class="toNum?'':'fc-808080'">
  216. {{toNum?toNum:'请输入需要兑换的USDT数量'}}
  217. </view>
  218. </view>
  219. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-50" v-else>
  220. <view class="align-items-start flex-justify-space mb-20">
  221. <view class="align-items-center">
  222. <image class="logo-img mr-8" :src="require('@/static/img/index/index/usdt.png')"></image>
  223. <view class="fs-28">USDT</view>
  224. </view>
  225. </view>
  226. <view class="fs-28" :class="toNum?'':'fc-808080'">
  227. {{toNum?toNum:'请输入需要兑换的DAO数量'}}
  228. </view>
  229. </view>
  230. </view>
  231. <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addDeal">
  232. 兑换
  233. </view>
  234. </view>
  235. <view class="bgc-f p-20 box-sizing-border b-rad-20 m-t-40">
  236. <view class="fs-28 pt-5 mb-8">
  237. 兑换记录
  238. </view>
  239. <view v-if="list.length<=0" class="blank-box align-items-center flex-justify-center">
  240. <blank :showBlank="list.length<=0?true:false" message="暂无数据"></blank>
  241. </view>
  242. <view class="bgc-F6F7FA" v-else>
  243. <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">
  244. <view>
  245. <view class="mb-8 fs-28 fw-b">兑换 {{item.money}} USDT</view>
  246. <view class="fs-24">{{item.created_date}}</view>
  247. </view>
  248. <view class="align-items-center">
  249. <view class="fs-24">{{item.status_str}}</view>
  250. <view class="fs-28 ">到账: <text class="fc-ED301D">{{item.to_money}} DAO</text></view>
  251. </view>
  252. </view>
  253. </view>
  254. </view>
  255. </view>
  256. </view>
  257. </template>
  258. <style scoped lang="scss">
  259. .flex-common-box {
  260. width: 100%;
  261. height: calc(100vh - 138rpx);
  262. display: flex;
  263. flex-direction: column;
  264. }
  265. .t-img {
  266. width: 70rpx;
  267. height: 60rpx;
  268. }
  269. .max-box {
  270. color: #0d81cf;
  271. border: 2rpx solid #0d81cf;
  272. padding: 6rpx 20rpx;
  273. }
  274. ::v-deep .el-input__inner {
  275. background-color: transparent;
  276. border: none;
  277. padding: 0;
  278. }
  279. .jh-img {
  280. width: 60rpx;
  281. height: 60rpx;
  282. transform: rotate(90deg);
  283. }
  284. .logo-img {
  285. width: 66rpx;
  286. height: 50rpx;
  287. }
  288. .convent-but {
  289. height: 80rpx;
  290. background: #0d81cf;
  291. color: #fff;
  292. line-height: 80rpx;
  293. }
  294. .img-box {
  295. width: 78rpx;
  296. height: 60rpx;
  297. }
  298. .top-b {
  299. width: 100%;
  300. height: 98rpx;
  301. line-height: 98rpx;
  302. }
  303. .item-box {
  304. width: 100%;
  305. height: 120rpx;
  306. padding: 10rpx 20rpx;
  307. box-sizing: border-box;
  308. border-top: 2rpx solid #e5e5e5;
  309. }
  310. </style>