add.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="add-box">
  3. <en-nav title="投资"></en-nav>
  4. <en-input type="number" v-model="investData.invest_money" :disabled="true" label="投资金额"></en-input>
  5. <view class="box-but">
  6. <button @click="setInvest">投资</button>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import EnNav from "@/components/en-utils/en-nav/en-nav";
  12. import EnInput from "@/components/en-from/en-input/en-input";
  13. import {getInvestData, setInvest} from "@/api/contract";
  14. import tools from "@/common/js/tools";
  15. import bitkeepTron from "@/common/wallet/bitkeep-wallet/bitkeep-tron";
  16. export default {
  17. name: "add",
  18. components: {EnInput, EnNav},
  19. props: {},
  20. data() {
  21. return {
  22. investData: {
  23. id: 1,
  24. invest_money: '',
  25. sysAddress: "",
  26. sendNum: "",
  27. },
  28. isAjax: false
  29. }
  30. },
  31. watch: {},
  32. mounted() {
  33. this.getInvestData()
  34. },
  35. methods: {
  36. getUsdtNum() {
  37. },
  38. getInvestData() {
  39. getInvestData().then((res) => {
  40. if (res.code === 1) {
  41. this.investData = res.data
  42. } else {
  43. tools.leftClick()
  44. }
  45. }).catch((e) => {
  46. tools.leftClick()
  47. })
  48. },
  49. async setInvest() {
  50. if (this.investData.sendNum > 0) {
  51. tools.error('有正在执行的交易')
  52. return;
  53. }
  54. let trxNum = await bitkeepTron.getBalance('');
  55. if (trxNum < 10) {
  56. tools.error('不低于TRX10')
  57. return
  58. }
  59. let usdtNum = await bitkeepTron.getTokenBalance('', 0);
  60. if (usdtNum < this.investData.invest_money && !tools.isDevelopment()) {
  61. tools.error('USDT数量不足')
  62. return
  63. }
  64. if (this.isAjax) {
  65. return
  66. }
  67. this.isAjax = true
  68. let transactionData = bitkeepTron.getContractData(this.investData.sysAddress, this.investData.invest_money,0)
  69. bitkeepTron.sendTransaction(transactionData).then((res) => {
  70. if (res) {
  71. setInvest().then((res)=>{
  72. if(res.code===1){
  73. tools.success(res.msg)
  74. setTimeout(()=>{
  75. tools.leftClick()
  76. },1500)
  77. }else {
  78. this.isAjax = false
  79. tools.error(res.msg)
  80. }
  81. })
  82. } else {
  83. this.isAjax = false
  84. tools.error('交易失败')
  85. }
  86. }).catch((e) => {
  87. this.isAjax = false
  88. tools.error('交易失败')
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .add-box {
  96. padding: 32rpx;
  97. background: #fff;
  98. .box-but {
  99. padding-top: 32rpx;
  100. button {
  101. background: #3169FA;
  102. color: #fff;
  103. font-size: 32rpx;
  104. }
  105. }
  106. }
  107. </style>