convert.vue 6.4 KB

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