convert.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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,shan } 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. buying: false,
  46. };
  47. },
  48. computed: {
  49. // 转换金额
  50. moneyReta() {
  51. // 保存当前选中的对象
  52. const obj = this.moneyType[this.index];
  53. return (this.pushMoney * +obj.usdt_price) / +this.add.usdt_price;
  54. },
  55. // 实时汇率
  56. exchange() {
  57. try {
  58. const data = this.moneyType[this.index];
  59. return 1 + data.name + '≈' + data.usdt_price / this.add.usdt_price + this.add.name;
  60. } catch (e) {
  61. console.log(e);
  62. return '加载中...';
  63. }
  64. },
  65. },
  66. //页面加载即刻发生
  67. onLoad() {
  68. this.init();
  69. },
  70. methods: {
  71. // 初始化页面
  72. init() {
  73. this.wallet();
  74. },
  75. // 弹出层选择事件
  76. changeIndex(e){
  77. console.log(e);
  78. this.index = e;
  79. },
  80. // 加载币种分类
  81. wallet() {
  82. let that = this;
  83. console.log('请求兑换');
  84. uni.showLoading({
  85. title: '载入数据中...',
  86. mask: true
  87. });
  88. wallet()
  89. .then(e => {
  90. uni.hideLoading();
  91. that.lodingType = true;
  92. const moneyType = Object.keys(e.data.back);
  93. moneyType.forEach(es => {
  94. const data = e.data.back[es];
  95. data.text = data.name;
  96. if (+data.do_exchange == 1) {
  97. that.moneyType.push(data);
  98. }
  99. if (+data.exchange == 1) {
  100. that.add = data;
  101. console.log(e.data.back[es], '555');
  102. }
  103. });
  104. console.log(that.moneyType);
  105. console.log(that.add, '兑入');
  106. })
  107. .catch(e => {
  108. uni.hideLoading();
  109. if (e.status != 410000) {
  110. that.lodingType = true;
  111. uni.showModal({
  112. title: '错误',
  113. content: '加载失败请刷新页面',
  114. cancelText: '关闭',
  115. confirmText: '刷新',
  116. success: res => {
  117. if (res.confirm) {
  118. that.init();
  119. }
  120. }
  121. });
  122. console.log(e);
  123. }
  124. });
  125. },
  126. //确认兑换
  127. buy(){
  128. if (this.buying){
  129. }else {
  130. this.buying = true
  131. console.log(this.moneyType[this.index].name)
  132. shan({
  133. origin_money_type: this.moneyType[this.index].name,
  134. money_type: this.add.name,
  135. num: this.pushMoney,
  136. }).then(({data}) => {
  137. console.log(data)
  138. this.buying = false
  139. this.$api.msg("闪兑成功")
  140. }).catch(e =>{
  141. this.buying = false
  142. console.log(e)
  143. })
  144. }
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss">
  150. .center {
  151. min-height: 100%;
  152. }
  153. .lsButtom {
  154. font-size: 30rpx;
  155. background-image: $bg-green-gradual;
  156. text-align: center;
  157. color: $font-color-white;
  158. padding: 30rpx 0;
  159. border-radius: 99rpx;
  160. margin: 50rpx 30rpx 0rpx 30rpx;
  161. line-height: 1;
  162. }
  163. .rateBox {
  164. padding: $page-row-spacing;
  165. background-color: #ffffff;
  166. .rateTitle {
  167. font-size: 26rpx;
  168. font-weight: 500;
  169. color: $font-color-dark;
  170. }
  171. .rate {
  172. margin-top: 10rpx;
  173. font-size: 26rpx;
  174. font-weight: 500;
  175. color: $font-color-light;
  176. }
  177. }
  178. .rateConetnt {
  179. margin-top: 10rpx;
  180. background-color: #ffffff;
  181. line-height: 1;
  182. padding-bottom: 60rpx;
  183. .titleBox {
  184. align-items: stretch;
  185. justify-content: flex-start;
  186. padding: $page-row-spacing;
  187. border-bottom: 1px solid $border-color-light;
  188. .leftTip {
  189. width: 7rpx;
  190. border-radius: 99rpx;
  191. background-color: $base-color;
  192. }
  193. .title {
  194. margin-left: 20rpx;
  195. font-size: 30rpx;
  196. font-weight: 500;
  197. color: $font-color-dark;
  198. }
  199. }
  200. .content {
  201. .moneyText {
  202. font-size: 24rpx;
  203. font-weight: 500;
  204. color: $font-color-dark;
  205. padding: $page-row-spacing;
  206. }
  207. .Type {
  208. padding: 0 $page-row-spacing;
  209. .moneylogo {
  210. width: 50rpx;
  211. height: 50rpx;
  212. border-radius: 99rpx;
  213. }
  214. .moneyName {
  215. width: 180rpx;
  216. font-size: 30rpx;
  217. font-weight: 500;
  218. color: $font-color-dark;
  219. margin: 0 20rpx;
  220. }
  221. .input {
  222. flex-grow: 1;
  223. height: 45rpx;
  224. line-height: 45rpx;
  225. margin-left: 40rpx;
  226. color: $font-color-light;
  227. border-bottom: 1px solid $border-color-light;
  228. }
  229. .line {
  230. width: 2rpx;
  231. background-color: $font-color-dark;
  232. margin: 0 10rpx;
  233. height: 30rpx;
  234. }
  235. }
  236. .contentImg {
  237. width: 70rpx;
  238. height: 70rpx;
  239. margin: 40rpx auto 0;
  240. .img {
  241. width: 100%;
  242. height: 100%;
  243. }
  244. }
  245. }
  246. }
  247. </style>