交易所前端蓝色ui, 4.5 jiem
jhzh
2024-04-08 67357c691325dc3cf743267f1ef0e1f5c93d7528
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<template>
  <div id="mining-account">
    <van-tabs v-model="active">
      <van-tab :title="$t('市价')"></van-tab>
    </van-tabs>
    <div style="position: relative" class="px-30 pb-104">
      <mining-exchange-input :title="$t('从')" :isMoney="true" v-model="form.volume" :actions="actions"
        @select="onSelect('symbol', $event)" @input="onInput" @max="onMax" :type="1" :coin="form.symbol" :tips="[]"
        :showMax="true" />
      <div v-if="show" class="font-28 textColor">{{ $t('可用数量') }}:<span class="textColor">{{ amountAvailable
      }}&nbsp;{{ form.symbol.toUpperCase() }}</span>
      </div>
      <div class="flex ex-bg justify-center my-42 items-center">
        <img src="@/assets/image/exchange/icon_3.png" alt="" class="w-25 h-25" @click="onSwitch" />
      </div>
      <mining-exchange-input :title="$t('至')" :value="form.volume ? (form.volume * form.rate).toFixed(5) : ''"
        :actions="actions" @select="onSelect('symbol_to', $event)" :disabled="true" :type="2" :coin1="form.symbol_to"
        :tips="[]" :showMax="false" />
      <div class="exchange-btn w-full flex justify-center mt-20">
        <p class="h-100 btnMain mx-auto flex justify-center items-center text-white w-768" @click="onConfirm">
          {{ $t('询价') }}
        </p>
      </div>
    </div>
  </div>
</template>
 
<script>
import MiningExchangeInput from "@/components/mining-exchange-input";
import { Grid, GridItem, Popup, Icon } from "vant";
// import { mapState } from "vuex";
import { _exchangeRage, _getAllWallet, _getBalance, _initWidthdrawl, _widthdrawl, _records } from "@/API/fund.api";
import { _getBalance as __getBalance } from '@/API/trade.api'
import { mapGetters } from "vuex";
import Axios from "@/API/recharge";
import { List, PullRefresh, Tab, Tabs } from 'vant';
import { debounce } from '@/utils/utis'
export default {
  name: "MiningAcccount",
  components: {
    [Grid.name]: Grid,
    [GridItem.name]: GridItem,
    [Popup.name]: Popup,
    [Icon.name]: Icon,
    MiningExchangeInput,
    [List.name]: List,
    [PullRefresh.name]: PullRefresh,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs
  },
  props: {
    show: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    ...mapGetters('user', ['userInfo']),
    amountAvailable() {
      let res
      let data = this.wallets.find(item => item.symbol === this.form.symbol.toLowerCase())
      if (data) {
        res = data.usable
      } else {
        res = 0
      }
      return res;
    },
    tabList() {
      return [
        { id: 1, text: this.$t('提幣') },
        { id: 2, text: this.$t('交易記錄') }
      ]
    },
    addr() {
      const account = this.userInfo.account
      return account && account.substr(0, 5) + '********' + account.substr(account.length - 5)
    }
  },
  data() {
    return {
      showPopup: false,
      activeRecord: 'exchange',
      valueTwo: 0,
      rate: 0,
      form: { // 闪兑
        symbol: 'ETH',
        symbol_to: 'USDT',
        volume: '',
        rate: 0
      },
      interval: null,
      actions: [],
      balance: 0, // 质押余额
      page: 1,
      loading: false, // 当loading为true时,转圈圈
      finished: false,  // 数据是否请求结束,结束会先显示'已经全部加载完毕'
      noData: false,// 如果没有数据,显示暂无数据
      wallets: [], // 钱包列表
      active: 0
 
    }
  },
  created() {
    _getAllWallet().then(data => {
      console.log('闪兑', data)
      data.extends.map(item => {
        console.log(item)
        this.actions.push({ symbol: item.symbol, name: item.symbol.toUpperCase(), usable: item.usable, usdt: item.usdt })
      })
      this.wallets = data.extends
      this.form.symbol = this.actions[0].name
      let toObj = this.actions.find(item => {
        return item.symbol.toLowerCase() == 'btc'
      })
      this.form.symbol_to = toObj.name
    })
  },
  methods: {
    onMax() { // 最大
      console.log(this.amountAvailable)
      if (this.amountAvailable / 1) {
        this.form.volume = this.amountAvailable
        this.onInput()
      } else {
        this.$toast(this.$t('你没有可提数量'))
      }
    },
    onInput() { // 获取最新
      this.clearInterval()
      if (this.form.volume == '') {
        this.form.get_volume = ''
      } else {
        this.debounceFn()
      }
    },
    debounceFn: debounce(function () {
      this.fetchRate(true)
    }, 300),
    fetchRate(callback) { // interval
      _exchangeRage(this.form).then(data => {
        const { get_rate } = data
        this.form.rate = get_rate
        this.clearInterval()
        if (callback && typeof callback === 'function') {
          callback()
        }
      })
    },
    onSwitch() { // 交换
      const temp = this.form.symbol
      this.form.symbol = this.form.symbol_to
      this.form.symbol_to = temp
      this.form.volume = ''
      this.clearInterval()
    },
    onSelect(type, evt) { // 选择
      if (evt.type == 0) {
        this.form['symbol'] = evt.item.name
      } else {
        this.form['symbol_to'] = evt.item.name
      }
      if (this.form.symbol !== this.form.symbol_to) {
        this.form.volume = ''
      }
      this.clearInterval()
    },
    onConfirm() { // 闪兑
      this.clearInterval()
      if (this.form.volume == '') {
        this.$toast(this.$t('请输入数量'));
      } else {
        this.fetchRate(() => {
          this.$emit("exchange", this.form);
        })
      }
    },
    clearInterval() { // 清除定时器
      clearInterval(this.interval)
      this.interval = null
    }
  },
  beforeDestroy() {
    // console.log('beforeDestroy')
    this.clearInterval()
  }
};
</script>
 
<style lang="scss" scoped>
#mining-account {
  ::v-deep .van-tabs__nav {
    @include themify() {
      background-color: themed("main_background") !important;
    }
  }
 
  ::v-deep .van-tab {
    @include themify() {
      color: themed("text_color");
    }
  }
 
  ::v-deep .van-tab--active {
    @include themify() {
      background: themed("main_background") !important;
    }
  }
}
 
 
 
.ex-bg {
  width: 70px;
  height: 70px;
 
  @include themify() {
    background: 12px solid themed("cont_background");
  }
 
  border-radius: 50%;
  margin: 30px auto;
}
 
.exchange-btn {
  margin-top: 400px;
 
  .btnMain {
    background: linear-gradient(90deg, #2C64D4 0%, #38AEEA 100%);
    border-radius: 10px;
  }
}
</style>