5.10航天ui交易所pc端,代码jiem-pc
lxf
2025-06-20 d5db05869b00fb72b4944f1fdcfa147eae854bc8
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!-- 张数选择器 -->
<template>
  <div>
    <div class="place-order-input-box">
      <div class="amount-label">
        {{ $t("message.home.zhangshu") }}
        <!-- ({{ symbol?.toUpperCase() }}) -->
      </div>
      <!-- 输入值只能为整数 step-strictly表示只能是step的倍数,step默认为1-->
      <el-input-number
        class="slider-input-amount"
        v-model="amount"
        step-strictly="true"
        :min="0"
        :max="maxAmount"
        @change="inputChange"
      />
 
      <el-slider
        class="slider-block"
        tooltip-class="tooltip-box"
        @change="sliderAmountChange"
        v-model="sliderAmount"
        :format-tooltip="(v) => `${v}%`"
        :marks="marks"
        :step="25"
      >
      </el-slider>
    </div>
    <!-- 订单 -->
    <div v-if="existToken">
      <div v-if="typeNum == 0" class="submit-info-item">
        <!-- <div>{{ $t("message.home.kekaizhangshu") }}</div>
        <div>{{ `${maxAmount} ${$t("message.home.zhang")}` }}</div> -->
        <div>{{ $t("message.jiaoyi.qianbaoyue") }}</div>
        <div>{{ walletMoney }} USDT</div>
      </div>
 
      <div v-if="typeNum == 1" class="submit-info-item">
        <div>{{ $t("message.home.kepingduo") }}</div>
        <div>{{ `${closeBuyAmount} ${$t("message.home.zhang")}` }}</div>
      </div>
      <div v-if="typeNum == 1" class="submit-info-item">
        <div>{{ $t("message.home.kepingkong") }}</div>
        <div>{{ `${closeSellAmount} ${$t("message.home.zhang")}` }}</div>
      </div>
    </div>
    <!-- 持仓区 -->
    <div v-if="typeNum == 2" class="submit-info-item">
      <div>{{ $t("message.home.kepingzhangshu") }}</div>
      <div>{{ `${maxAmount} ${$t("message.home.zhang")}` }}</div>
    </div>
  </div>
</template>
<script>
import { mapState, mapActions, mapStores } from "pinia";
import { useUserStore } from "@/store/user";
import { useCurrencyStore } from "@/store/currency";
import Axios from "@/api/currency.js";
import bus from "vue3-eventbus";
 
export default {
  emits: ["getAmount"],
  name: "amountSlider",
  props: {
    maxAmount: {
      type: Number,
      default: 1, //可开或者可平的总数
    },
    symbol: {
      type: String,
      default: "",
    },
    lever_rate: {
      type: Number,
      default: 1,
    },
    typeNum: {
      type: Number,
      default: 0,
    },
    closeSellAmount: {
      type: Number,
      default: 0,
    },
    closeBuyAmount: {
      type: Number,
      default: 0,
    },
    initOpen: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      amount: undefined, //用户输入的张数
      sliderAmount: undefined, //滑块的数量
      marks: {
        0: "0",
        25: "25%",
        50: "50%",
        75: "75%",
        100: "100%",
      },
      allowedSteps: [0, 25, 50, 75, 100],
 
      totalAsset: "0.000000", //总资产
      walletMoney: "0.000000", //钱包余额
      profitLoss: "0.000000", //未实现盈亏
      marginRate: "0.000000", //保证金比率
      maintenanceMargin: "0.000000", //维持保证金 = 钱包余额
    };
  },
  mounted() {
    if (this.existToken) {
      this.timer = setInterval(() => {
        this.getAssetTotal();
      }, 2000);
    }
  },
  unmounted() {
    if (this.timer) {
      clearInterval(this.timer);
      this.timer = null;
    }
  },
  computed: {
    ...mapState(useUserStore, ["existToken"]),
    //保证金余额
    marginBalance: function () {
      // 钱包余额 + 未实现盈亏
      return bigDecimal.add(this.walletMoney, this.profitLoss);
    },
  },
  methods: {
    //获取资产总余额
    getAssetTotal() {
      Axios.currencyPaypal().then((res) => {
        const { total, money_wallet, money_contract, money_contract_profit } =
          res.data;
        this.totalAsset = total; //总资产
        this.walletMoney = bigDecimal.round(money_wallet, 2); //钱包余额
        this.profitLoss = bigDecimal.round(money_contract_profit, 2); //永续合约总未实现盈亏
        // bus.emit("moneyContract", money_contract); //合约可用余额
        bus.emit("moneyContract", money_wallet); //合约可用余额
      });
    },
    //输入框事件
    inputChange(val) {
      this.$emit("getAmount", val);
    },
    // 清除输入框
    cleanAmount() {
      this.amount = undefined;
    },
    //滑块事件
    sliderAmountChange(val) {
      let data;
      if (this.maxAmount) {
        // if (val == 0) {
        //   this.amount = undefined;
        // } else {
 
        const rate = val / 100; //如0.25
        let sxf = 0;
        switch (Number(this.lever_rate)) {
          case 25:
            sxf = 0.0375;
            break;
          case 50:
            sxf = 0.075;
            break;
          case 100:
            sxf = 0.15;
            break;
          case 200:
            sxf = 0.3;
            break;
          default:
            sxf = 0;
        }
        // const fl =
        // this.walletMoney * sxf * this.initOpen.amount * this.lever_rate * rate;
        // const maxAmount =
        // this.walletMoney * this.initOpen.amount * this.lever_rate;
        const maxAmount =
          Math.floor(this.walletMoney / (1 + sxf)) * this.lever_rate;
        const fl = maxAmount * sxf;
        console.log(maxAmount * rate, fl);
 
        // data = maxAmount * rate - fl;
        data = maxAmount;
 
        // if (this.lever_rate) {
        //   data = math.format((this.maxAmount * rate), 2);
        // } else {
        //   data = math.format((this.maxAmount * rate) / 1, 2);
        // }
        this.amount = parseInt(data);
        // }
        this.$emit("getAmount", this.amount);
      }
    },
    emptyValue() {
      this.sliderAmount = 0;
    },
  },
};
</script>
<style>
@import url("@/assets/css/commonTrade/constract/order/amountSliderInput.css");
@import url("@/assets/css/commonTrade/el-slider.css");
.submit-info-item {
  color: #909090;
  height: 32px;
  line-height: 32px;
  display: flex;
  justify-content: space-between;
}
 
/* 张数输入 */
.place-order-input-box {
  position: relative;
  color: #909090;
}
/* 前缀 */
.amount-label {
  position: absolute;
  font-size: 12px;
  top: 2px;
  left: 10px;
  display: inline-block;
  height: 30px;
  line-height: 30px;
  z-index: 9;
}
 
/* d张数 */
.input-unit {
  position: absolute;
  top: 4px;
  right: 10px;
  display: inline-block;
  height: 30px;
  line-height: 30px;
  z-index: 9;
}
.place-order-input-box input {
  padding: 0px 10px;
  box-sizing: border-box;
  text-align: center;
}
 
.place-order-form-box .place-order-form-splitter {
  height: auto;
}
.place-order-inner-common {
  padding: 0px 16px 4px 13px;
}
 
.place-order-form-box .submit-btn-box-container {
  margin-top: 0px;
}
</style>