home-index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. getDividendList({
  86. 'page': this.page
  87. }).then(res => {
  88. if (res.code === 1) {
  89. this.list.push(...res.data.items)
  90. this.total = res.data.total
  91. }
  92. })
  93. },
  94. async addPledge() {
  95. if (this.listTab === 1) {
  96. if (this.coinNum < this.pledgeNUm) {
  97. tools.error('DAO不足')
  98. return
  99. }
  100. } else {
  101. if (this.pledgeTotal < this.pledgeNUm) {
  102. tools.error('贡献不足')
  103. return
  104. }
  105. let bnbNUm = tokenpocketBnb.getBalance(this.address)
  106. if (bnbNUm < this.bnb_num) {
  107. tools.error('BNB不足')
  108. return
  109. }
  110. }
  111. let data = ''
  112. let transactionData
  113. if (this.listTab === 1) {
  114. data = '0xa9059cbb'
  115. //icon转账
  116. let formHex = web3.utils.numberToHex(ethers.utils.parseEther(this.pledgeNUm.toString())
  117. .toString());
  118. data = data + tools.replenishZero(this.pledgeAddress) + tools.replenishZero(formHex)
  119. transactionData = await tokenpocketBnb.getContractTransaction(data, 0);
  120. } else {
  121. //bnb转账
  122. transactionData = await tokenpocketBnb.getTransactionData(this.pledgeAddress, this.bnb_num);
  123. }
  124. tokenpocketBnb.sendTransaction(transactionData).then(res => {
  125. if (res) {
  126. addPledge({
  127. 'type': this.listTab,
  128. 'money': this.pledgeNUm,
  129. 'hash': res
  130. }).then(res => {
  131. if (res.code === 0) {
  132. this.pledgeNUm = ''
  133. tools.success(res.msg)
  134. this.getTotalMoney()
  135. } else {
  136. tools.error(res.msg)
  137. }
  138. })
  139. } else {
  140. tools.error('发起失败')
  141. }
  142. console.log(res)
  143. })
  144. },
  145. scrolltolower() {
  146. if (this.list.length < this.total) {
  147. ++this.page
  148. this.getDividendList()
  149. // console.log('触底');
  150. }
  151. },
  152. getTotalMoney() {
  153. getTotalMoney().then(res => {
  154. if (res.code === 1) {
  155. this.pledgeTotal = res.data.pledgeTotal
  156. this.revenueTotal = res.data.revenueTotal
  157. this.price = res.data.price
  158. }
  159. })
  160. },
  161. async getIconNum() {
  162. if (this.address === '') {
  163. return
  164. }
  165. setTimeout(async () => {
  166. this.coinNum = await tokenpocketBnb.getTokenBalance(this.address, 0)
  167. console.log(this.coinNum, "icon-num----------------------")
  168. }, 100)
  169. },
  170. setMax() {
  171. if (this.listTab === 1) {
  172. this.pledgeNUm = this.coinNum
  173. } else {
  174. this.pledgeNUm = this.pledgeTotal
  175. }
  176. },
  177. },
  178. }
  179. </script>
  180. <template>
  181. <view>
  182. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40">
  183. <image class="head-img" :src="require('@/static/img/index/index/bannerhome.png')" mode="widthFix"></image>
  184. </view>
  185. <view class="bgc-f p-20 box-sizing-border b-rad-20 mb-40">
  186. <view class="b-rad-20 h-80 align-items-center bgc-f1f9fe">
  187. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  188. <view class="fs-28 mb-8">
  189. DAO價格($)
  190. </view>
  191. <view class="fs-28 fw-b">
  192. {{price}}
  193. </view>
  194. </view>
  195. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  196. <view class="fs-28 mb-8">
  197. DAO餘額
  198. </view>
  199. <view class="fs-28 fw-b">
  200. {{coinNum}}
  201. </view>
  202. </view>
  203. <view class="flex-1 flex-direction-column align-items-center flex-justify-center">
  204. <view class="fs-28 mb-8">
  205. 贡献总额
  206. </view>
  207. <view class="fs-28 fw-b">
  208. {{pledgeTotal}}
  209. </view>
  210. </view>
  211. </view>
  212. </view>
  213. <view class="list-tab">
  214. <view class="tab-items">
  215. <view class="tab-item" @click="setListTab(1)" :class="{'option-tab':listTab===1}">
  216. 质押
  217. </view>
  218. <view class="tab-item" @click="setListTab(2)" :class="{'option-tab':listTab===2}">
  219. 解压
  220. </view>
  221. <!-- <view class="tab-item" @click="setListTab(3)" :class="{'option-tab':listTab===3}">-->
  222. <!-- {{ $t('index.index.code') }}-->
  223. <!-- </view>-->
  224. </view>
  225. <view class="tab-item-bg"
  226. :class="{'bg-location-1':listTab===1,'bg-location-2':listTab===2,'bg-location-3':listTab===3}"></view>
  227. <view class="bgc-f p-40">
  228. <view class="bgc-F6F7FA b-rad-20 mb-20 p-20 box-sizing-border mb-20">
  229. <view class="align-items-start flex-justify-space mb-20">
  230. <view class="align-items-center">
  231. <image class="t-img mr-8" :src="require('@/static/img/logo/logo.png')"></image>
  232. <view class="fs-28">DAO</view>
  233. </view>
  234. <view class="max-box b-rad-20 fs-28" @click="setMax">
  235. Max {{listTab===1 ?coinNum:pledgeTotal}}
  236. </view>
  237. </view>
  238. <view>
  239. <input v-model="pledgeNUm" :placeholder="'输入要'+(listTab===1 ?'质押':'解压')+'的DAO数量'"
  240. placeholder-class="fs-28"></input>
  241. </view>
  242. </view>
  243. <view class="convent-but b-rad-20 text-align-center fs-28 fc-f" @click="addPledge">
  244. 确定
  245. </view>
  246. </view>
  247. </view>
  248. <view class="bgc-f p-20 box-sizing-border b-rad-20">
  249. <view class="fs-28 pt-5 mb-8">
  250. 分红记录
  251. </view>
  252. <view v-if="list.length<=0" class="blank-box align-items-center flex-justify-center">
  253. <blank :showBlank="list.length<=0?true:false" message="暂无数据"></blank>
  254. </view>
  255. <view class="bgc-F6F7FA" v-else>
  256. <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">
  257. <view>
  258. <view class="mb-8 fs-28 fw-b">贡献 {{item.pledge_money}} DAO</view>
  259. <view class="fs-24">{{item.created_date}}</view>
  260. </view>
  261. <view class="align-items-center">
  262. <view class="fs-24">分红:</view>
  263. <view class="fs-28 fc-ED301D">{{item.sorting_money}}</view>
  264. </view>
  265. </view>
  266. <!-- <view class="h-50 text-align-center fs-28">-->
  267. <!-- ~暂无记录-->
  268. <!-- </view>-->
  269. </view>
  270. <!-- <view class="bgc-F6F7FA" v-else>-->
  271. <!-- <view class="item-box align-items-center flex-justify-space" v-for="item in list" :key="item.id">-->
  272. <!-- <view>-->
  273. <!-- <view class="mb-8 fs-28 fw-b">{{item.type===1?'质押':'解压'}}</view>-->
  274. <!-- <view class="fs-24">{{item.created_date}}</view>-->
  275. <!-- </view>-->
  276. <!-- <view class="">-->
  277. <!-- <view class="fs-24" v-if="item.status===1">执行中</view>-->
  278. <!-- <view class="fs-24" v-else-if="item.status===2">已完成</view>-->
  279. <!-- <view class="fs-24" v-else>已作废</view>-->
  280. <!-- <view class="fs-28 ">数量:<text class="fc-ED301D">{{item.money}}</text></view>-->
  281. <!-- </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>