home-index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <script>
  2. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  3. import {
  4. getTotalMoney
  5. } from "@/api/money";
  6. import {
  7. addPledge,
  8. getDividendList,
  9. getPledgeConfig,
  10. getPledgeList
  11. } from "@/api/pledge";
  12. import blank from "@/components/en-utils/en-blank/en-blank.vue"
  13. import web3 from "web3";
  14. import {
  15. ethers
  16. } from "ethers";
  17. import tools from "@/common/js/tools";
  18. export default {
  19. name: "home-index",
  20. props: {
  21. address: {
  22. default: ''
  23. }
  24. },
  25. components: {
  26. blank
  27. },
  28. watch: {
  29. 'address': function() {
  30. this.getIconNum()
  31. },
  32. 'pledgeNUm': function() {
  33. if (this.pledgeNUm === '') {
  34. return
  35. }
  36. if (this.listTab === 1) {
  37. if (this.coinNum*1 < this.pledgeNUm*1) {
  38. this.pledgeNUm = this.coinNum
  39. }
  40. } else {
  41. if (this.pledgeTotal*1 < this.pledgeNUm*1) {
  42. this.pledgeNUm = this.pledgeTotal
  43. }
  44. }
  45. }
  46. },
  47. data() {
  48. return {
  49. listTab: 1,
  50. coinNum: '',
  51. pledgeTotal: '',
  52. revenueTotal: '',
  53. price: '',
  54. page: 1,
  55. total: '',
  56. pledgeNUm: '',
  57. bnb_num: '',
  58. pledgeAddress: '',
  59. list: []
  60. };
  61. },
  62. mounted() {
  63. this.getIconNum()
  64. this.getTotalMoney()
  65. this.getDividendList()
  66. this.getPledgeConfig()
  67. },
  68. methods: {
  69. async test(){
  70. // let price= await tokenpocketBnb.getPrice()
  71. // console.log('price:',price)
  72. //icon转账
  73. let data=''
  74. // 查询
  75. //查询开关
  76. // data='0x3494a347'
  77. // tokenpocketBnb.getProvider().request({method: 'eth_call',params:[{'to':'0x7EC437314542acFAB189671b935ba56605483796','data':data}, "latest"]}).then((balance)=>{
  78. // console.log('getTrading-----------------------',balance)
  79. // })
  80. // 查询系统地址
  81. // data='0x7fce276d'
  82. // tokenpocketBnb.getProvider().request({method: 'eth_call',params:[{'to':'0x7EC437314542acFAB189671b935ba56605483796','data':data}, "latest"]}).then((balance)=>{
  83. // console.log('0x7fce276d-----------------------',balance)
  84. // })
  85. // getSwapPair 是否是交易地址
  86. // data='0xd5afd0ac000000000000000000000000e113cfd2d4de965e73de6e217591793fa85b1de6'
  87. // tokenpocketBnb.getProvider().request({method: 'eth_call',params:[{'to':'0x7EC437314542acFAB189671b935ba56605483796','data':data}, "latest"]}).then((balance)=>{
  88. // console.log('getSwapPair-----------------------',balance)
  89. // })
  90. //
  91. // testSwapPermission 转出测试
  92. // data='0xa7bdc7f200000000000000000000000014a4ce7bfade4c897ae0d59fdfb7f8317dcdecb4'
  93. // tokenpocketBnb.getProvider().request({method: 'eth_call',params:[{'to':'0x41D8081BE81e5940F23ADd6F68bFA0Bd0aF24Af4','data':data}, "latest"]}).then((balance)=>{
  94. // console.log('testSwapPermission-----------------------',balance)
  95. // })
  96. // approve 授权测试
  97. // data='0x8b09832d000000000000000000000000241ff4db9141649ef142d297bd5623f6743fc16f'
  98. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  99. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  100. // console.log(res)
  101. // })
  102. // // setSwapPair 设置交易合约地址
  103. // data='0xa842486100000000000000000000000097cc9e8dd1143e5ba2df7df6f8570203e40aa3c60000000000000000000000000000000000000000000000000000000000000001'
  104. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  105. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  106. // console.log(res)
  107. // })
  108. //setSwapPair 设置交易合约地址
  109. // data='0xdc2c50e5000000000000000000000000d99d1c33f9fc3444f8101754abc46c52416550d1000000000000000000000000337610d27c682e347c9cd60bd4b3b107c9d34ddd'
  110. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  111. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  112. // console.log(res)
  113. // })
  114. //0xfe219D86FC55cd07441005fF647B9babAd12C36C
  115. //0xfe219D86FC55cd07441005fF647B9babAd12C36C
  116. // approve 预授权
  117. // data = '0x095ea7b3000000000000000000000000b7f1c21c51a0f85704a13b981aa9075d9b1029620000000000000000000000000000000000000000000000056bc75e2d63100000'
  118. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  119. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  120. // console.log(res)
  121. // })
  122. // approve 预授权
  123. // data = '0x095ea7b3000000000000000000000000b7f1c21c51a0f85704a13b981aa9075d9b1029620000000000000000000000000000000000000000000000056bc75e2d63100000'
  124. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  125. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  126. // console.log(res)
  127. // })
  128. // addSysAddress 设置系统地址
  129. // data = '0x5e9a0c4800000000000000000000000014a4ce7bfade4c897ae0d59fdfb7f8317dcdecb4'
  130. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  131. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  132. // console.log(res)
  133. // })
  134. // let data = '0x5e9a0c48' + tools.replenishZero('0xb7F1c21c51a0f85704a13b981Aa9075d9b102962')
  135. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  136. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  137. // console.log(res)
  138. // })
  139. // 0x2383eb8f 交易开关
  140. // let formHex = web3.utils.numberToHex(1);
  141. // console.log('formHex:'+formHex)
  142. // data = '0x2383eb8f' + tools.replenishZero(formHex)
  143. // console.log(data)
  144. // let transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  145. // tokenpocketBnb.sendTransaction(transactionData).then(res => {
  146. // console.log(res)
  147. // })
  148. },
  149. getPledgeConfig() {
  150. getPledgeConfig().then(res => {
  151. if (res.code === 1) {
  152. this.bnb_num = res.data.bnb_num
  153. this.pledgeAddress = res.data.address
  154. }
  155. })
  156. },
  157. setListTab(listTab) {
  158. if (this.listTab !== listTab) {
  159. this.listTab = listTab
  160. this.pledgeNUm = ''
  161. }
  162. },
  163. getDividendList() {
  164. if (this.total >= this.list.length && this.page>1) {
  165. return
  166. }
  167. getDividendList({
  168. 'page': this.page
  169. }).then(res => {
  170. if (res.code === 1) {
  171. this.list.push(...res.data.items)
  172. this.total = res.data.total
  173. this.page++
  174. }
  175. })
  176. },
  177. async addPledge() {
  178. if (this.listTab === 1) {
  179. if (this.coinNum*1 < this.pledgeNUm*1) {
  180. tools.error('DAO不足')
  181. return
  182. }
  183. } else {
  184. if (this.pledgeTotal*1 < this.pledgeNUm*1) {
  185. tools.error('贡献不足')
  186. return
  187. }
  188. let bnbNUm = tokenpocketBnb.getBalance(this.address)
  189. if (bnbNUm < this.bnb_num) {
  190. tools.error('BNB不足')
  191. return
  192. }
  193. }
  194. let data = ''
  195. let transactionData
  196. if (this.listTab === 1) {
  197. data = '0xa9059cbb'
  198. //icon转账
  199. let formHex = web3.utils.numberToHex(ethers.utils.parseEther(this.pledgeNUm.toString())
  200. .toString());
  201. data = data + tools.replenishZero(this.pledgeAddress) + tools.replenishZero(formHex)
  202. transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  203. } else {
  204. //bnb转账
  205. transactionData = await tokenpocketBnb.getTransactionData(this.pledgeAddress, this.bnb_num);
  206. }
  207. tokenpocketBnb.sendTransaction(transactionData).then(res => {
  208. if (res) {
  209. addPledge({
  210. 'type': this.listTab,
  211. 'money': this.pledgeNUm,
  212. 'hash': res
  213. }).then(res => {
  214. if (res.code === 0) {
  215. this.pledgeNUm = ''
  216. tools.success(res.msg)
  217. this.getTotalMoney()
  218. } else {
  219. tools.error(res.msg)
  220. }
  221. })
  222. } else {
  223. tools.error('发起失败')
  224. }
  225. console.log(res)
  226. })
  227. },
  228. scrolltolower() {
  229. if (this.list.length < this.total) {
  230. ++this.page
  231. this.getDividendList()
  232. // console.log('触底');
  233. }
  234. },
  235. getTotalMoney() {
  236. getTotalMoney().then(res => {
  237. if (res.code === 1) {
  238. this.pledgeTotal = res.data.pledgeTotal
  239. this.revenueTotal = res.data.revenueTotal
  240. this.price = res.data.price
  241. }
  242. })
  243. },
  244. async getIconNum() {
  245. if (this.address === '') {
  246. return
  247. }
  248. setTimeout(async () => {
  249. this.coinNum = await tokenpocketBnb.getTokenBalance(this.address, 0)
  250. console.log(this.coinNum, "icon-num----------------------")
  251. }, 100)
  252. },
  253. setMax() {
  254. if (this.listTab === 1) {
  255. this.pledgeNUm = this.coinNum
  256. } else {
  257. this.pledgeNUm = this.pledgeTotal
  258. }
  259. },
  260. },
  261. }
  262. </script>
  263. <template>
  264. <view>
  265. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40" @click="test">
  266. <image class="head-img" :src="require('@/static/img/index/index/bannerhome.png')" mode="widthFix"></image>
  267. </view>
  268. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40">
  269. <view class="b-rad-20 h-80 align-items-center bgc-f1f9fe">
  270. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  271. <view class="fs-28 mb-8">
  272. DAO價格($)
  273. </view>
  274. <view class="fs-28 fw-b">
  275. {{price}}
  276. </view>
  277. </view>
  278. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  279. <view class="fs-28 mb-8">
  280. DAO餘額
  281. </view>
  282. <view class="fs-28 fw-b">
  283. {{coinNum}}
  284. </view>
  285. </view>
  286. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  287. <view class="fs-28 mb-8">
  288. 贡献总额
  289. </view>
  290. <view class="fs-28 fw-b">
  291. {{pledgeTotal}}
  292. </view>
  293. </view>
  294. </view>
  295. </view>
  296. <view class="list-tab">
  297. <view class="tab-items">
  298. <view class="tab-item" @click="setListTab(1)" :class="{'option-tab':listTab===1}">
  299. 贡献
  300. </view>
  301. <view class="tab-item" @click="setListTab(2)" :class="{'option-tab':listTab===2}">
  302. 赎回
  303. </view>
  304. <!-- <view class="tab-item" @click="setListTab(3)" :class="{'option-tab':listTab===3}">-->
  305. <!-- {{ $t('index.index.code') }}-->
  306. <!-- </view>-->
  307. </view>
  308. <view class="tab-item-bg"
  309. :class="{'bg-location-1':listTab===1,'bg-location-2':listTab===2,'bg-location-3':listTab===3}"></view>
  310. <view class="bgc-f p-40">
  311. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20">
  312. <view class="align-items-start flex-justify-space mb-20">
  313. <view class="align-items-center">
  314. <image class="t-img mr-8" :src="require('@/static/img/logo/logo.png')"></image>
  315. <view class="fs-28">DAO</view>
  316. </view>
  317. <view class="max-box b-rad-20 fs-28" @click="setMax">
  318. Max {{listTab===1 ?coinNum:pledgeTotal}}
  319. </view>
  320. </view>
  321. <view>
  322. <input v-model="pledgeNUm" :placeholder="'输入要'+(listTab===1 ?'质押':'解压')+'的DAO数量'" type="number"
  323. placeholder-class="fs-28"></input>
  324. </view>
  325. </view>
  326. <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addPledge">
  327. 确定
  328. </view>
  329. </view>
  330. </view>
  331. <view class="bgc-f p-20 box-sizing-border b-rad-20">
  332. <view class="fs-28 pt-5 mb-8">
  333. 分红记录
  334. </view>
  335. <view v-if="list.length<=0" class="blank-box align-items-center flex-justify-center">
  336. <blank :showBlank="list.length<=0?true:false" message="暂无数据"></blank>
  337. </view>
  338. <view class="bgc-F6F7FA" v-else>
  339. <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">
  340. <view>
  341. <view class="mb-8 fs-28 fw-b">贡献 {{item.pledge_money}} DAO</view>
  342. <view class="fs-24">{{item.created_date}}</view>
  343. </view>
  344. <view class="align-items-center">
  345. <view class="fs-24">分红:</view>
  346. <view class="fs-28 fc-ED301D">{{item.sorting_money}}</view>
  347. </view>
  348. </view>
  349. </view>
  350. <!-- <view class="bgc-F6F7FA" v-else>-->
  351. <!-- <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">-->
  352. <!-- <view>-->
  353. <!-- <view class="mb-8 fs-28 fw-b">{{item.type===1?'质押':'解压'}}</view>-->
  354. <!-- <view class="fs-24">{{item.created_date}}</view>-->
  355. <!-- </view>-->
  356. <!-- <view class="">-->
  357. <!-- <view class="fs-24" v-if="item.status===1">执行中</view>-->
  358. <!-- <view class="fs-24" v-else-if="item.status===2">已完成</view>-->
  359. <!-- <view class="fs-24" v-else>已作废</view>-->
  360. <!-- <view class="fs-28 ">数量:<text class="fc-ED301D">{{item.money}}</text></view>-->
  361. <!-- </view>-->
  362. <!-- </view>-->
  363. </view>
  364. </view>
  365. </template>
  366. <style scoped lang="scss">
  367. .head-img {
  368. width: 100%;
  369. // height: 128px;
  370. }
  371. .h-80 {
  372. height: 160rpx;
  373. }
  374. .h-50 {
  375. height: 100rpx;
  376. line-height: 100rpx;
  377. }
  378. .item-box {
  379. width: 100%;
  380. height: 120rpx;
  381. padding: 10rpx 20rpx;
  382. box-sizing: border-box;
  383. border-top: 2rpx solid #e5e5e5;
  384. }
  385. .item-box:first-child {
  386. border-top: none;
  387. }
  388. .list-tab {
  389. width: 100%;
  390. height: 100%;
  391. background: #eaf2ff;
  392. border-radius: 10rpx;
  393. cursor: pointer;
  394. position: relative;
  395. margin: 20rpx 0;
  396. .tab-items {
  397. z-index: 10;
  398. display: flex;
  399. justify-content: space-between;
  400. border-radius: 10rpx;
  401. .tab-item {
  402. z-index: 10;
  403. width: calc(100% / 2);
  404. font-size: 13px;
  405. color: #adbad0;
  406. display: block;
  407. height: 32px;
  408. line-height: 32px;
  409. text-align: center;
  410. }
  411. .option-tab {
  412. color: #292929;
  413. }
  414. }
  415. .tab-item-bg {
  416. position: absolute;
  417. border-radius: 10rpx 10rpx 0 0;
  418. background: #fff;
  419. transition: .5s ease;
  420. height: 32px;
  421. width: calc(100% / 2);
  422. top: 0;
  423. }
  424. .bg-location-1 {
  425. left: 0;
  426. transition: .5s ease;
  427. }
  428. .bg-location-2 {
  429. left: 50%;
  430. transition: .5s ease;
  431. }
  432. }
  433. .t-img {
  434. width: 70rpx;
  435. height: 60rpx;
  436. }
  437. .max-box {
  438. color: #0d81cf;
  439. border: 2rpx solid #0d81cf;
  440. padding: 6rpx 20rpx;
  441. }
  442. .convent-but {
  443. height: 80rpx;
  444. background: #0d81cf;
  445. color: #fff;
  446. line-height: 80rpx;
  447. }
  448. </style>