recharge.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="container" style="padding-top: 100rpx;">
  3. <topView :backg="'#1A1A17'"></topView>
  4. <view class="infoBox">
  5. <view class="navBack" @click="navTo('/pages/index/property')">
  6. <u-icon name="arrow-left" size="25" color="#fff" style="position: absolute;left: 0;top: 0;font-weight: bold;"></u-icon>
  7. <view class="title">{{$t("property.充值")}}</view>
  8. </view>
  9. <view class="infoTpl">
  10. <view class="flex tplTop">
  11. <view class="name">{{$t("recharge.充值数量")}}</view>
  12. <view class="tip">{{$t("recharge.可用")}}{{userInfo.NUSD * 1}}NUSD</view>
  13. </view>
  14. <view class="flex inputBox">
  15. <input type="number" v-model="money" :placeholder='$t("recharge.请输入充值数量")'/>
  16. <!-- <view class="clickAll" @click="money = userInfo.NUSD * 1">NUSD 全部</view> -->
  17. </view>
  18. <!-- <view class="name">手续费</view>
  19. <view class="flex inputBox">
  20. <input v-model="free"/>
  21. <view class="freeTip">USTD</view>
  22. </view> -->
  23. </view>
  24. </view>
  25. <view class="footBox">
  26. <!-- <view class="flex numBox">
  27. <view class="numName">实际到账</view>
  28. <view class="num">{{num}}</view>
  29. </view> -->
  30. <view class="btnBox">
  31. <view class="submitBtn" :class="{ submitNo: !payOn }" @click="payOn ? recharge() : ''">{{$t("property.充值")}}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import topView from '../components/topView.vue';
  38. import {mapState,mapActions,mapMutations} from "vuex";
  39. import {charge,chargeCalculator} from "@/api/index.js";
  40. export default {
  41. components: {
  42. topView
  43. },
  44. data () {
  45. return {
  46. money:"",
  47. free:"--",
  48. payOn:true
  49. }
  50. },
  51. onLoad () {
  52. },
  53. computed: {
  54. ...mapState('user', ['userInfo']),
  55. },
  56. methods: {
  57. async recharge(){
  58. let obj = this;
  59. if (obj.money == '') {
  60. uni.showToast({
  61. title: obj.$t("recharge.请输入充值数量"),
  62. icon: "none",
  63. });
  64. return;
  65. }
  66. obj.payOn = false
  67. try {
  68. const res = await chargeCalculator({
  69. token: 'NUSD',
  70. num: obj.money,
  71. });
  72. uni.showLoading({
  73. title: "loading...",
  74. mask: true,
  75. });
  76. const txHash = await ethereum.request({
  77. method: "eth_sendTransaction",
  78. params: [{
  79. from: obj.userInfo.address,
  80. to: res.data.data.to,
  81. value: 0,
  82. data: res.data.data.data,
  83. }, ],
  84. });
  85. const req = await charge({
  86. token: 'NUSD',
  87. num: obj.money,
  88. transactionHash: txHash
  89. });
  90. obj.payOn = true
  91. uni.showToast({
  92. title:obj.$t("recharge.请等待审核"),
  93. icon:'success'
  94. });
  95. obj.money = ''
  96. // setTimeout(function () {
  97. // obj.$router.go(0)
  98. // }, 1000);
  99. } catch (e) {
  100. obj.payOn = true
  101. uni.showToast({
  102. title: obj.$t("recharge.充值成功"),
  103. icon:"error"
  104. });
  105. }
  106. },
  107. navTo(url){
  108. uni.navigateTo({
  109. url:url
  110. })
  111. },
  112. },
  113. }
  114. </script>
  115. <style lang="scss">
  116. page {
  117. width: 100%;
  118. min-height: 100vh;
  119. .container {
  120. width: 100%;
  121. min-height: 100vh;
  122. }
  123. }
  124. .topBox {
  125. color: #FFE0BD;
  126. padding: 25rpx 27rpx;
  127. background: #1A1A17;
  128. .topTpl {
  129. .addr {
  130. padding: 6rpx 25rpx;
  131. background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
  132. box-shadow: 3rpx 4rpx 5rpx 0rpx rgba(151, 118, 74, 0.5);
  133. border-radius: 21rpx;
  134. font-size: 24rpx;
  135. font-family: PingFang SC;
  136. font-weight: 500;
  137. color: #986629;
  138. }
  139. }
  140. }
  141. .infoBox{
  142. padding: 0rpx 30rpx;
  143. color: #fff;
  144. }
  145. .navBack{
  146. position: relative;
  147. color: #fff;
  148. text-align: center;
  149. margin: 30rpx 0rpx 40rpx 0rpx;
  150. .title{
  151. font-weight: bold;
  152. font-size: 34rpx;
  153. }
  154. }
  155. .infoTpl{
  156. background: #1A1A17;
  157. padding: 85rpx 25rpx;
  158. border-radius: 25rpx;
  159. .tplTop{
  160. .tip{
  161. font-size: 20rpx;
  162. }
  163. }
  164. .inputBox{
  165. background: #2F2F2D;
  166. padding: 25rpx 25rpx;
  167. border-radius: 25rpx;
  168. margin-bottom: 61rpx;
  169. .clickAll{
  170. font-size: 26rpx;
  171. }
  172. .freeTip{
  173. font-size: 30rpx;
  174. color: #888785;
  175. }
  176. }
  177. }
  178. .footBox{
  179. position: fixed;
  180. bottom: 0;
  181. width: 100%;
  182. background: #1A1A17;
  183. color: #fff;
  184. padding: 50rpx 42rpx;
  185. .numBox{
  186. .numName{
  187. font-weight: 500;
  188. font-size: 26rpx;
  189. color: #888785;
  190. }
  191. }
  192. .btnBox{
  193. // margin-top: 50rpx;
  194. .submitBtn{
  195. background: linear-gradient(258deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
  196. border-radius: 10rpx;
  197. font-weight: bold;
  198. font-size: 32rpx;
  199. color: #31190B;
  200. text-align: center;
  201. padding: 20rpx 0rpx;
  202. }
  203. .submitNo {
  204. background: #999999 !important;
  205. color: #fff !important;
  206. }
  207. }
  208. }
  209. .name{
  210. font-size: 32rpx;
  211. font-weight: bold;
  212. padding-bottom: 35rpx;
  213. }
  214. </style>