contract.vue 6.3 KB

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