huangbin 4 år sedan
förälder
incheckning
50c5e6f12c

+ 34 - 0
src/hooks/margin.ts

@@ -0,0 +1,34 @@
+import { TradeMode } from "@/common/constants/enumCommon"
+import { getMarketByTradeMode } from "@/services/bus/market"
+import { ref } from "vue"
+import { queryTjmdTodayAccountMargin } from "../services/go/Tjmd"
+import { TjmdTodayAccountMarginReq } from "../services/go/Tjmd/interface"
+
+// 注意:这个 保证金和 仓单贸易 里的保证金不一样
+// 目前是掉期市场
+
+// 查询 今日保证金
+const allTodayMargin = ref<TjmdTodayAccountMarginReq[]>([])
+export const useTodayMargin = () => {
+    if (allTodayMargin.value.length === 0) {
+        queryTjmdTodayAccountMargin({}).then(res => {
+            allTodayMargin.value = res
+        })
+    }
+    // 通过 市场 ID 查找 保证金信息
+    function findTodayMarginByMarketId(marketid: number) {
+        return allTodayMargin.value.find(e => e.marketid === marketid)
+    }
+
+    // 获取 结算保证金值
+    function getReckonMarginValueByTradeMode(trademode: TradeMode) {
+        let result = null
+        const marketInfo = getMarketByTradeMode(trademode)
+        if (marketInfo) {
+            const temp = findTodayMarginByMarketId(marketInfo.marketid)?.infoc?.ReckonMarginValue
+            result = temp ? temp : null
+        }
+        return result
+    }
+    return { findTodayMarginByMarketId, getReckonMarginValueByTradeMode }
+}

+ 1 - 1
src/services/go/Tjmd/interface.ts

@@ -40,7 +40,7 @@ export interface TjmdTodayAccountMarginReq {
     accountid: number; // 账号ID
     goodsid: number; // 商品ID
     marketid: number; // 市场ID
-    infoc: GoodsMarginCfgStruct[]
+    infoc: GoodsMarginCfgStruct
 }
 
 export interface QueryTjmdTradeOrderDetailReq {

+ 6 - 4
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/components/delisting/index.vue

@@ -173,6 +173,7 @@ import { defineComponent, PropType, ref } from 'vue';
 import { useUserType } from '../setup';
 import { FormParam } from './interface';
 import { handleForm, useBlocksPrice, useBlocksNumber } from './setup';
+import { useTodayMargin } from '@/hooks/margin';
 
 export default defineComponent({
     emits: ['cancel', 'update'],
@@ -193,6 +194,8 @@ export default defineComponent({
         },
     },
     setup(props, context) {
+        // 获取保证金比例
+        const { getReckonMarginValueByTradeMode } = useTodayMargin();
         // 控制弹窗
         const { visible, cancel } = _closeModal(context);
         // 表单
@@ -219,11 +222,10 @@ export default defineComponent({
         };
         // 保证金
         const getMargin = () => {
-            const { buymarginvalue, sellmarginvalue } = useTradeRule();
-            const marginvalue = isBuy() ? buymarginvalue : sellmarginvalue;
+            const marginvalue = getReckonMarginValueByTradeMode(TradeMode.DiaoQi);
             let result = 0;
-            if (formState.num) {
-                result = (getMoney() + props.selectedRow.marketmaxsub) * formState.num * marginvalue;
+            if (formState.num && marginvalue) {
+                result = (getMoney() + props.selectedRow.marketmaxsub) * formState.num * (marginvalue / 100);
             }
             return result ? result.toFixed(2) : '--';
         };