jhzh
2024-09-23 e678ec74066a2c5b5b3b404d3344bffbd3cf59bd
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
<template>
    <div class="addPledge">
        <assets-head :title="$t('新增质押')"></assets-head>
        <div class="contentBox">
            <div class="imgBox"><img src="../../assets/image/addpledgeBg.png" alt="" /></div>
            <div class="px-32">
                <div class="content box-shad tabBackground">
                    <div class="mb-38">
                        <div class="font-32 textColor">{{ $t('质押') }}</div>
                        <div class="flex mt-20 h-96 items-center inputBox inputBackground1 textColor relative">
                            <input class="h-full pl-22 inputBackground1" type="text" v-model="pledgeAmount"
                                :placeholder="$t('请输入质押数量')" @input="changeMount" />
                            <div class="right w-252 h-62 flex items-center pl-26 box-border">
                                <img :src="`${HOST_URL}/symbol/${pledgeCurrency.toLowerCase()}.png`" class="w-48 h-48"
                                    alt="" />
                                <span class="ml-14 mr-30 w-90">{{ pledgeCurrency.toUpperCase() }}</span>
                            </div>
                        </div>
                        <div class="flex items-center font-24 mt-16 text-grey">
                            {{ $t('可用余额') }}:<span class="mr-14">{{ volume ||
                                '--' }}&nbsp;{{ pledgeCurrency.toUpperCase() }}</span>
                            <img click="$router.push('/exchange/exchangePage')" src="../../assets/image/exchangeIcon.png"
                                class="w-28 h-28" alt="" />
                        </div>
                        <div class="flex justify-between font-32 mt-48">
                            <div class="text-grey">{{ $t('质押后质押率') }}</div>
                            <div class="textColor">{{ pledgeRate !== '' ? (pledgeRate * 10000 / 100).toFixed(2) : '--' }}%
                            </div>
                        </div>
                        <div class="h-96 lh-96 btnMain rounded-lg text-center text-black font-34 mt-96"
                            @click="getReplenishOrder">{{ $t('确认质押') }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
 
<script>
import assetsHead from "@/components/assets-head";
import Axios from "@/API/pledgeLoan.js";
import { _getAllWallet } from "@/API/fund.api";
import { HOST_URL } from '@/config'
import { debounce } from '@/utils/utis'
export default {
    props: {
 
    },
    components: {
        assetsHead
    },
    data() {
        return {
            HOST_URL,
            walletList: [],
            id: '',
            pledgeAmount: '',
            pledgeRate: '',//质押率
            pledgeCurrency: '', //质押币种
            volume: '', //可用余额
        }
    },
    mounted() {
        this.id = this.$route.query.id
        this.pledgeCurrency = this.$route.query.pledgeCurrency
        this.getList()
    },
    methods: {
        changeMount() {
            if (this.pledgeAmount >= this.volume) {
                this.pledgeAmount = this.volume
            }
 
            this.debounceFn()
 
        },
        debounceFn: debounce(function () {
            this.getLoanParam()
        }, 500),
        getLoanParam() {
            if (this.pledgeAmount == '') {
                this.$toast(this.$t('请输入质押数量'))
                return false
            }
            Axios.getLoanParam({
                loanOrderId: this.id,
                pledgeAmount: this.pledgeAmount
            }).then(res => {
                this.pledgeRate = res.data.pledgeRate
            }).catch(error => {
                if (error.code === 'ECONNABORTED') { this.$toast(this.$t('网络超时!')); }
                else if (error.msg !== undefined) { this.$toast(this.$t(error.msg)); }
            })
        },
        getList() {
            _getAllWallet().then((res) => {
                this.walletList = res.extends;
                let initObj = this.walletList.find(item => {
                    return item.symbol.toLowerCase() == this.pledgeCurrency
                })
                this.volume = initObj.usable
            });
        },
        getReplenishOrder() {
            if (this.pledgeAmount == '') {
                this.$toast(this.$t('请输入质押数量'))
                return false
            }
            Axios.replenishOrder({
                loanOrderId: this.id,
                pledgeAmount: this.pledgeAmount
            }).then(res => {
                this.$toast(this.$t('质押成功'));
                this.$router.push('/pledgeLoanOrder')
            }).catch(error => {
                if (error.code === 'ECONNABORTED') { this.$toast(this.$t('网络超时!')); }
                else if (error.msg !== undefined) { this.$toast(this.$t(error.msg)); }
            })
        }
    }
}
</script>
 
<style lang="scss" scoped>
.addPledge {
    width: 100%;
    box-sizing: border-box;
}
 
.contentBox {
    position: relative;
 
    .imgBox {
        width: 100%;
        height: 300px;
 
        img {
            width: 100%;
            height: 100%;
        }
    }
 
    .content {
        border-radius: 8px;
        padding: 36px 30px 36px 34px;
        position: relative;
        margin-top: -92px;
 
        .inputBox {
            input {
                flex: 1;
                border: none;
            }
 
            .right {
                border-left: 1px solid #B8BCC5;
            }
        }
 
    }
}
 
.slectBox {
    position: absolute;
    left: 0;
    top: 114px;
    width: 100%;
 
    @include themify() {
        background: themed("main_background");
    }
 
    border-radius: 4px;
    padding: 0px 20px 76px 20px;
    box-sizing: border-box;
 
    @include themify() {
        border: 1px solid themed("line_color");
    }
 
    z-index: 2;
 
    &.slectBoxMax {
        max-height: 574px;
        overflow-y: auto;
    }
}
</style>