add.vue 2.7 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. getInvestData() {
  37. getInvestData().then((res) => {
  38. if (res.code === 1) {
  39. this.investData = res.data
  40. } else {
  41. tools.leftClick()
  42. }
  43. }).catch((e) => {
  44. tools.leftClick()
  45. })
  46. },
  47. async setInvest() {
  48. if (this.investData.sendNum > 0) {
  49. tools.error('有正在执行的交易')
  50. return;
  51. }
  52. let trxNum = await bitkeepTron.getBalance('');
  53. if (trxNum < 10) {
  54. tools.error('不低于TRX10')
  55. return
  56. }
  57. let usdtNum = await bitkeepTron.getTokenBalance('', 0);
  58. if (usdtNum < this.investData.invest_money && !tools.isDevelopment()) {
  59. tools.error('USDT数量不足')
  60. return
  61. }
  62. if (this.isAjax) {
  63. return
  64. }
  65. this.isAjax = true
  66. let transactionData = bitkeepTron.getContractData(this.investData.sysAddress, this.investData.invest_money,0)
  67. console.log('transactionData:')
  68. console.log(transactionData)
  69. bitkeepTron.sendTransaction(transactionData).then((res) => {
  70. if (res) {
  71. setInvest({'txid':res,'id':this.investData.id}).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>