home-index.vue 9.3 KB

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