Quellcode durchsuchen

修改 资金信息

huangbin vor 4 Jahren
Ursprung
Commit
f3e8e23e72

+ 28 - 0
src/common/constants/enumsName.ts

@@ -1309,4 +1309,32 @@ export function getBarmaginApplyStatus(status: number) {
             break
     }
     return result
+}
+
+export function getTaacountStatus(status: number) {
+    let result = '--'
+    switch (status) {
+        case 1:
+            result = '正常'
+            break
+        case 2:
+            result = '受限'
+            break
+        case 3:
+            result = '冻结'
+            break
+        case 4:
+            result = '禁止建仓'
+            break
+        case 5:
+            result = '禁止交易'
+            break
+        case 6:
+            result = '待激活'
+            break
+        case 7:
+            result = '已注销'
+            break
+    }
+    return result
 }

+ 30 - 0
src/services/bus/holdPosition.ts

@@ -0,0 +1,30 @@
+import { QueryTradePositionRsp } from "../go/ermcp/order/interface";
+import { getQuoteDayInfoByCodeFindPrice } from "./goods";
+
+
+// 持仓盈亏
+// 浮动盈亏	持仓单:
+// 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率)
+// 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额)
+export const useProfitloss = (record: QueryTradePositionRsp) => {
+    // 最新价
+    const lastPrice = getQuoteDayInfoByCodeFindPrice(record.goodscode);
+    if (lastPrice !== '--') {
+        const { averageprice, decimalplace, agreeunit, curpositionqty } = record;
+        return ((+lastPrice - averageprice) * curpositionqty * agreeunit).toFixed(decimalplace);
+    } else {
+        return lastPrice;
+    }
+}
+
+// 持仓金额(市值(所有权)) = 数量 * 现价 * 合约单位
+export const useHolderprice = (record: QueryTradePositionRsp) => {
+    // 最新价
+    const lastPrice = getQuoteDayInfoByCodeFindPrice(record.goodscode);
+    if (lastPrice !== '--') {
+        const { decimalplace, agreeunit, curpositionqty } = record;
+        return (+lastPrice * curpositionqty * agreeunit).toFixed(decimalplace);
+    } else {
+        return lastPrice
+    }
+}

+ 2 - 2
src/services/go/ermcp/order/index.ts

@@ -1,6 +1,6 @@
 
 /** ================================= 通用单据相关接口 ================================**/
