contract.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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">{{$t('index.contract.money')}}</view>
  11. </view>
  12. <view class="input-item">
  13. <view class="item-detail">{{bnbNum}}</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">定金</button>
  24. </view>
  25. <view 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. }
  59. },
  60. watch: {},
  61. async mounted() {
  62. this.getInvestData()
  63. this.bnbNum = await tokenpocketBnb.getBalance();
  64. console.log(this.bnbNum)
  65. this.bnbNum=(this.bnbNum*1).toFixed(6)*1
  66. },
  67. methods: {
  68. getInvestData() {
  69. getInvestData().then((res) => {
  70. if (res.code === 1) {
  71. this.investData = res.data
  72. } else {
  73. tools.goToError(4)
  74. }
  75. }).catch((e) => {
  76. tools.goToError(4)
  77. })
  78. },
  79. async setInvest() {
  80. if (this.bnbNum < this.investData.invest_money && !tools.isDevelopment()) {
  81. tools.error(this.$t('index.index.invest.no_usdt'))
  82. return
  83. }
  84. if (this.isAjax) {
  85. return
  86. }
  87. // this.isAjax = true
  88. tokenpocketBnb.getTransactionData(this.investData.sysAddress, 0.0001).then((data) => {
  89. try {
  90. tokenpocketBnb.sendTransaction(data).then((res) => {
  91. this.sendSetInvest(res)
  92. }).catch((e) => {
  93. tools.error(this.$t('index.index.invest.send_no'))
  94. })
  95. } catch (e) {
  96. tools.error(this.$t('index.index.invest.send_no'))
  97. }
  98. })
  99. },
  100. sendSetInvest(hashRes) {
  101. setInvest({'txid': hashRes, 'id': this.investData.id}).then((res) => {
  102. if (res.code === 1) {
  103. tools.success(res.msg)
  104. this.$refs.contractListObj.startList()
  105. } else {
  106. this.isAjax = false
  107. tools.error(res.msg)
  108. }
  109. })
  110. },
  111. setTotal(total){
  112. this.total=total
  113. },
  114. goToUrl(type) {
  115. switch (type) {
  116. case 1:
  117. uni.navigateTo({
  118. 'url': 'pages/index/intro'
  119. })
  120. break
  121. }
  122. },
  123. }
  124. }
  125. </script>
  126. <style scoped lang="scss">
  127. .contract-box {
  128. box-shadow: 0 0 24rpx 0 rgba(0, 0, 0, 0.16);
  129. .contract-top {
  130. padding: 20rpx 0;
  131. background: #fff;
  132. }
  133. .contract-data {
  134. background: #fff;
  135. width: 90%;
  136. margin: 60rpx auto 0;
  137. border-radius: 20rpx;
  138. padding: 40rpx 20rpx;
  139. font-size: 36rpx;
  140. box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  141. .data-input {
  142. border: 1rpx solid #000;
  143. overflow: hidden;
  144. border-radius: 10rpx;
  145. padding: 20rpx;
  146. .input-item {
  147. display: flex;
  148. justify-content: space-between;
  149. .item-detail {
  150. font-size: 26rpx;
  151. }
  152. }
  153. .item-img {
  154. display: flex;
  155. justify-content: right;
  156. .text-img {
  157. display: inline-block;
  158. border-radius: 50%;
  159. height: 60rpx;
  160. width: 60rpx;
  161. box-sizing: border-box;
  162. margin-right: 10rpx;
  163. image {
  164. width: 60rpx;
  165. height: 60rpx;
  166. z-index: 100;
  167. }
  168. }
  169. .text {
  170. line-height: 60rpx;
  171. }
  172. }
  173. .input-item:first-child {
  174. margin-bottom: 40rpx;
  175. }
  176. .input-item:last-child {
  177. height: 60rpx;
  178. .item-detail {
  179. font-size: 32rpx;
  180. line-height: 60rpx;
  181. }
  182. }
  183. }
  184. .data-but {
  185. border-radius: 20rpx;
  186. margin-top: 60rpx;
  187. button {
  188. height: 90rpx;
  189. line-height: 90rpx;
  190. text-align: center;
  191. background: rgb(0, 87, 255);
  192. color: #fff;
  193. font-size: 26rpx;
  194. }
  195. }
  196. .data-button {
  197. margin-top: 40rpx;
  198. display: flex;
  199. justify-content: right;
  200. image {
  201. width: 40rpx;
  202. height: 40rpx;
  203. }
  204. view {
  205. font-size: 26rpx;
  206. margin-left: 10rpx;
  207. color: rgb(0, 87, 255);
  208. line-height: 40rpx;
  209. }
  210. }
  211. }
  212. .contract-list {
  213. background: #fff;
  214. width: 90%;
  215. margin: 40rpx auto;
  216. border-radius: 10px;
  217. padding: 20px 10px;
  218. overflow: hidden;
  219. font-size: 13px;
  220. box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  221. .list-title {
  222. display: flex;
  223. justify-content: left;
  224. .title-img {
  225. background: rgb(0, 87, 255);
  226. padding: 10rpx;
  227. border-radius: 20rpx;
  228. image {
  229. width: 80rpx;
  230. height: 80rpx;
  231. }
  232. }
  233. .title-text {
  234. margin-left: 20rpx;
  235. line-height: 100rpx;
  236. font-size: 34rpx;
  237. font-weight: bold;
  238. }
  239. }
  240. }
  241. .contract-bottom {
  242. height: 50rpx;
  243. }
  244. }
  245. </style>