convert.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="center">
  3. <view class="rateBox">
  4. <view class="rateTitle">实时汇率</view>
  5. <view class="rate">{{ exchange }}</view>
  6. </view>
  7. <view class="rateConetnt" v-if="lodingType">
  8. <view class="titleBox flex">
  9. <view class="leftTip"></view>
  10. <view class="title">兑换币种</view>
  11. </view>
  12. <view class="content">
  13. <view class="moneyText">兑出币种</view>
  14. <view class="Type flex">
  15. <image class="moneylogo" :src="moneyType[index].LOGO" mode="scaleToFill"></image>
  16. <view class="moneyName clamp" @click="show = true">{{moneyType[index].name}}</view>
  17. <u-icon name="arrow-down-fill" color="#0F253A" size="10"></u-icon>
  18. <u-input :height="45" class="input" v-model="pushMoney" type="number" :border="false" placeholder="请输入需要兑换的数量" />
  19. </view>
  20. <view class="contentImg"><image class="img" src="../../static/img/tab.png" mode="scaleToFill"></image></view>
  21. <view class="moneyText">兑入币种</view>
  22. <view class="Type flex">
  23. <image class="moneylogo" :src="add.LOGO" mode="scaleToFill"></image>
  24. <view class="moneyName clamp">{{ add.name }}</view>
  25. <view class="line"></view>
  26. <view class="input">{{ moneyReta }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="lsButtom" @click="buy()">确认兑换</view>
  31. <u-action-sheet :list="moneyType" v-model="show" @click="changeIndex"></u-action-sheet>
  32. </view>
  33. </template>
  34. <script>
  35. import { recharge, wallet, moneyType } from '@/api/finance.js';
  36. export default {
  37. data() {
  38. return {
  39. index: 0, //当前选中的兑出币种
  40. moneyType: [],//兑出币种类型
  41. add: { LOGO: '', name: '' }, //兑入币种
  42. pushMoney: '',//要兑换的金额
  43. lodingType: false, //判断是否已经载入币种分类分类数据
  44. show: false
  45. };
  46. },
  47. computed: {
  48. // 转换金额
  49. moneyReta() {
  50. // 保存当前选中的对象
  51. const obj = this.moneyType[this.index];
  52. return (this.pushMoney * +obj.usdt_price) / +this.add.usdt_price;
  53. },
  54. // 实时汇率
  55. exchange() {
  56. try {
  57. const data = this.moneyType[this.index];
  58. return 1 + data.name + '≈' + data.usdt_price / this.add.usdt_price + this.add.name;
  59. } catch (e) {
  60. console.log(e);
  61. return '加载中...';
  62. }
  63. }
  64. },
  65. //页面加载即刻发生
  66. onLoad() {
  67. this.init();
  68. },
  69. methods: {
  70. // 初始化页面
  71. init() {
  72. this.wallet();
  73. },
  74. // 弹出层选择事件
  75. changeIndex(e){
  76. console.log(e);
  77. this.index = e;
  78. },
  79. // 加载币种分类
  80. wallet() {
  81. let that = this;
  82. console.log('请求兑换');
  83. uni.showLoading({
  84. title: '载入数据中...',
  85. mask: true
  86. });
  87. wallet()
  88. .then(e => {
  89. uni.hideLoading();
  90. that.lodingType = true;
  91. const moneyType = Object.keys(e.data.back);
  92. moneyType.forEach(es => {
  93. const data = e.data.back[es];
  94. data.text = data.name;
  95. if (+data.do_exchange == 1) {
  96. that.moneyType.push(data);
  97. }
  98. if (+data.exchange == 1) {
  99. that.add = data;
  100. console.log(e.data.back[es], '555');
  101. }
  102. });
  103. console.log(that.moneyType);
  104. console.log(that.add, '兑入');
  105. })
  106. .catch(e => {
  107. uni.hideLoading();
  108. if (e.status != 410000) {
  109. that.lodingType = true;
  110. uni.showModal({
  111. title: '错误',
  112. content: '加载失败请刷新页面',
  113. cancelText: '关闭',
  114. confirmText: '刷新',
  115. success: res => {
  116. if (res.confirm) {
  117. that.init();
  118. }
  119. }
  120. });
  121. console.log(e);
  122. }
  123. });
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss">
  129. .center {
  130. min-height: 100%;
  131. }
  132. .lsButtom {
  133. font-size: 30rpx;
  134. background-image: $bg-green-gradual;
  135. text-align: center;
  136. color: $font-color-white;
  137. padding: 30rpx 0;
  138. border-radius: 99rpx;
  139. margin: 50rpx 30rpx 0rpx 30rpx;
  140. line-height: 1;
  141. }
  142. .rateBox {
  143. padding: $page-row-spacing;
  144. background-color: #ffffff;
  145. .rateTitle {
  146. font-size: 26rpx;
  147. font-weight: 500;
  148. color: $font-color-dark;
  149. }
  150. .rate {
  151. margin-top: 10rpx;
  152. font-size: 26rpx;
  153. font-weight: 500;
  154. color: $font-color-light;
  155. }
  156. }
  157. .rateConetnt {
  158. margin-top: 10rpx;
  159. background-color: #ffffff;
  160. line-height: 1;
  161. padding-bottom: 60rpx;
  162. .titleBox {
  163. align-items: stretch;
  164. justify-content: flex-start;
  165. padding: $page-row-spacing;
  166. border-bottom: 1px solid $border-color-light;
  167. .leftTip {
  168. width: 7rpx;
  169. border-radius: 99rpx;
  170. background-color: $base-color;
  171. }
  172. .title {
  173. margin-left: 20rpx;
  174. font-size: 30rpx;
  175. font-weight: 500;
  176. color: $font-color-dark;
  177. }
  178. }
  179. .content {
  180. .moneyText {
  181. font-size: 24rpx;
  182. font-weight: 500;
  183. color: $font-color-dark;
  184. padding: $page-row-spacing;
  185. }
  186. .Type {
  187. padding: 0 $page-row-spacing;
  188. .moneylogo {
  189. width: 50rpx;
  190. height: 50rpx;
  191. border-radius: 99rpx;
  192. }
  193. .moneyName {
  194. width: 180rpx;
  195. font-size: 30rpx;
  196. font-weight: 500;
  197. color: $font-color-dark;
  198. margin: 0 20rpx;
  199. }
  200. .input {
  201. flex-grow: 1;
  202. height: 45rpx;
  203. line-height: 45rpx;
  204. margin-left: 40rpx;
  205. color: $font-color-light;
  206. border-bottom: 1px solid $border-color-light;
  207. }
  208. .line {
  209. width: 2rpx;
  210. background-color: $font-color-dark;
  211. margin: 0 10rpx;
  212. height: 30rpx;
  213. }
  214. }
  215. .contentImg {
  216. width: 70rpx;
  217. height: 70rpx;
  218. margin: 40rpx auto 0;
  219. .img {
  220. width: 100%;
  221. height: 100%;
  222. }
  223. }
  224. }
  225. }
  226. </style>