home-index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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.type===1?'质押':'解压'}}</view>
  259. <view class="fs-24">{{item.created_date}}</view>
  260. </view>
  261. <view class="">
  262. <view class="fs-24" v-if="item.status===1">执行中</view>
  263. <view class="fs-24" v-else-if="item.status===2">已完成</view>
  264. <view class="fs-24" v-else>已作废</view>
  265. <view class="fs-28 ">数量:<text class="fc-ED301D">{{item.money}}</text></view>
  266. </view>
  267. </view>
  268. </view>
  269. </view>
  270. </view>
  271. </template>
  272. <style scoped lang="scss">
  273. .head-img {
  274. width: 100%;
  275. // height: 128px;
  276. }
  277. .h-80 {
  278. height: 160rpx;
  279. }
  280. .h-50 {
  281. height: 100rpx;
  282. line-height: 100rpx;
  283. }
  284. .item-box {
  285. width: 100%;
  286. height: 120rpx;
  287. padding: 10rpx 20rpx;
  288. box-sizing: border-box;
  289. border-top: 2rpx solid #e5e5e5;
  290. }
  291. .item-box:first-child {
  292. border-top: none;
  293. }
  294. .list-tab {
  295. width: 100%;
  296. height: 100%;
  297. background: #eaf2ff;
  298. border-radius: 10rpx;
  299. cursor: pointer;
  300. position: relative;
  301. margin: 20rpx 0;
  302. .tab-items {
  303. z-index: 10;
  304. display: flex;
  305. justify-content: space-between;
  306. border-radius: 10rpx;
  307. .tab-item {
  308. z-index: 10;
  309. width: calc(100% / 2);
  310. font-size: 13px;
  311. color: #adbad0;
  312. display: block;
  313. height: 32px;
  314. line-height: 32px;
  315. text-align: center;
  316. }
  317. .option-tab {
  318. color: #292929;
  319. }
  320. }
  321. .tab-item-bg {
  322. position: absolute;
  323. border-radius: 10rpx 10rpx 0 0;
  324. background: #fff;
  325. transition: .5s ease;
  326. height: 32px;
  327. width: calc(100% / 2);
  328. top: 0;
  329. }
  330. .bg-location-1 {
  331. left: 0;
  332. transition: .5s ease;
  333. }
  334. .bg-location-2 {
  335. left: 50%;
  336. transition: .5s ease;
  337. }
  338. }
  339. .t-img {
  340. width: 70rpx;
  341. height: 60rpx;
  342. }
  343. .max-box {
  344. color: #0d81cf;
  345. border: 2rpx solid #0d81cf;
  346. padding: 6rpx 20rpx;
  347. }
  348. .convent-but {
  349. height: 80rpx;
  350. background: #0d81cf;
  351. color: #fff;
  352. line-height: 80rpx;
  353. }
  354. </style>