conversionIntegral.vue 6.3 KB

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