From 4cbc5a9d0f04b1d9b1f44563a5f99af9fb35e470 Mon Sep 17 00:00:00 2001
From: lxf <1371462558@qq.com>
Date: Mon, 30 Jun 2025 15:59:57 +0800
Subject: [PATCH] 盈利率

---
 src/components/constract/PerpetualContract/orderCom/amountSlider.vue |  123 ++++++++++++++++++++++++++++++----------
 1 files changed, 91 insertions(+), 32 deletions(-)

diff --git a/src/components/constract/PerpetualContract/orderCom/amountSlider.vue b/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
index fdd211e..b9ab905 100644
--- a/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
+++ b/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
@@ -12,7 +12,6 @@
         v-model="amount"
         step-strictly="true"
         :min="0"
-        :max="maxAmount"
         @change="inputChange"
       />
 
@@ -30,8 +29,10 @@
     <!-- 订单 -->
     <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.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">
@@ -54,6 +55,9 @@
 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",
@@ -82,6 +86,10 @@
       type: Number,
       default: 0,
     },
+    initOpen: {
+      type: Object,
+      default: {},
+    },
   },
   data() {
     return {
@@ -95,27 +103,47 @@
         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: {
-    onSliderInput(val) {
-      // 只允许滑到指定点
-      const allowed = this.allowedSteps;
-      let closest = allowed[0];
-      let minDiff = Math.abs(val - allowed[0]);
-      for (let i = 1; i < allowed.length; i++) {
-        const diff = Math.abs(val - allowed[i]);
-        if (diff < minDiff) {
-          minDiff = diff;
-          closest = allowed[i];
-        }
-      }
-      if (this.sliderAmount !== closest) {
-        this.sliderAmount = closest;
-      }
+    //获取资产总余额
+    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) {
@@ -128,21 +156,52 @@
     //滑块事件
     sliderAmountChange(val) {
       let data;
-      if (this.maxAmount) {
-        if (val == 0) {
-          this.amount = undefined;
-        } else {
-          const rate = val / 100; //如0.25
-          data = this.maxAmount * rate;
-          // 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);
+      console.log(val, "sliderAmountChange");
+
+      // if (val) {
+      // 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)) * rate) * this.lever_rate;
+      // const fl = maxAmount * sxf;
+      console.log(maxAmount * rate);
+
+      // data = maxAmount * rate - fl;
+      data = maxAmount / this.initOpen.amount;
+      // this.maxAmount = maxAmount;
+      // if (this.lever_rate) {
+      //   data = math.format((this.maxAmount * rate), 2);
+      // } else {
+      //   data = math.format((this.maxAmount * rate) / 1, 2);
+      // }
+      this.amount = data;
+      // }
+      this.$emit("getAmount", this.amount);
+      // }
     },
     emptyValue() {
       this.sliderAmount = 0;

--
Gitblit v1.9.3