contract.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="contract-box">
  3. <view class="contract-top">
  4. <top-head :top-type="2"></top-head>
  5. </view>
  6. <view class="contract-data">
  7. <view class="data-input">
  8. <view class="input-item">
  9. <view class="item-detail">{{$t('index.contract.num')}}</view>
  10. <view class="item-detail" @click="getBnbNum">{{$t('index.contract.money')}}:{{bnbNum}}</view>
  11. </view>
  12. <view class="input-item">
  13. <view class="item-detail">{{investData.invest_money}}</view>
  14. <view class="item-detail item-img">
  15. <view class="text-img">
  16. <image src="@/static/img/index/bnb.png"></image>
  17. </view>
  18. <view class="text">BNB</view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="data-but">
  23. <button @click="setInvest">{{$t('index.index.pay')}}</button>
  24. </view>
  25. <view v-if="false" class="data-button" @click="goToUrl(1)">
  26. <image src="@/static/img/index/msg.svg"></image>
  27. <view>{{$t('index.contract.word')}}>></view>
  28. </view>
  29. </view>
  30. <view class="contract-list">
  31. <view class="list-title">
  32. <view class="title-img">
  33. <image src="@/static/img/index/bnb2.png" mode="aspectFill"></image>
  34. </view>
  35. <view class="title-text">{{$t('index.contract.list.title')}}({{total}})</view>
  36. </view>
  37. <division></division>
  38. <contract-list ref="contractListObj" @setTotal="setTotal"></contract-list>
  39. </view>
  40. <view class="contract-bottom"></view>
  41. </view>
  42. </template>
  43. <script>
  44. import TopHead from "@/pages/index/components/top-head";
  45. import Division from "@/pages/index/components/division";
  46. import ContractList from "@/pages/index/components/contract-list";
  47. import {getInvestData, setInvest} from "@/api/contract";
  48. import tools from "@/common/js/tools";
  49. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  50. export default {
  51. name: "contract",
  52. components: { ContractList, Division, TopHead},
  53. props: {},
  54. data() {
  55. return {
  56. total:0,
  57. bnbNum:0,
  58. investData: {
  59. id: 1,
  60. invest_money: '',
  61. sysAddress: "",
  62. sendNum: "",
  63. },
  64. }
  65. },
  66. watch: {},
  67. async mounted() {
  68. this.getInvestData()
  69. this.bnbNum = await tokenpocketBnb.getBalance();
  70. this.bnbNum=(this.bnbNum*1).toFixed(6)*1
  71. },
  72. methods: {
  73. async getBnbNum(){
  74. this.bnbNum = await tokenpocketBnb.getBalance();
  75. },
  76. getInvestData() {
  77. getInvestData().then((res) => {
  78. if (res.code === 1) {
  79. this.investData = res.data
  80. } else {
  81. tools.goToError(4)
  82. }
  83. }).catch((e) => {
  84. tools.goToError(4)
  85. })
  86. },
  87. async setInvest() {
  88. if (this.bnbNum < this.investData.invest_money && !tools.isDevelopment()) {
  89. tools.error(this.$t('index.index.invest.no_usdt'))
  90. return
  91. }
  92. if (this.isAjax) {
  93. return
  94. }
  95. // this.isAjax = true
  96. tokenpocketBnb.getTransactionData(this.investData.sysAddress, this.investData.invest_money).then((data) => {
  97. try {
  98. tokenpocketBnb.sendTransaction(data).then((res) => {
  99. this.sendSetInvest(res)
  100. }).catch((e) => {
  101. tools.error(this.$t('index.index.invest.send_no'))
  102. })
  103. } catch (e) {
  104. tools.error(this.$t('index.index.invest.send_no'))
  105. }
  106. })
  107. },
  108. sendSetInvest(hashRes) {
  109. setInvest({'txid': hashRes, 'id': this.investData.id}).then((res) => {
  110. if (res.code === 1) {
  111. tools.success(res.msg)
  112. this.$refs.contractListObj.startList()
  113. } else {
  114. this.isAjax = false
  115. tools.error(res.msg)
  116. }
  117. })
  118. },
  119. setTotal(total){
  120. this.total=total
  121. },
  122. goToUrl(type) {
  123. switch (type) {
  124. case 1:
  125. uni.navigateTo({
  126. 'url': 'pages/index/intro'
  127. })
  128. break
  129. }
  130. },
  131. }
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .contract-box {
  136. padding-top: 124rpx;
  137. box-shadow: 0 0 24rpx 0 rgba(0, 0, 0, 0.16);
  138. min-height: 100vh;
  139. .contract-top {
  140. //padding: 20rpx 0;
  141. background: #fff;
  142. }
  143. .contract-data {
  144. background: #fff;
  145. width: 90%;
  146. margin: 60rpx auto 0;
  147. border-radius: 20rpx;
  148. padding: 40rpx 20rpx;
  149. font-size: 36rpx;
  150. box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  151. .data-input {
  152. border: 1rpx solid #000;
  153. overflow: hidden;
  154. border-radius: 10rpx;
  155. padding: 20rpx;
  156. .input-item {
  157. display: flex;
  158. justify-content: space-between;
  159. .item-detail {
  160. font-size: 26rpx;
  161. }
  162. }
  163. .item-img {
  164. display: flex;
  165. justify-content: right;
  166. .text-img {
  167. display: inline-block;
  168. border-radius: 50%;
  169. height: 60rpx;
  170. width: 60rpx;
  171. box-sizing: border-box;
  172. margin-right: 10rpx;
  173. image {
  174. width: 60rpx;
  175. height: 60rpx;
  176. z-index: 100;
  177. }
  178. }
  179. .text {
  180. line-height: 60rpx;
  181. }
  182. }
  183. .input-item:first-child {
  184. margin-bottom: 40rpx;
  185. }
  186. .input-item:last-child {
  187. height: 60rpx;
  188. .item-detail {
  189. font-size: 32rpx;
  190. line-height: 60rpx;
  191. }
  192. }
  193. }
  194. .data-but {
  195. border-radius: 20rpx;
  196. margin-top: 60rpx;
  197. button {
  198. height: 90rpx;
  199. line-height: 90rpx;
  200. text-align: center;
  201. background: rgb(0, 87, 255);
  202. color: #fff;
  203. font-size: 26rpx;
  204. }
  205. }
  206. .data-button {
  207. margin-top: 40rpx;
  208. display: flex;
  209. justify-content: right;
  210. image {
  211. width: 40rpx;
  212. height: 40rpx;
  213. }
  214. view {
  215. font-size: 26rpx;
  216. margin-left: 10rpx;
  217. color: rgb(0, 87, 255);
  218. line-height: 40rpx;
  219. }
  220. }
  221. }
  222. .contract-list {
  223. background: #fff;
  224. width: 90%;
  225. margin: 40rpx auto;
  226. border-radius: 10px;
  227. padding: 20px 10px;
  228. overflow: hidden;
  229. font-size: 13px;
  230. box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  231. .list-title {
  232. display: flex;
  233. justify-content: left;
  234. .title-img {
  235. background: rgb(0, 87, 255);
  236. padding: 10rpx;
  237. border-radius: 20rpx;
  238. image {
  239. width: 80rpx;
  240. height: 80rpx;
  241. }
  242. }
  243. .title-text {
  244. margin-left: 20rpx;
  245. line-height: 100rpx;
  246. font-size: 34rpx;
  247. font-weight: bold;
  248. }
  249. }
  250. }
  251. .contract-bottom {
  252. height: 50rpx;
  253. }
  254. }
  255. </style>