home-index.vue 16 KB

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