exchange.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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/index')">
  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("exchange.闪兑")}}</view>
  8. </view>
  9. <view class="listBox">
  10. <view class="name">{{$t("exchange.兑换")}}</view>
  11. <view class="redion">
  12. <u-radio-group class="flex" v-model="value">
  13. <u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in currList"
  14. :key="index" :label="item" :name="item" activeColor="#C29963">
  15. </u-radio>
  16. </u-radio-group>
  17. </view>
  18. <view class="listTpl">
  19. <view class="flex tplBox">
  20. <view class="flex_item tpl">
  21. <image src="/static/img/img23.png" style="width: 60rpx;height: 59rpx;"></image>
  22. <view class="title">NICE</view>
  23. </view>
  24. <view class="money">{{$t("exchange.余额")}}:{{userInfo.NICE * 1}}</view>
  25. </view>
  26. <view class="flex inputBox">
  27. <input type="number" v-model="money" @input="moneyInput" :placeholder='$t("exchange.请填写兑换的NICE数量")'/>
  28. <view class="all">MAX</view>
  29. </view>
  30. </view>
  31. <image class="reImg" src="../../static/img/img24.png" style="width: 85rpx;height: 86rpx;"></image>
  32. <view class="listTpl">
  33. <view class="flex tplBox">
  34. <view class="flex_item tpl">
  35. <image v-if="value == 'USDT'" src="/static/img/img25.png" style="width: 57rpx;height: 57rpx;"></image>
  36. <image v-if="value == 'NUSD'" src="/static/img/img23.png" style="width: 57rpx;height: 57rpx;"></image>
  37. <view class="title">{{value}}</view>
  38. </view>
  39. <view class="money" v-if="value == 'USDT'">{{$t("exchange.余额")}}:{{userInfo.USDT * 1}}</view>
  40. <view class="money" v-if="value == 'NUSD'">{{$t("exchange.余额")}}:{{userInfo.NUSD * 1}}</view>
  41. </view>
  42. <view class="flex inputBox">
  43. <input type="number" v-model="numUsdt" :placeholder='$t("exchange.实际到账的")+value' disabled/>
  44. <view class="all">MAX</view>
  45. </view>
  46. </view>
  47. <view class="tip">{{$t("exchange.兑换比率")}}:1NICE≈{{userInfo.nice_price}}{{value}}</view>
  48. <view class="submitBtn" :class="{ submitNo: !payOn }" @click="payOn ? clickSubmit() : ''" >{{$t("exchange.立即兑换")}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import topView from '../components/topView.vue';
  55. import {mapState,mapActions,mapMutations} from "vuex";
  56. import {exchange} from "@/api/index.js";
  57. export default {
  58. components: {
  59. topView
  60. },
  61. data() {
  62. return {
  63. money:'',
  64. numUsdt:'',
  65. payOn:true,
  66. currList:['USDT','NUSD'],
  67. value:'USDT',
  68. }
  69. },
  70. onLoad () {},
  71. onShow () {},
  72. computed: {
  73. ...mapState('user', ['userInfo']),
  74. },
  75. methods: {
  76. moneyInput(e){
  77. this.numUsdt = (e.detail.value)*this.userInfo.nice_price
  78. },
  79. clickSubmit(){
  80. let obj = this
  81. if(obj.money == ''){
  82. uni.showToast({
  83. title: obj.$t('exchange.请填写兑换的NICE数量'),
  84. icon: "none",
  85. });
  86. return;
  87. }
  88. if (obj.money > obj.userInfo.NICE) {
  89. uni.showToast({
  90. title: "NICE" + obj.$t('exchange.余额不足'),
  91. icon: "none",
  92. });
  93. return;
  94. }
  95. obj.payOn = false
  96. ethereum.request({
  97. method: 'eth_requestAccounts'
  98. }).then((account) => {
  99. const PKR_EXCHANGE = 'PKR_EXCHANGE' + (new Date()).getTime();
  100. ethereum.request({
  101. "method": "personal_sign",
  102. "params": [
  103. PKR_EXCHANGE,
  104. account[0]
  105. ]
  106. }).then((res) => {
  107. obj.exchange(res,PKR_EXCHANGE);
  108. });
  109. });
  110. },
  111. exchange(sign,msg){
  112. let obj = this
  113. exchange({
  114. sign,
  115. msg,
  116. num:obj.money,
  117. to_token:obj.value
  118. }).then(function(res){
  119. if(res.code == 0){
  120. obj.payOn = true
  121. uni.showToast({
  122. title:res.msg,
  123. icon: "error",
  124. });
  125. }else{
  126. obj.payOn = true
  127. uni.showToast({
  128. title: obj.$t('exchange.兑换成功'),
  129. icon: "success",
  130. });
  131. setTimeout(function () {
  132. obj.$router.go(0)
  133. }, 1000);
  134. }
  135. }).catch(e => {
  136. obj.payOn = true
  137. });
  138. },
  139. navTo(url){
  140. uni.navigateTo({
  141. url:url
  142. })
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="scss">
  148. page {
  149. width: 100%;
  150. min-height: 100vh;
  151. .container {
  152. width: 100%;
  153. min-height: 100vh;
  154. }
  155. }
  156. .redion{
  157. padding:25rpx 100rpx 25rpx 100rpx;
  158. }
  159. .infoBox{
  160. padding: 0rpx 25rpx;
  161. }
  162. .listBox{
  163. color: #fff;
  164. border-radius: 30rpx;
  165. border: 4rpx solid #DAB787;
  166. padding: 42rpx 57rpx;
  167. position: relative;
  168. .name{
  169. font-weight: bold;
  170. font-size: 34rpx;
  171. color: #FFFFFF;
  172. padding-bottom: 30rpx;
  173. }
  174. .listTpl{
  175. background: #2F2F2D;
  176. padding: 55rpx 30rpx;
  177. border-radius: 30rpx;
  178. margin-bottom: 31rpx;
  179. .tplBox{
  180. .title{
  181. font-size: 30rpx;
  182. padding-left: 15rpx;
  183. }
  184. .money{
  185. font-size: 30rpx;
  186. }
  187. }
  188. .inputBox{
  189. padding-top: 115rpx;
  190. padding-left: 25rpx;
  191. padding-bottom: 25rpx;
  192. .all{
  193. font-weight: 500;
  194. font-size: 32rpx;
  195. color: #1D69E2;
  196. background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
  197. -webkit-background-clip: text;
  198. -webkit-text-fill-color: transparent;
  199. }
  200. }
  201. }
  202. .reImg{
  203. position: absolute;
  204. left: 45%;
  205. top:42%;
  206. }
  207. }
  208. .tip{
  209. font-size: 30rpx;
  210. color: #FFFFFF;
  211. padding: 40rpx 0;
  212. }
  213. .submitBtn{
  214. background: linear-gradient(258deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
  215. border-radius: 10rpx;
  216. font-weight: bold;
  217. font-size: 32rpx;
  218. color: #31190B;
  219. line-height:90rpx;
  220. text-align: center;
  221. margin:25rpx 0;
  222. }
  223. .submitNo {
  224. background: #999999 !important;
  225. color: #fff !important;
  226. }
  227. .navBack{
  228. position: relative;
  229. color: #fff;
  230. text-align: center;
  231. margin: 30rpx 0rpx 40rpx 0rpx;
  232. .title{
  233. font-weight: bold;
  234. font-size: 34rpx;
  235. }
  236. }
  237. </style>