home-index.vue 10 KB

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