convert.vue 5.9 KB

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