home-index.vue 12 KB

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