home-index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. // let price= await tokenpocketBnb.getPrice()
  71. // console.log('price:',price)
  72. //icon转账
  73. let data=''
  74. // 查询
  75. //查询开关
  76. data='0xdbf4453000000000000000000000000014a4ce7bfade4c897ae0d59fdfb7f8317dcdecb4000000000000000000000000241ff4db9141649ef142d297bd5623f6743fc16f'
  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. console.log('this.bnb_num',this.bnb_num)
  206. transactionData = await tokenpocketBnb.getTransactionData(this.pledgeAddress, this.bnb_num);
  207. }
  208. tokenpocketBnb.sendTransaction(transactionData).then(res => {
  209. if (res) {
  210. addPledge({
  211. 'type': this.listTab,
  212. 'money': this.pledgeNUm,
  213. 'hash': res
  214. }).then(res => {
  215. if (res.code === 0) {
  216. this.pledgeNUm = ''
  217. tools.success(res.msg)
  218. this.getTotalMoney()
  219. } else {
  220. tools.error(res.msg)
  221. }
  222. })
  223. } else {
  224. tools.error('发起失败')
  225. }
  226. console.log(res)
  227. })
  228. },
  229. scrolltolower() {
  230. if (this.list.length < this.total) {
  231. ++this.page
  232. this.getDividendList()
  233. // console.log('触底');
  234. }
  235. },
  236. getTotalMoney() {
  237. getTotalMoney().then(res => {
  238. if (res.code === 1) {
  239. this.pledgeTotal = res.data.pledgeTotal
  240. this.revenueTotal = res.data.revenueTotal
  241. this.price = res.data.price
  242. }
  243. })
  244. },
  245. async getIconNum() {
  246. let address=tokenpocketBnb.getMyAddress()
  247. if (address === '') {
  248. return
  249. }
  250. setTimeout(async () => {
  251. this.coinNum = await tokenpocketBnb.getTokenBalance(address, 0)
  252. console.log(this.coinNum, "icon-num----------------------")
  253. }, 100)
  254. },
  255. setMax() {
  256. if (this.listTab === 1) {
  257. this.pledgeNUm = this.coinNum
  258. } else {
  259. this.pledgeNUm = this.pledgeTotal
  260. }
  261. },
  262. },
  263. }
  264. </script>
  265. <template>
  266. <view>
  267. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40" @click="test">
  268. <image class="head-img" :src="require('@/static/img/index/index/bannerhome.png')" mode="widthFix"></image>
  269. </view>
  270. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40">
  271. <view class="b-rad-20 h-80 align-items-center bgc-f1f9fe">
  272. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  273. <view class="fs-28 mb-8">
  274. DAO價格($)
  275. </view>
  276. <view class="fs-28 fw-b">
  277. {{price}}
  278. </view>
  279. </view>
  280. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  281. <view class="fs-28 mb-8">
  282. DAO餘額
  283. </view>
  284. <view class="fs-28 fw-b">
  285. {{coinNum}}
  286. </view>
  287. </view>
  288. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  289. <view class="fs-28 mb-8">
  290. 贡献总额
  291. </view>
  292. <view class="fs-28 fw-b">
  293. {{pledgeTotal}}
  294. </view>
  295. </view>
  296. </view>
  297. </view>
  298. <view class="list-tab">
  299. <view class="tab-items">
  300. <view class="tab-item" @click="setListTab(1)" :class="{'option-tab':listTab===1}">
  301. 贡献
  302. </view>
  303. <view class="tab-item" @click="setListTab(2)" :class="{'option-tab':listTab===2}">
  304. 赎回
  305. </view>
  306. <!-- <view class="tab-item" @click="setListTab(3)" :class="{'option-tab':listTab===3}">-->
  307. <!-- {{ $t('index.index.code') }}-->
  308. <!-- </view>-->
  309. </view>
  310. <view class="tab-item-bg"
  311. :class="{'bg-location-1':listTab===1,'bg-location-2':listTab===2,'bg-location-3':listTab===3}"></view>
  312. <view class="bgc-f p-40">
  313. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20">
  314. <view class="align-items-start flex-justify-space mb-20">
  315. <view class="align-items-center">
  316. <image class="t-img mr-8" :src="require('@/static/img/logo/logo.png')"></image>
  317. <view class="fs-28">DAO</view>
  318. </view>
  319. <view class="max-box b-rad-20 fs-28" @click="setMax">
  320. Max {{listTab===1 ?coinNum:pledgeTotal}}
  321. </view>
  322. </view>
  323. <view>
  324. <input v-model="pledgeNUm" :placeholder="'输入要'+(listTab===1 ?'质押':'解压')+'的DAO数量'" type="number"
  325. placeholder-class="fs-28"></input>
  326. </view>
  327. </view>
  328. <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addPledge">
  329. 确定
  330. </view>
  331. </view>
  332. </view>
  333. <view class="bgc-f p-20 box-sizing-border b-rad-20">
  334. <view class="fs-28 pt-5 mb-8">
  335. 分红记录
  336. </view>
  337. <view v-if="list.length<=0" class="blank-box align-items-center flex-justify-center">
  338. <blank :showBlank="list.length<=0?true:false" message="暂无数据"></blank>
  339. </view>
  340. <view class="bgc-F6F7FA" v-else>
  341. <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">
  342. <view>
  343. <view class="mb-8 fs-28 fw-b">贡献 {{item.pledge_money}} DAO</view>
  344. <view class="fs-24">{{item.created_date}}</view>
  345. </view>
  346. <view class="align-items-center">
  347. <view class="fs-24">分红:</view>
  348. <view class="fs-28 fc-ED301D">{{item.sorting_money}}</view>
  349. </view>
  350. </view>
  351. </view>
  352. <!-- <view class="bgc-F6F7FA" v-else>-->
  353. <!-- <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">-->
  354. <!-- <view>-->
  355. <!-- <view class="mb-8 fs-28 fw-b">{{item.type===1?'质押':'解压'}}</view>-->
  356. <!-- <view class="fs-24">{{item.created_date}}</view>-->
  357. <!-- </view>-->
  358. <!-- <view class="">-->
  359. <!-- <view class="fs-24" v-if="item.status===1">执行中</view>-->
  360. <!-- <view class="fs-24" v-else-if="item.status===2">已完成</view>-->
  361. <!-- <view class="fs-24" v-else>已作废</view>-->
  362. <!-- <view class="fs-28 ">数量:<text class="fc-ED301D">{{item.money}}</text></view>-->
  363. <!-- </view>-->
  364. <!-- </view>-->
  365. </view>
  366. </view>
  367. </template>
  368. <style scoped lang="scss">
  369. .head-img {
  370. width: 100%;
  371. // height: 128px;
  372. }
  373. .h-80 {
  374. height: 160rpx;
  375. }
  376. .h-50 {
  377. height: 100rpx;
  378. line-height: 100rpx;
  379. }
  380. .item-box {
  381. width: 100%;
  382. height: 120rpx;
  383. padding: 10rpx 20rpx;
  384. box-sizing: border-box;
  385. border-top: 2rpx solid #e5e5e5;
  386. }
  387. .item-box:first-child {
  388. border-top: none;
  389. }
  390. .list-tab {
  391. width: 100%;
  392. height: 100%;
  393. background: #eaf2ff;
  394. border-radius: 10rpx;
  395. cursor: pointer;
  396. position: relative;
  397. margin: 20rpx 0;
  398. .tab-items {
  399. z-index: 10;
  400. display: flex;
  401. justify-content: space-between;
  402. border-radius: 10rpx;
  403. .tab-item {
  404. z-index: 10;
  405. width: calc(100% / 2);
  406. font-size: 13px;
  407. color: #adbad0;
  408. display: block;
  409. height: 32px;
  410. line-height: 32px;
  411. text-align: center;
  412. }
  413. .option-tab {
  414. color: #292929;
  415. }
  416. }
  417. .tab-item-bg {
  418. position: absolute;
  419. border-radius: 10rpx 10rpx 0 0;
  420. background: #fff;
  421. transition: .5s ease;
  422. height: 32px;
  423. width: calc(100% / 2);
  424. top: 0;
  425. }
  426. .bg-location-1 {
  427. left: 0;
  428. transition: .5s ease;
  429. }
  430. .bg-location-2 {
  431. left: 50%;
  432. transition: .5s ease;
  433. }
  434. }
  435. .t-img {
  436. width: 70rpx;
  437. height: 60rpx;
  438. }
  439. .max-box {
  440. color: #0d81cf;
  441. border: 2rpx solid #0d81cf;
  442. padding: 6rpx 20rpx;
  443. }
  444. .convent-but {
  445. height: 80rpx;
  446. background: #0d81cf;
  447. color: #fff;
  448. line-height: 80rpx;
  449. }
  450. </style>