Przeglądaj źródła

修改资金信息

huangbin 4 lat temu
rodzic
commit
24d36648c1

+ 17 - 2
src/common/components/capitalInfo/index.vue

@@ -37,7 +37,7 @@
         <div class="firstLine">
           <div>可用</div>
         </div>
-        <div class="numBar blue">{{showValue(data.canUse)}}</div>
+        <div class="numBar blue">{{showValue(canUseMoney(getSelectedAccount()))}}</div>
       </div>
     </div>
   </div>
@@ -49,10 +49,13 @@ import { getAllTaAccount, getCanUseMoney, getFreeze, getSelectedAccount, setSele
 import { AccountListItem } from '@/services/dataCenter/interafce/account';
 import Bus from '@/utils/eventBus/index';
 import { getTaAccount } from '@/services/go/TaAccount';
+import { useHazardRates } from '@/views/order/funding_information/components/funding_information_funding_summary/setup'
+import { initData } from '@/common/methods';
 
 export default defineComponent({
     name: 'capital-info',
     setup(props, context) {
+        // 当前选中的资金账号
         const selectedAccount = getSelectedAccount();
         const selectedAccountId = ref<number>(selectedAccount.accountid);
         const data = reactive(getMoney(selectedAccount));
@@ -60,9 +63,18 @@ export default defineComponent({
         function showAction() {
             show.value = !show.value;
         }
-        function showValue(value: number) {
+
+        // 脱敏处理
+        function showValue(value: number | string) {
             return show.value ? value : '******';
         }
+        const loading = ref<boolean>(false)
+        const {  canUseMoney, getHoldsList } = useHazardRates();
+        initData(() => {
+            // 获取头寸
+            getHoldsList(loading)
+        })
+
         function getMoney(value: AccountListItem) {
             const { currentbalance } = value;
             return { currentbalance, freeze: getFreeze(value, true), canUse: getCanUseMoney(value) };
@@ -86,6 +98,9 @@ export default defineComponent({
             show,
             showValue,
             showAction,
+            loading,
+            canUseMoney,
+            getSelectedAccount,
         };
     },
 });

+ 1 - 1
src/services/bus/account.ts

@@ -115,7 +115,7 @@ export function getCanUserMoney() {
 
 // 获取选中的资金账号信息
 export function getSelectedAccount(): AccountListItem {
-    return APP.get('selectedAccount')
+    return APP.getRef('selectedAccount').value
 }
 
 // 设置当前中的资金账号

+ 3 - 6
src/views/order/funding_information/components/funding_information_funding_summary/index.vue

@@ -81,8 +81,7 @@ export default defineComponent({
     setup() {
         // 表格列表数据
         const { loading, tableList, queryTable } = queryTableList<Taaccount>();
-        // 持仓汇总
-        const holdsList = ref<QueryTradePositionRsp[]>([]);
+        const { handleProfitloss, hazardRates, netWorth, canUseMoney, getHoldsList } = useHazardRates();
         // 获取列表数据
         const queryTableAction = () => {
             const param: GetTaAccountsReq = {
@@ -90,11 +89,9 @@ export default defineComponent({
             };
             queryTable(getTaAccounts, param);
             // 获取头寸
-            queryTradePosition().then((res) => {
-                holdsList.value = res;
-            });
+            getHoldsList(loading)
         };
-        const { handleProfitloss, hazardRates, netWorth, canUseMoney } = useHazardRates(holdsList);
+
         // 资金变化,重新加载数据
         Bus.$on('moneyChangedNtf_UI', () => {
             queryTableAction();

+ 20 - 8
src/views/order/funding_information/components/funding_information_funding_summary/setup.ts

@@ -1,10 +1,13 @@
 import { isOemByEnum, OemType } from '@/common/config/projectName';
+import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
 import { hasSystemParam } from '@/hooks/system';
 import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
 import { getMarketTradePropertyByGoodsId } from '@/services/bus/market';
+import { AccountListItem } from '@/services/dataCenter/interafce/account';
+import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { Taaccount } from '@/services/go/TaAccount/interface';
-import { Ref } from 'vue';
+import { ref, Ref } from 'vue';
 
 export const tableColumns = () => {
     let result = [
@@ -130,15 +133,24 @@ export const tableColumns = () => {
 }
 
 
-export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
+export const useHazardRates = () => {
+    // 持仓汇总
+    const holdsList = ref<QueryTradePositionRsp[]>([]);
+    function getHoldsList(loading: Ref<boolean>) {
+        // 获取头寸
+        queryResultLoadingAndInfo(queryTradePosition, loading).then(res => {
+            holdsList.value = res;
+        })
+    }
+
     // 获取报价小数位
     function getDecimalplace() {
-        return positions.value.length > 0 ? positions.value[0].decimalplace : 2
+        return holdsList.value.length > 0 ? holdsList.value[0].decimalplace : 2
     }
 
     // 获取当前资金账号对应的头寸
     function getTaaccountPosition(accountid: number) {
-        return positions.value.filter(e => e.accountid === accountid)
+        return holdsList.value.filter(e => e.accountid === accountid)
     }
     // 汇总资金账号 的 浮动盈亏
     function handleProfitloss({ accountid }: Taaccount, isDecimalPace = true) {
@@ -208,12 +220,12 @@ export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
         result = result ? result * 100 : 0
         return result.toFixed(decimalplace) + '%'
     }
-
-    function canUseMoney(taaccount: Taaccount) {
+    // 可用资金
+    function canUseMoney(taaccount: Taaccount | AccountListItem) {
         const { currentbalance, usedmargin, freezemargin, freezecharge, otherfreezemargin, outamountfreeze } = taaccount
 
         // 浮动盈亏
-        const profitloss = handleProfitloss(taaccount, false) as number
+        const profitloss = handleProfitloss(taaccount as Taaccount, false) as number
         // 占用+冻结+其它冻结+手续费冻结+出金冻结
         const freeze = usedmargin + freezemargin + freezecharge + otherfreezemargin + outamountfreeze
         let result = 0
@@ -235,6 +247,6 @@ export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
         return result.toFixed(decimalplace)
     }
 
-    return { handleProfitloss, hazardRates, netWorth, canUseMoney }
+    return { handleProfitloss, hazardRates, netWorth, canUseMoney, getHoldsList }
 }