transfer.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="container">
  3. <view class="infoBox">
  4. <view class="title">{{$t("transfer.收款地址")}}</view>
  5. <view class="inputBox">
  6. <view class="flex_item inpitTpl">
  7. <image src="/static/img/img21.png" style="width: 33rpx;height: 36rpx;margin-right: 25rpx;"></image>
  8. <input type="text" :placeholder='$t("transfer.请输入或长按粘贴地址")' v-model="address" style="width: 100%;"/>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="infoBox">
  13. <view class="title">{{$t("transfer.转账金额")}}</view>
  14. <view class="inputBox flex">
  15. <view class="flex_item inpitTpl">
  16. <image src="/static/img/img21.png" style="width: 33rpx;height: 36rpx;margin-right: 25rpx;"></image>
  17. <input type="text" :placeholder='$t("transfer.请输入转账金额")' v-model="money"/>
  18. </view>
  19. <view class="all" @click="money = userInfo.NUSD * 1">{{$t("transfer.全部")}}</view>
  20. </view>
  21. <view class="tipTpl">{{$t("transfer.可转账余额")}}:{{userInfo.NUSD * 1}}NUSD</view>
  22. </view>
  23. <!-- <view class="infoBox">
  24. <view class="title">手续费</view>
  25. <view class="inputBox flex">
  26. <input type="text" v-model="free"/>
  27. <view class="tip">USTD</view>
  28. </view>
  29. </view> -->
  30. <view class="footBox">
  31. <!-- <view class="flex numBox">
  32. <view class="numName">实际到账</view>
  33. <view class="num">{{num}}</view>
  34. </view> -->
  35. <view class="btnBox">
  36. <view class="submitBtn" :class="{ submitNo: !payOn }" @click="payOn ? transfer() : ''">{{$t("property.转账")}}</view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {getUserInfo,trade} from '@/api/login.js';
  43. export default {
  44. data () {
  45. return {
  46. address:"",
  47. money:"",
  48. free:"--",
  49. num:"--",
  50. userInfo:'',
  51. payOn:true
  52. }
  53. },
  54. onLoad () {
  55. this.getUserInfo()
  56. },
  57. onShow () {
  58. uni.setNavigationBarTitle({
  59. title: this.$t("property.转账")
  60. });
  61. },
  62. methods: {
  63. transfer(){
  64. let obj = this
  65. if(obj.address == ''){
  66. uni.showToast({
  67. title: this.$t("transfer.请输入收款地址"),
  68. icon: "none",
  69. });
  70. return;
  71. }
  72. if(obj.money == ''){
  73. uni.showToast({
  74. title: this.$t("transfer.请输入转账金额"),
  75. icon: "none",
  76. });
  77. return;
  78. }
  79. obj.payOn = false
  80. ethereum.request({
  81. method: 'eth_requestAccounts'
  82. }).then((account) => {
  83. const PKR_TRADE = 'PKR_TRADE' + (new Date()).getTime();
  84. ethereum.request({
  85. "method": "personal_sign",
  86. "params": [
  87. PKR_TRADE,
  88. account[0]
  89. ]
  90. }).then((res) => {
  91. obj.trade(res,PKR_TRADE);
  92. });
  93. });
  94. },
  95. trade(sign,msg){
  96. let obj = this
  97. trade({
  98. sign,
  99. msg,
  100. address:obj.address,
  101. token:'NUSD',
  102. num:obj.money,
  103. }).then(function(res){
  104. if(res.code == 0){
  105. obj.payOn = true
  106. uni.showToast({
  107. title: obj.$t("transfer.参数错误"),
  108. icon: "error",
  109. });
  110. }else{
  111. uni.showToast({
  112. title:obj.$t("transfer.转账成功"),
  113. icon: "success",
  114. });
  115. obj.payOn = true
  116. setTimeout(function () {
  117. obj.$router.go(0)
  118. }, 1000);
  119. }
  120. }).catch(e => {
  121. obj.payOn = true
  122. console.log(e,11111);
  123. });
  124. },
  125. getUserInfo(){
  126. let obj = this
  127. getUserInfo({}).then(({data}) => {
  128. obj.userInfo = data
  129. }).catch(e => {
  130. console.log(e.msg);
  131. });
  132. },
  133. },
  134. }
  135. </script>
  136. <style lang="scss">
  137. page {
  138. width: 100%;
  139. .container {
  140. width: 100%;
  141. }
  142. }
  143. .infoBox{
  144. color: #fff;
  145. padding: 58rpx 38rpx 0rpx 38rpx;
  146. .title{
  147. font-weight: bold;
  148. font-size: 32rpx;
  149. padding-bottom: 10rpx;
  150. }
  151. .inputBox{
  152. border-bottom: 1rpx solid #CBCBCA;
  153. padding: 30rpx 0rpx;
  154. .all{
  155. font-weight: 500;
  156. font-size: 28rpx;
  157. color: #ABB1CC;
  158. background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
  159. -webkit-background-clip: text;
  160. -webkit-text-fill-color: transparent;
  161. }
  162. .tip{
  163. font-weight: 500;
  164. font-size: 30rpx;
  165. color: #888785;
  166. }
  167. }
  168. .tipTpl{
  169. font-weight: 500;
  170. font-size: 24rpx;
  171. color: #888785;
  172. padding-top: 15rpx;
  173. }
  174. }
  175. .footBox{
  176. position: fixed;
  177. bottom: 0;
  178. width: 100%;
  179. background: #1A1A17;
  180. color: #fff;
  181. padding: 50rpx 42rpx;
  182. .numBox{
  183. .numName{
  184. font-weight: 500;
  185. font-size: 26rpx;
  186. color: #888785;
  187. }
  188. }
  189. .btnBox{
  190. .submitBtn{
  191. background: linear-gradient(258deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
  192. border-radius: 10rpx;
  193. font-weight: bold;
  194. font-size: 32rpx;
  195. color: #31190B;
  196. text-align: center;
  197. padding: 20rpx 0rpx;
  198. }
  199. .submitNo {
  200. background: #999999 !important;
  201. color: #fff !important;
  202. }
  203. }
  204. }
  205. </style>