-import { getSelectedAccountId } from "@/services/bus/account";
+import { getAccoutIdList, getSelectedAccountId } from "@/services/bus/account";
 import { commonSearch_go } from "@/services/go";
 import {
     QueryHisTradeDetailReq,
@@ -70,7 +70,7 @@ export function queryTradeOrderDetail(req: QueryTradeOrderDetailReq): Promise<Qu
  * @param //  交易模式 - 格式:1,2,3
  */
 export function queryTradePosition(radeMode?: string): Promise<QueryTradePositionRsp[]> {
-    const accountID = getSelectedAccountId()?.toString()
+    const accountID = getAccoutIdList()
     const param = radeMode ? { accountID, radeMode } : { accountID }
     return commonSearch_go('/Order/QueryTradePosition', param).catch((err) => {
         throw new Error(`仓汇总查询(合约市场): ${err}`);

+ 10 - 15
src/views/order/commodity_contract/components/commodity_contract_bargain/index.vue

@@ -56,29 +56,24 @@
 </template>
 
 <script lang="ts">
-import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
-import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEnum } from '@/common/export/commonTable';
+import { BtnListType } from '@/common/components/btnList/interface';
+import { ApplyType } from '@/common/constants/enumCommon';
+import { getBuyOrSellName, getScfContractStatusName } from '@/common/constants/enumsName';
+import { BtnList, defineAsyncComponent, defineComponent, queryTableList } from '@/common/export/commonTable';
+import { formatTime } from '@/common/methods';
+import { handleDeliveryRelation } from '@/common/setup/deliveryRelation';
 import { getRecordItemTab } from '@/common/setup/order/orderData';
+import { expandIcon } from '@/common/setup/table/clolumn';
 import { handleComposeOrderTable } from '@/common/setup/table/compose';
 import { ComposeOrderTableParam } from '@/common/setup/table/interface';
-import { formatTime } from '@/common/methods';
-import { expandIcon } from '@/common/setup/table/clolumn';
-import { queryTradePosition } from '@/services/go/ermcp/order';
+import { getAccoutIdList } from '@/services/bus/account';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
-import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
-import { findGoodsTradeModeById, getQuoteDayInfoByCode } from '@/services/bus/goods';
-import { handleDeliveryRelation } from '@/common/setup/deliveryRelation';
-import { TradeMode } from '@/common/constants/enumCommon';
-import { BtnListType } from '@/common/components/btnList/interface';
-import { columns } from './setup';
 import { queryTjmdTransferApply } from '@/services/go/Tjmd';
 import { QueryTjmdTransferApplyReq, QueryTjmdTransferApplyRsp } from '@/services/go/Tjmd/interface';
 import Bus from '@/utils/eventBus/index';
-import { ref } from 'vue';
-import { ApplyType } from '@/common/constants/enumCommon';
-import { getBuyOrSellName, getScfContractStatusName } from '@/common/constants/enumsName';
-import { getAccoutIdList } from '@/services/bus/account';
 import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
+import { ref } from 'vue';
+import { columns } from './setup';
 
 export default defineComponent({
     name: 'commodity_contract_bargain',

+ 16 - 43
src/views/order/commodity_contract/components/commodity_contract_summary/index.vue

@@ -29,11 +29,11 @@
       </template>
       <!-- 持仓金额  -->
       <template #holderprice="{ record }">
-        <a>{{ getHolderprice(record) }}</a>
+        <a>{{ useHolderprice(record) }}</a>
       </template>
       <!-- 持仓盈亏 -->
       <template #profitloss="{ record }">
-        <a>{{ getProfitloss(record) }}</a>
+        <a>{{ useProfitloss(record) }}</a>
       </template>
     </a-table>
     <component :is="componentId"
@@ -45,20 +45,21 @@
 </template>
 
 <script lang="ts">
+import { BtnListType } from '@/common/components/btnList/interface';
+import { TradeMode } from '@/common/constants/enumCommon';
 import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
-import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEnum } from '@/common/export/commonTable';
+import { BtnList, defineAsyncComponent, defineComponent, ModalEnum, queryTableList } from '@/common/export/commonTable';
+import { formatTime } from '@/common/methods';
+import { handleDeliveryRelation } from '@/common/setup/deliveryRelation';
 import { getRecordItemTab } from '@/common/setup/order/orderData';
+import { expandIcon } from '@/common/setup/table/clolumn';
 import { handleComposeOrderTable } from '@/common/setup/table/compose';
 import { ComposeOrderTableParam } from '@/common/setup/table/interface';
-import { formatTime } from '@/common/methods';
-import { expandIcon } from '@/common/setup/table/clolumn';
+import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
+import { findGoodsTradeModeById, getQuoteDayInfoByCodeFindPrice } from '@/services/bus/goods';
+import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
 import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
-import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
-import { findGoodsTradeModeById, getQuoteDayInfoByCode } from '@/services/bus/goods';
-import { handleDeliveryRelation } from '@/common/setup/deliveryRelation';
-import { TradeMode } from '@/common/constants/enumCommon';
-import { BtnListType } from '@/common/components/btnList/interface';
 
 export default defineComponent({
     name: enumOrderComponents.commodity_contract_summary,
@@ -92,38 +93,10 @@ export default defineComponent({
         };
         // 现价
         function getLastprice({ goodscode, decimalplace }: QueryTradePositionRsp) {
-            const item = getQuoteDayInfoByCode(goodscode);
-            let result = '';
-            if (item) {
-                const { last, presettle } = item;
-                if (last && ((last as unknown) as string) !== '--') {
-                    result = last.toFixed(decimalplace); // 最新
-                } else if (presettle) {
-                    result = presettle.toFixed(decimalplace); // 昨结
-                }
-            }
-            return result;
-        }
-        // 持仓金额 = 数量 * 现价 * 合约单位
-        function getHolderprice(record: QueryTradePositionRsp) {
-            const price = getLastprice(record);
-            if (price !== '--') {
-                const { decimalplace, agreeunit, curpositionqty } = record;
-                return (+price * curpositionqty * agreeunit).toFixed(decimalplace);
-            } else {
-                return price;
-            }
-        }
-        /// 持仓盈亏 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
-        function getProfitloss(record: QueryTradePositionRsp) {
-            const price = getLastprice(record);
-            if (price !== '--') {
-                const { averageprice, decimalplace, agreeunit, curpositionqty } = record;
-                return ((+price - averageprice) * curpositionqty * agreeunit).toFixed(decimalplace);
-            } else {
-                return price;
-            }
+            const lastPrice = getQuoteDayInfoByCodeFindPrice(goodscode);
+            return lastPrice === '--' ? lastPrice : Number(lastPrice).toFixed(decimalplace);
         }
+
         function handleBtnList(record: QueryTradePositionRsp, btnList: BtnListType[]) {
             if (findGoodsTradeModeById(record.goodsid) === TradeMode.DiaoQi) {
                 return btnList.filter((e) => e.code === 'commodity_contract_summary_deal_closed');
@@ -138,8 +111,8 @@ export default defineComponent({
             formatTime,
             expandIcon,
             getLastprice,
-            getHolderprice,
-            getProfitloss,
+            useHolderprice,
+            useProfitloss,
             handleBtnList,
         };
     },

+ 38 - 5
src/views/order/funding_information/components/funding_information_funding_summary/index.vue

@@ -1,7 +1,7 @@
 <template>
   <!-- 资金汇总 -->
   <section>
-    <a-table :columns="columns"
+    <a-table :columns="tableColumns"
              class="srcollYTable expandLeftTable"
              :scroll="{ x: '100%', y: '190px' }"
              :pagination="false"
@@ -21,11 +21,26 @@
                  @click="openComponent" />
       </template>
       <template #balance="{record}">
-        <span>{{getCanUseMoney(record)}}</span>
+        <span>{{canUseMoney(record)}}</span>
       </template>
       <template #freezemargin="{record}">
         <span>{{getFreeze(record, true)}}</span>
       </template>
+      <!-- 浮动盈亏 -->
+      <template #closepl="{record}">
+        <span>{{handleProfitloss(record)}}</span>
+      </template>
+      <!-- 风险率 -->
+      <template #accountname="{record}">
+        <span>{{hazardRates(record)}}</span>
+      </template>
+      <!-- 净值 -->
+      <template #currentbalance="{record}">
+        <span>{{netWorth(record)}}</span>
+      </template>
+      <template #tradestatus="{text}">
+        <span>{{getTaacountStatus(text)}}</span>
+      </template>
     </a-table>
     <component :is="componentId"
                v-if="componentId"
@@ -43,12 +58,17 @@ import { getRecordItemTab } from '@/common/setup/order/orderData';
 import { handleComposeOrderTable } from '@/common/setup/table/compose';
 import { ComposeOrderTableParam } from '@/common/setup/table/interface';
 import { getTaAccounts, queryAmountLog } from '@/services/go/TaAccount';
-import { GetTaAccountsReq, QueryAmountLogReq } from '@/services/go/TaAccount/interface';
+import { GetTaAccountsReq, QueryAmountLogReq, Taaccount } from '@/services/go/TaAccount/interface';
 import { getSelectedAccountId, getCanUseMoney, getFreeze } from '@/services/bus/account';
 import { geLoginID_number } from '@/services/bus/login';
 import * as Long from 'long';
 import Bus from '@/utils/eventBus/index';
 import { expandIcon } from '@/common/setup/table/clolumn';
+import { tableColumns, useHazardRates } from './setup';
+import { queryTradePosition } from '@/services/go/ermcp/order';
+import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
+import { ref } from 'vue';
+import { getTaacountStatus } from '@/common/constants/enumsName';
 
 export default defineComponent({
     name: enumOrderComponents.funding_information_funding_summary,
@@ -57,14 +77,21 @@ export default defineComponent({
     },
     setup() {
         // 表格列表数据
-        const { loading, tableList, queryTable } = queryTableList<WrPerformancePlan>();
+        const { loading, tableList, queryTable } = queryTableList<Taaccount>();
+        // 持仓汇总
+        const holdsList = ref<QueryTradePositionRsp[]>([]);
         // 获取列表数据
         const queryTableAction = () => {
             const param: GetTaAccountsReq = {
                 loginID: Number(geLoginID_number()),
             };
             queryTable(getTaAccounts, param);
+            // 获取头寸
+            queryTradePosition().then((res) => {
+                holdsList.value = res;
+            });
         };
+        const { handleProfitloss, hazardRates, netWorth, canUseMoney } = useHazardRates(holdsList);
         // 资金变化,重新加载数据
         Bus.$on('moneyChangedNtf_UI', () => {
             queryTableAction();
@@ -76,12 +103,18 @@ export default defineComponent({
             recordList: getRecordItemTab(),
         };
         return {
-            ...handleComposeOrderTable<WrPerformancePlan>(param),
+            ...handleComposeOrderTable<Taaccount>(param),
             loading,
             tableList,
             getCanUseMoney,
             getFreeze,
             expandIcon,
+            handleProfitloss,
+            hazardRates,
+            tableColumns,
+            getTaacountStatus,
+            netWorth,
+            canUseMoney,
         };
     },
 });

+ 200 - 0
src/views/order/funding_information/components/funding_information_funding_summary/setup.ts

@@ -0,0 +1,200 @@
+import APP from '@/services';
+import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
+import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
+import { Taaccount } from '@/services/go/TaAccount/interface';
+import { Systemparam } from '@/services/go/useInfo/interface';
+import { Ref } from 'vue';
+
+export const tableColumns = [
+    {
+        key: '0th',
+        dataIndex: 'accountid',
+        title: '资金账号',
+        align: 'center',
+        slots: {
+            customRender: 'accountid',
+        },
+        width: 120,
+    },
+    {
+        key: '1th',
+        dataIndex: 'currentbalance',
+        title: '净值',
+        align: 'center',
+        slots: {
+            customRender: 'currentbalance',
+        },
+        width: 120,
+    },
+    {
+        key: '2th',
+        dataIndex: 'balance',
+        title: '可用资金',
+        align: 'center',
+        slots: {
+            customRender: 'balance',
+        },
+        width: 120,
+    },
+    {
+        key: '3th',
+        dataIndex: 'usedmargin',
+        title: '占用资金',
+        align: 'center',
+        slots: {
+            customRender: 'usedmargin',
+        },
+        width: 120,
+    },
+    {
+        key: '4th',
+        dataIndex: 'freezemargin',
+        title: '冻结资金',
+        align: 'center',
+        slots: {
+            customRender: 'freezemargin',
+        },
+        width: 120,
+    },
+    {
+        key: '5th',
+        dataIndex: 'closepl',
+        title: '浮动盈亏',
+        align: 'center',
+        slots: {
+            customRender: 'closepl',
+        },
+        width: 120,
+    },
+    {
+        key: '51th',
+        dataIndex: 'currentbalance',
+        title: '余额',
+        align: 'center',
+        slots: {
+            customRender: 'currentbalance',
+        },
+        width: 120,
+    },
+    {
+        key: '6th',
+        dataIndex: 'usedmargin',
+        title: '风险率',
+        align: 'center',
+        slots: {
+            customRender: 'accountname',
+        },
+        width: 120,
+    },
+    {
+        key: '7th',
+        dataIndex: 'tradestatus',
+        title: '状态',
+        align: 'center',
+        slots: {
+            customRender: 'tradestatus',
+        },
+        width: 120,
+    },
+];
+
+
+export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
+    // 获取报价小数位
+    function getDecimalplace() {
+        return positions.value.length > 0 ? positions.value[0].decimalplace : 2
+    }
+    // 获取系统参数
+    const getSystemParam = (paramcode: string, value: string) => APP.getRef('systemParams').value.find((param: Systemparam) => param.paramcode)?.paramvalue === value
+    // 获取当前资金账号对应的头寸
+    function getTaaccountPosition(accountid: number) {
+        return positions.value.filter(e => e.accountid === accountid)
+    }
+    // 汇总资金账号 的 浮动盈亏
+    function handleProfitloss({ accountid }: Taaccount, isDecimalPace = true) {
+        const decimalplace = getDecimalplace()
+        const result = getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
+            const profitloos = useProfitloss(current)
+            const temp = profitloos === '--' ? 0 : Number(profitloos)
+            return acc + temp
+        }, 0)
+        return isDecimalPace ? result.toFixed(decimalplace) : result
+    }
+    // 计算 市值
+    function handleHoldPrice(accountid: number) {
+        return getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
+            const price = useHolderprice(current)
+            const temp = price === '--' ? 0 : Number(price)
+            return acc + temp
+        }, 0)
+    }
+    // 风险净值
+    function handleRiskValue(taaccount: Taaccount) {
+        const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
+        // 浮动盈亏
+        const profitloss = handleProfitloss(taaccount, false) as number
+        // 市值
+        const price = getSystemParam('087', '1') ? handleHoldPrice(accountid) : 0
+
+        // 风险净值	根据系统参数“087 风险净值是否加上市值 - 0:不加 1:加“
+        // 0. 风险净值=期末余额+浮动盈亏(收益权)-其他冻结-出金冻结
+        // 1. 风险净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
+        return currentbalance + price + profitloss - otherfreezemargin - outamountfreeze
+    }
+    // 净值期 末余额+市值+浮动盈亏(收益权
+    function netWorth(taaccount: Taaccount) {
+        const { accountid, currentbalance } = taaccount
+        // 浮动盈亏
+        const profitloss = handleProfitloss(taaccount, false) as number
+        // 市值
+        const price = handleHoldPrice(accountid)
+        const decimalplace = getDecimalplace()
+        return (currentbalance + profitloss + price).toFixed(decimalplace)
+    }
+    // 风险率
+    function hazardRates(taaccount: Taaccount) {
+        const { usedmargin, mortgagecredit } = taaccount
+        // 风险净值
+        const riskValue = handleRiskValue(taaccount)
+        const decimalplace = getDecimalplace()
+        //   风险率	根据系统参数“132   风险率计算公式”:
+        // 1. 风险率=占用/风险净值
+        // 2. 风险率=(占用-授信金额)/(风险净值-授信金额)
+        const credit = getSystemParam('132', '1') ? 0 : mortgagecredit
+        let result = 0
+        if (riskValue && (riskValue - credit)) {
+            result = (usedmargin - credit) / (riskValue - credit)
+        }
+        result = result ? result * 100 : 0
+        return result.toFixed(decimalplace) + '%'
+    }
+
+    function canUseMoney(taaccount: Taaccount) {
+        const { currentbalance, usedmargin, freezemargin, freezecharge, otherfreezemargin, outamountfreeze } = taaccount
+
+        // 浮动盈亏
+        const profitloss = handleProfitloss(taaccount, false) as number
+        // 占用+冻结+其它冻结+手续费冻结+出金冻结
+        const freeze = usedmargin + freezemargin + freezecharge + otherfreezemargin + outamountfreeze
+        let result = 0
+        if (profitloss < 0) {
+            // 账户总浮动盈亏为负:= 期末余额+总浮动盈亏-占用-冻结-其它冻结-手续费冻结-出金冻结
+            result = currentbalance + profitloss - freeze
+        } else {
+            // *系统参数”113“(当日浮动盈利是否可用) 0:不可用 1:可用
+            const isUse = getSystemParam('113', '1')
+            if (isUse) {
+                // 账户总浮动盈亏为正 且 113 = 1 :=期末余额+总浮动盈亏-占用-冻结-其它冻结-手续费冻结-出金冻结
+                result = currentbalance + profitloss - freeze
+            } else {
+                // 账户总浮动盈亏为正 且 113 = 0 :=期末余额-占用-冻结-其它冻结-手续费冻结-出金冻结
+                result = currentbalance - freeze
+            }
+        }
+        const decimalplace = getDecimalplace()
+        return result.toFixed(decimalplace)
+    }
+
+    return { handleProfitloss, hazardRates, netWorth, canUseMoney }
+}
+