withdrawal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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("withdrawal.提币")}}</view>
  8. </view>
  9. <view class="redion">
  10. <u-radio-group class="flex" v-model="value">
  11. <u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in currList"
  12. :key="index" :label="item" :name="item" activeColor="#C29963">
  13. </u-radio>
  14. </u-radio-group>
  15. </view>
  16. <view class="infoTpl">
  17. <view class="flex tplTop">
  18. <view class="name">{{$t("withdrawal.提币數量")}}</view>
  19. <view class="tip" v-if="value == 'USDT'">{{$t("withdrawal.可用")}}{{userInfo.USDT * 1}}USDT</view>
  20. <view class="tip" v-if="value == 'NICE'">{{$t("withdrawal.可用")}}{{userInfo.NICE * 1}}NICE</view>
  21. </view>
  22. <view class="flex inputBox">
  23. <input type="number" v-model="money" @input="inputMonry" :placeholder='$t("withdrawal.请输入提币数量")'/>
  24. <view class="clickAll" v-if="value == 'USDT'" @click="money = userInfo.USDT * 1">USDT {{$t("withdrawal.全部")}}</view>
  25. <view class="clickAll" v-if="value == 'NICE'" @click="money = userInfo.NICE * 1">NICE {{$t("withdrawal.全部")}}</view>
  26. </view>
  27. <view class="name">{{$t("withdrawal.手续费")}}</view>
  28. <view class="flex inputBox">
  29. <input v-model="free" disabled/>
  30. <view class="freeTip">{{value}}</view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="footBox">
  35. <view class="flex numBox">
  36. <view class="numName">{{$t("withdrawal.实际到账")}}</view>
  37. <view class="num">{{num}}</view>
  38. </view>
  39. <view class="btnBox">
  40. <view class="submitBtn" :class="{ submitNo: !payOn }" @click="payOn ? clickExtract() : ''">{{$t("withdrawal.提币")}}</view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import topView from '../components/topView.vue';
  47. import {extract,extractCalculator} from "@/api/index.js";
  48. import {mapState,mapActions,mapMutations} from "vuex";
  49. export default {
  50. components: {
  51. topView
  52. },
  53. data () {
  54. return {
  55. money:"",
  56. free:"--",
  57. num:'0.00',
  58. payOn:true,
  59. value:'USDT',
  60. currList:['USDT','NICE']
  61. }
  62. },
  63. onLoad () {},
  64. computed: {
  65. ...mapState('user', ['userInfo']),
  66. },
  67. methods: {
  68. inputMonry(e){
  69. this.free = e.detail.value * (this.userInfo.extract_fee/100)
  70. this.num = e.detail.value - this.free
  71. },
  72. //提取
  73. async clickExtract() {
  74. let obj = this;
  75. if (obj.money == '') {
  76. uni.showToast({
  77. title: obj.$t("withdrawal.请输入提币数量"),
  78. icon: "none",
  79. });
  80. return;
  81. }
  82. if (obj.money < 100) {
  83. uni.showToast({
  84. title: obj.$t("withdrawal.提币数量大于100"),
  85. icon: "none",
  86. });
  87. return;
  88. }
  89. if(obj.value == 'USDT'){
  90. if (obj.money > obj.userInfo.USDT) {
  91. uni.showToast({
  92. title: "USDT" + obj.$t("exchange.余额不足"),
  93. icon: "none",
  94. });
  95. return;
  96. }
  97. }
  98. if(obj.value == 'NICE'){
  99. if (obj.money > obj.userInfo.NICE) {
  100. uni.showToast({
  101. title: "NICE" + obj.$t("exchange.余额不足"),
  102. icon: "none",
  103. });
  104. return;
  105. }
  106. }
  107. obj.payOn = false
  108. try {
  109. const res = await extractCalculator({
  110. token: obj.value,
  111. number: obj.money,
  112. });
  113. if(res.data.msg == '提币数量大于100'){
  114. obj.payOn = true
  115. uni.showToast({
  116. title: obj.$t("withdrawal.提币数量大于100"),
  117. icon: "error",
  118. });
  119. }else{
  120. const txHash = await ethereum.request({
  121. method: "eth_sendTransaction",
  122. params: [{
  123. from: obj.userInfo.address,
  124. to: res.data.to,
  125. value: (res.data.gas*1).toString(16),
  126. }, ],
  127. });
  128. uni.showLoading({
  129. title: "loading...",
  130. mask: true,
  131. });
  132. const req = await extract({
  133. token: obj.value,
  134. number: obj.money,
  135. transactionHash: txHash,
  136. });
  137. obj.payOn = true
  138. uni.showToast({
  139. title: this.$t("withdrawal.提取成功"),
  140. });
  141. setTimeout(function () {
  142. obj.$router.go(0)
  143. }, 1000);
  144. }
  145. } catch (e) {
  146. obj.payOn = true
  147. uni.showToast({
  148. title: this.$t("withdrawal.提取失败"),
  149. icon: "error",
  150. });
  151. }
  152. },
  153. navTo(url){
  154. uni.navigateTo({
  155. url:url
  156. })
  157. },
  158. },
  159. }
  160. </script>
  161. <style lang="scss">
  162. page {
  163. width: 100%;
  164. min-height: 100vh;
  165. .container {
  166. width: 100%;
  167. min-height: 100vh;
  168. }
  169. }
  170. .topBox {
  171. color: #FFE0BD;
  172. padding: 25rpx 27rpx;
  173. background: #1A1A17;
  174. .topTpl {
  175. .addr {
  176. padding: 6rpx 25rpx;
  177. background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
  178. box-shadow: 3rpx 4rpx 5rpx 0rpx rgba(151, 118, 74, 0.5);
  179. border-radius: 21rpx;
  180. font-size: 24rpx;
  181. font-family: PingFang SC;
  182. font-weight: 500;
  183. color: #986629;
  184. }
  185. }
  186. }
  187. .infoBox{
  188. padding: 0rpx 30rpx;
  189. color: #fff;
  190. }
  191. .navBack{
  192. position: relative;
  193. color: #fff;
  194. text-align: center;
  195. margin: 30rpx 0rpx 40rpx 0rpx;
  196. .title{
  197. font-weight: bold;
  198. font-size: 34rpx;
  199. }
  200. }
  201. .redion{
  202. padding:25rpx 150rpx 25rpx 150rpx;
  203. }
  204. .infoTpl{
  205. background: #1A1A17;
  206. padding: 85rpx 25rpx;
  207. border-radius: 25rpx;
  208. .tplTop{
  209. .tip{
  210. font-size: 20rpx;
  211. }
  212. }
  213. .inputBox{
  214. background: #2F2F2D;
  215. padding: 25rpx 25rpx;
  216. border-radius: 25rpx;
  217. margin-bottom: 61rpx;
  218. .clickAll{
  219. font-size: 26rpx;
  220. }
  221. .freeTip{
  222. font-size: 30rpx;
  223. color: #888785;
  224. }
  225. }
  226. }
  227. .footBox{
  228. position: fixed;
  229. bottom: 0;
  230. width: 100%;
  231. background: #1A1A17;
  232. color: #fff;
  233. padding: 50rpx 42rpx;
  234. .numBox{
  235. .numName{
  236. font-weight: 500;
  237. font-size: 26rpx;
  238. color: #888785;
  239. }
  240. }
  241. .btnBox{
  242. margin-top: 50rpx;
  243. .submitBtn{
  244. background: linear-gradient(258deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
  245. border-radius: 10rpx;
  246. font-weight: bold;
  247. font-size: 32rpx;
  248. color: #31190B;
  249. text-align: center;
  250. padding: 20rpx 0rpx;
  251. }
  252. .submitNo {
  253. background: #999999 !important;
  254. color: #fff !important;
  255. }
  256. }
  257. }
  258. .name{
  259. font-size: 32rpx;
  260. font-weight: bold;
  261. padding-bottom: 35rpx;
  262. }
  263. </style>