convert-index.vue 8.9 KB

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