Browse Source

合约杠杆切换保证金

master
luyisha 3 years ago
parent
commit
bd56b8e743
  1. 3
      layout/vDropdwon.vue
  2. 74
      pages/exchange/open-position.vue

3
layout/vDropdwon.vue

@ -64,8 +64,7 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.text=this.list[newVal].label; this.text=this.list[newVal].label;
}) })
}, }
immediate: true,
}, },
}, },
methods: { methods: {

74
pages/exchange/open-position.vue

@ -132,10 +132,11 @@
<view> <view>
<!-- :placeholder="$t('contract.d2')" <!-- :placeholder="$t('contract.d2')"
v-model="form.amount" --> v-model="form.amount" -->
<!-- 保证金 -->
<v-input <v-input
v-model="margin" v-model="margin"
:placeholder="$t('contract.d2')" :placeholder="$t('contract.d2')"
@input="sliderActive=-1" @input="marginInput"
class="h-30 p-x-sm p-y-xxs rounded-xs" class="h-30 p-x-sm p-y-xxs rounded-xs"
style="background-color: #F5F5F5;" style="background-color: #F5F5F5;"
> >
@ -159,7 +160,7 @@
:class="sliderActive==index?'color-theme-1 active':''"> :class="sliderActive==index?'color-theme-1 active':''">
{{item}}% {{item}}%
</view> --> </view> -->
<slider style="width: 100%;margin:0px;" block-size="16" class="fn-center p-y-xs fn-12" value="0" @change="sliderChangeN" step="1" /> <slider style="width: 100%;margin:0px;" block-size="16" class="fn-center p-y-xs fn-12" :value="sliderValue" @change="sliderChangeN" step="1" />
<view style="width: 100%;display: flex;justify-content: space-between;"> <view style="width: 100%;display: flex;justify-content: space-between;">
<text style="text-align: left;font-size: 12px;">0%</text> <text style="text-align: left;font-size: 12px;">0%</text>
<text style="text-align: right;font-size: 12px;">25%</text> <text style="text-align: right;font-size: 12px;">25%</text>
@ -832,11 +833,9 @@ export default {
tradeList: [], tradeList: [],
show: false, show: false,
accountInfo: {}, accountInfo: {},
// lever_rage: [],//
lever_rage: [], leverShow: '',//
leverShow: '', maxNum: 0,//
//
maxNum: 0,
form: { form: {
type: 1, type: 1,
entrust_price: "", entrust_price: "",
@ -867,7 +866,8 @@ export default {
progress: [25, 50, 75, 100], progress: [25, 50, 75, 100],
progressPing: [25, 50, 75, 100], progressPing: [25, 50, 75, 100],
sliderActive: -1, sliderActive: -1,
sliderActive1: 0, sliderValue: 0,
showSliderNum: '0%',
pingActive: 3, pingActive: 3,
contract: "0", contract: "0",
// contract:"0", // contract:"0",
@ -889,8 +889,7 @@ export default {
refreshing: false, refreshing: false,
pingAmount: '', pingAmount: '',
imgurl: '', imgurl: '',
bao: 0, bao: 0
showSliderNum: '0%'
}; };
}, },
computed: { computed: {
@ -912,8 +911,8 @@ export default {
// activeCommission() { // activeCommission() {
// return this.commissionTypes.find((item) => this.form.type == item.value); // return this.commissionTypes.find((item) => this.form.type == item.value);
// }, // },
// marginCALCU() {
margin() { console.log(this.form.amount, this.unit_amount, this.form.lever_rate, '-------');
return math.omitTo( return math.omitTo(
(this.form.amount * this.unit_amount) / this.form.lever_rate, (this.form.amount * this.unit_amount) / this.form.lever_rate,
0 0
@ -922,7 +921,16 @@ export default {
amount() { amount() {
if (this.margin == 0){ if (this.margin == 0){
this.margin=''; this.margin='';
} this.sliderValue = '0';
this.showSliderNum = '0%';
}else if(this.margin>(+this.accountInfo.usable_balance) || this.margin==this.accountInfo.usable_balance){
this.margin = (+this.accountInfo.usable_balance / this.form.lever_rate).toFixed(5);
this.sliderValue = 100;
this.showSliderNum = '100%';
}else{
this.sliderValue = Math.floor(this.margin * this.form.lever_rate * 100 / this.accountInfo.usable_balance);
this.showSliderNum = '≈'+this.sliderValue.toFixed(0)+'%';
}
if (!this.form.lever_rate || !this.margin) return 0; if (!this.form.lever_rate || !this.margin) return 0;
let p = this.margin * this.form.lever_rate; let p = this.margin * this.form.lever_rate;
p = p.toFixed(0) p = p.toFixed(0)
@ -950,8 +958,9 @@ export default {
}, },
watch: { watch: {
maxNum(n) { maxNum(n) {
this.form.amount = Math.round((this.maxNum * this.sliderActive1) / 100); // this.form.amount = Math.round((this.maxNum * this.sliderValue) / 100);
this.margin = (this.form.amount / this.form.lever_rate).toFixed(5) //
// this.margin = (this.form.amount / this.form.lever_rate).toFixed(5)
}, },
symbol() { symbol() {
this.$emit("symbols", this.symbol) this.$emit("symbols", this.symbol)
@ -1355,6 +1364,12 @@ export default {
label: item, label: item,
value: item, value: item,
})); }));
for(let item =0;item<this.lever_rage.length;item++){
if(res.data.default_lever==this.lever_rage[item].value){
// leverShow v-dropdwontext
this.leverShow = item.toString();
}
}
let e={value:res.data.default_lever, label: res.data.default_lever} let e={value:res.data.default_lever, label: res.data.default_lever}
this.openNum(e); this.openNum(e);
@ -1366,7 +1381,6 @@ export default {
// //
openNum(e) { openNum(e) {
// console.log(e, '', this.lever_rage); // console.log(e, '', this.lever_rage);
if (!this.isLogin) return;
let data = { let data = {
symbol: this.symbolLeft, //ETH symbol: this.symbolLeft, //ETH
lever_rate: this.form.lever_rate, //10 lever_rate: this.form.lever_rate, //10
@ -1383,6 +1397,7 @@ export default {
} }
// console.log('111111111111', this.leverShow, this.form.lever_rate); // console.log('111111111111', this.leverShow, this.form.lever_rate);
} }
if (!this.isLogin) return;
Contract.openNum(data, {toast: false}).then((res) => { Contract.openNum(data, {toast: false}).then((res) => {
this.maxNum = res.data; this.maxNum = res.data;
}); });
@ -1439,15 +1454,16 @@ export default {
// this.openNum() // this.openNum()
}); });
}, },
// //
sliderChangeN(e){ sliderChangeN(e){
console.log('value 发生变化:' + e.detail.value); console.log('value 发生变化:' + e.detail.value);
let num = e.detail.value; let num = e.detail.value;
this.showSliderNum = num+"%"; this.showSliderNum = num.toFixed(0)+"%";
this.form.amount = Math.round((this.maxNum * num) / 100); this.form.amount = Math.round((this.accountInfo.usable_balance * num) / 100);
// this.sliderActive = i // this.sliderActive = this.sliderValue
this.sliderActive1 = num console.log(this.form.amount, this.form.lever_rate);
this.margin = (this.form.amount / this.form.lever_rate).toFixed(5) this.sliderValue = num;
this.margin = (this.form.amount / this.form.lever_rate).toFixed(2)
}, },
// sliderChange($ev) { // sliderChange($ev) {
// this.form.amount = Math.round((this.maxNum * $ev) / 100)||''; // this.form.amount = Math.round((this.maxNum * $ev) / 100)||'';
@ -1462,6 +1478,20 @@ export default {
this.sliderActive1 = n this.sliderActive1 = n
this.margin = (this.form.amount / this.form.lever_rate).toFixed(5) this.margin = (this.form.amount / this.form.lever_rate).toFixed(5)
}, },
//
marginInput(e){
this.sliderValue = Math.floor(this.margin * this.form.lever_rate * 100 / this.accountInfo.usable_balance)
// console.log(this.sliderValue, 2);
if(this.sliderValue==0){
this.showSliderNum = '0%';
}else if(this.sliderValue>100 || this.sliderValue==100){
this.margin = (+this.accountInfo.usable_balance / this.form.lever_rate).toFixed(5);
this.sliderValue = 100;
this.showSliderNum = '100%';
}else{
this.showSliderNum = '≈'+this.sliderValue.toFixed(0)+'%';
}
},
pingChange(n, i) { pingChange(n, i) {
console.log(n) console.log(n)
this.pingAmount = Math.round((this.activeItem.avail_position * n) / 100); this.pingAmount = Math.round((this.activeItem.avail_position * n) / 100);

Loading…
Cancel
Save