home-index.vue 14 KB

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