li.shaoyi 3 years ago
parent
commit
f2b88c7a28

+ 1 - 0
src/common/components/thirdMenu/index.vue

@@ -60,6 +60,7 @@ export default defineComponent({
     padding-top: 2px;
     background-color: @m-black5;
     z-index: 2;
+    margin-top: auto;
     .ant-tabs {
         line-height: 26px;
         .flex;

+ 76 - 43
src/views/order/funding_information/components/funding_information_funding_summary/setup.ts

@@ -3,18 +3,19 @@ import { TradeMode } from '@/common/constants/enumCommon';
 import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
 import { queryTableList } from '@/common/setup/table';
 import { hasSystemParam } from '@/hooks/system';
-import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
+import { useHolderprice } from '@/services/bus/holdPosition';
 import { getMarketIdsByTradeMode, getMarketTradePropertyByGoodsId } from '@/services/bus/market';
 import { getUserAccountType, getUsrId } from '@/services/bus/user';
 import { AccountListItem } from '@/services/dataCenter/interafce/account';
 import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { queryTradeHolderDetail } from "@/services/go/order";
-import { QueryTradeHolderDetailReq } from "@/services/go/order/interface";
+import { QueryTradeHolderDetailRsp } from "@/services/go/order/interface";
 import { Taaccount } from '@/services/go/TaAccount/interface';
 import { queryQuoteGoodsList } from '@/services/go/Tjmd';
 import { QueryQuoteGoodsListReq, QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
-import { findGoodsCode } from '@/views/order/swap_the_order/components/swap_commodity_contract_summary/setup';
+import { findGoodsCode, useDetail } from '@/views/order/swap_the_order/components/swap_commodity_contract_summary/setup';
+import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
 import { ref, Ref } from 'vue';
 
 export const tableColumns = () => {
@@ -140,40 +141,38 @@ export const tableColumns = () => {
     return result
 }
 
-// export function useTradePosition() {
-//     const positionList = ref<QueryTradePositionRsp[]>([]); // 持仓汇总
-//     const positionDetailList = ref<QueryTradeHolderDetailReq[]>([]); // 持仓明细
+/**
+ * 资金账户数据计算------------------------待优化
+ */
+export function useHazardRates() {
+    const { getDetailProfitloss } = useDetail();
+    const positionList = ref<QueryTradePositionRsp[]>([]); // 所有持仓汇总
+    const positionDetailList = ref<QueryTradeHolderDetailRsp[]>([]); // 所有持仓明细
+    const swapList = ref<QueryQuoteGoodsListRsp[]>([]); // 交割商品
 
-//     const getPositionList = (loading: Ref<boolean>) => {
-//         // 获取头寸
-//         queryResultLoadingAndInfo(queryTradePosition, loading).then((res) => {
-//             positionList.value = res;
-//         })
-
-//         const param: QueryTradeHolderDetailReq = {
-//             userid: getUsrId(),
-//             accids: accountid.toString(),
-//             trademodes: trademode.toString(),
-//             marketids: marketid.toString(),
-//         }
-//         queryResultLoadingAndInfo(queryTradeHolderDetail, loading, param).then(res => {
-//             positionDetailList.value = res
-//         })
-//     }
-// }
+    const getHoldsList = async (loading: Ref<boolean>, tradeMode?: string) => {
+        // 获取头寸
+        await queryResultLoadingAndInfo(queryTradePosition, loading, tradeMode).then((res) => {
+            const goodsSet = new Set<string>();
+            positionList.value = res;
 
+            res.forEach((el) => {
+                // 商品掉期取参考行情最新价,挂牌点选取自己行情的最新价
+                const goodscode = findGoodsCode(el.goodsid, el.goodscode, swapList.value);
+                if (goodscode) {
+                    goodsSet.add(goodscode);
+                }
+            });
 
-export const useHazardRates = () => {
-    // 持仓汇总
-    const holdsList = ref<QueryTradePositionRsp[]>([]);
-    function getHoldsList(loading: Ref<boolean>) {
-        // 获取头寸
-        queryResultLoadingAndInfo(queryTradePosition, loading).then(res => {
-            holdsList.value = res;
+            //  行情订阅
+            const { subscribeAction } = handleSubcriteQuote();
+            subscribeAction([...goodsSet]);
+        })
+        await queryResultLoadingAndInfo(queryTradeHolderDetail, loading, { userid: getUsrId() }).then(res => {
+            positionDetailList.value = res
         })
     }
-    // 交割商品
-    const swapList = ref<QueryQuoteGoodsListRsp[]>([]);
+
     function getSwapList() {
         const { queryTable } = queryTableList<QueryQuoteGoodsListRsp>();
         // 组装 参数
@@ -186,31 +185,50 @@ export const useHazardRates = () => {
         }
         queryTable(queryQuoteGoodsList, param).then(res => swapList.value = res)
     }
+
     // 获取报价小数位
     function getDecimalplace() {
-        return holdsList.value.length > 0 ? holdsList.value[0].decimalplace : 2
+        return positionList.value.length > 0 ? positionList.value[0].decimalplace : 2
     }
 
     // 获取当前资金账号对应的头寸
     function getTaaccountPosition(accountid: number) {
-        return holdsList.value.filter(e => e.accountid === accountid)
+        return positionList.value.filter(e => e.accountid === accountid)
+    }
+
+    // 获取持仓明细
+    function getTradeHolderDetail(record: QueryTradePositionRsp) {
+        const { accountid, trademode, marketid, goodsid, buyorsell } = record;
+        return positionDetailList.value.filter((e) => e.accountid === accountid && e.trademode === trademode && e.marketid === marketid && e.goodsid === goodsid && e.buyorsell === buyorsell);
+    }
+
+    // 持仓盈亏
+    // 浮动盈亏	持仓单:
+    // 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率)
+    // 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额)
+    function useProfitloss(record: QueryTradePositionRsp) {
+        const detailList = getTradeHolderDetail(record);
+        return detailList.reduce((res, item) => {
+            const goodscode = findGoodsCode(item.goodsid, item.goodscode, swapList.value);
+            res += Number(getDetailProfitloss(item, goodscode));
+            return res;
+        }, 0)
     }
+
     // 汇总资金账号 的 浮动盈亏
     function handleProfitloss({ accountid }: Taaccount, isDecimalPace = true) {
         const decimalplace = getDecimalplace()
         const result = getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
-            const tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid)
-            let temp = 0
+            const tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid);
+            // 资金 只算 收益权
             if (tradeproperty === 1) {
-                // 资金 只算 收益权
-                const goodscode = findGoodsCode(current.goodsid, current.goodscode, swapList.value)
-                const profitloos = useProfitloss(current, goodscode)
-                temp = profitloos === '--' ? 0 : Number(profitloos)
+                acc += useProfitloss(current);
             }
-            return acc + temp
+            return acc
         }, 0)
         return isDecimalPace ? result.toFixed(decimalplace) : result
     }
+
     // 计算 市值
     function handleHoldPrice(accountid: number) {
         return getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
@@ -219,6 +237,7 @@ export const useHazardRates = () => {
             return acc + temp
         }, 0)
     }
+
     // 风险净值
     function handleRiskValue(taaccount: Taaccount) {
         const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
@@ -232,6 +251,7 @@ export const useHazardRates = () => {
         // 1. 风险净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
         return currentbalance + price + profitloss - otherfreezemargin - outamountfreeze
     }
+
     // 净值
     // 根据系统参数“307 账户净值是否减冻结资金 - 0:不减 1:减“
     //0.净值=期末余额+市值+浮动盈亏(收益权)
@@ -247,6 +267,7 @@ export const useHazardRates = () => {
         const decimalplace = getDecimalplace()
         return (currentbalance + profitloss + price - free).toFixed(decimalplace)
     }
+
     // 风险率
     function hazardRates(taaccount: Taaccount) {
         const { usedmargin, mortgagecredit } = taaccount
@@ -264,6 +285,7 @@ export const useHazardRates = () => {
         result = result ? result * 100 : 0
         return result.toFixed(decimalplace) + '%'
     }
+
     // 可用资金
     function canUseMoney(taaccount: Taaccount | AccountListItem) {
         const { currentbalance, usedmargin, freezemargin, freezecharge, otherfreezemargin, outamountfreeze } = taaccount
@@ -291,6 +313,17 @@ export const useHazardRates = () => {
         return result.toFixed(decimalplace)
     }
 
-    return { handleProfitloss, getSwapList, hazardRates, netWorth, canUseMoney, getHoldsList, handleHoldPrice }
+    return {
+        positionList,
+        swapList,
+        useProfitloss,
+        handleProfitloss,
+        getTradeHolderDetail,
+        getSwapList,
+        hazardRates,
+        netWorth,
+        canUseMoney,
+        getHoldsList,
+        handleHoldPrice
+    }
 }
-

+ 10 - 35
src/views/order/swap_the_order/components/swap_commodity_contract_summary/index.vue

@@ -2,10 +2,10 @@
   <!-- 商品订单 - 合约汇总 -->
   <mtp-table-scroll>
     <template #default="{ scroll }">
-      <a-table :columns="getTableColums()" class="srcollYTableExpendBgColor srcollYTable" :scroll="scroll" :pagination="false" :loading="loading" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :expandIcon="expandIcon" :expandIconAsCell="false" rowKey="key" :data-source="tableList">
+      <a-table :columns="getTableColums()" class="srcollYTableExpendBgColor srcollYTable" :scroll="scroll" :pagination="false" :loading="loading" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :expandIcon="expandIcon" :expandIconAsCell="false" rowKey="key" :data-source="positionList">
         <!-- 额外的展开行 -->
         <template #expandedRowRender="{ record }">
-          <a-table :columns="getDetailColums()" class="expandBottomTable" :pagination="false" :loading="detailLoading" :expandedRowKeys="expandedRowKeys" :expandIcon="expandIcon" :expandIconAsCell="false" rowKey="key" :data-source="detailTableList">
+          <a-table :columns="getDetailColums()" class="expandBottomTable" :pagination="false" :loading="detailLoading" :expandedRowKeys="expandedRowKeys" :expandIcon="expandIcon" :expandIconAsCell="false" rowKey="key" :data-source="getTradeHolderDetail(record)">
             <template #operate="sub">
               <BtnList :btnList="handleBtnList(record, btnList)" :record="sub.record" class="btn-list-sticky" @click="openComponent" />
             </template>
@@ -71,6 +71,7 @@ import { QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
 import Bus from '@/utils/eventBus/index';
 import { isInvestment } from '@/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/components/setup';
 import { ref } from 'vue';
+import { useHazardRates } from '@/views/order/funding_information/components/funding_information_funding_summary/setup'
 import { findGoodsCode, getSwapList, getTableColums, useDetail } from './setup';
 
 
@@ -83,39 +84,23 @@ export default defineComponent({
     swap_commodity_contract_summary_order_closed: defineAsyncComponent(() => import('./components/swap_commodity_contract_summary_order_closed/index.vue')), // 平仓
   },
   setup() {
+    const { positionList, swapList, getHoldsList, getSwapList, getTradeHolderDetail, useProfitloss } = useHazardRates();
     // 表格列表数据
-    const { loading, tableList, queryTable } = queryTableList<QueryTradePositionRsp>();
-    const { subscribeAction } = handleSubcriteQuote();
+    const { loading } = queryTableList<QueryTradePositionRsp>();
     // 交割商品
     handleDeliveryRelation();
-    const swapList = ref<QueryQuoteGoodsListRsp[]>([]);
+    getSwapList();
 
     // 获取列表数据
-    const queryTableAction = () => {
-      Promise.all([queryTable(queryTradePosition, TradeMode.DiaoQi.toString()), getSwapList()]).then((res) => {
-        swapList.value = res[1];
-        tableList.value = res[0];
-        const goodsSet = new Set<string>();
-        res[0].forEach((el) => {
-          // 商品掉期取参考行情最新价,挂牌点选取自己行情的最新价
-          const goodscode = findGoodsCode(el.goodsid, el.goodscode, swapList.value);
-          if (goodscode) {
-            goodsSet.add(goodscode);
-          }
-        });
-        //  行情订阅
-        subscribeAction([...goodsSet]);
-      });
-    };
+    const queryTableAction = () => getHoldsList(loading, TradeMode.DiaoQi.toString());
 
     // 明细 逻辑
-    const { getTradeHolderDetail, detailLoading, getDetailColums, detailTableList, getDetailProfitloss, getDetailMarketAmount } = useDetail();
+    const { detailLoading, getDetailColums, getDetailProfitloss, getDetailMarketAmount } = useDetail();
     // 表格通用逻辑
     const param: ComposeOrderTableParam = {
       queryFn: queryTableAction,
       tableName: 'table_pcweb_spot_trade_bottom_commodity_contract_summary',
       recordList: getRecordItemTab(),
-      clickCB: getTradeHolderDetail,
     };
 
     // 现价
@@ -143,19 +128,9 @@ export default defineComponent({
     } = handleComposeOrderTable<QueryTradePositionRsp>(param)
     function clsoeAction(value: boolean) {
       closeComponent(value)
-      if (value) {
-        if (selectedRow.value) {
-          getTradeHolderDetail(selectedRow.value!)
-
-        }
-      }
     }
     Bus.$on('spotTrade', () => {
       queryTableAction()
-      if (selectedRow.value) {
-        getTradeHolderDetail(selectedRow.value!)
-
-      }
     });
     return {
       contextMenu, openContext, closeContext, // 右键
@@ -164,7 +139,7 @@ export default defineComponent({
       componentId, closeComponent, openComponent,  // 控制异步组件
       btnList, // 表格按钮
       loading,
-      tableList,
+      positionList,
       formatTime,
       expandIcon,
       getLastprice,
@@ -177,7 +152,7 @@ export default defineComponent({
       handleNoneValue,
       detailLoading,
       getDetailColums,
-      detailTableList,
+      getTradeHolderDetail,
       findGoodsCode,
       getDetailProfitloss, getDetailMarketAmount, handleQuotePriceColor, clsoeAction
     };