Преглед изворни кода

Merge branch 'mtp_v6' of http://47.101.159.18:3000/Muchinfo/MTP2.0_WEB into mtp_v6

huangbin пре 4 година
родитељ
комит
7f79ca82f5

+ 16 - 10
src/hooks/account/index.ts

@@ -7,7 +7,7 @@ import { getTaAccounts } from '@/services/go/TaAccount';
 import { Taaccount } from "@/services/go/TaAccount/interface";
 import { geLoginID_number } from '@/services/bus/login';
 import { Systemparam } from '@/services/go/useInfo/interface';
-import { getSelectedAccountId } from '@/services/bus/account';
+import { getSelectedAccountId, setSelectedAccount } from '@/services/bus/account';  // 为了兼容以前代码,待优化后期废除
 import { TradeAccount, TradePosition } from './interface'
 import APP from '@/services';
 
@@ -24,6 +24,7 @@ const tradeAccount = ref<TradeAccount>();
  * 资金账户
  */
 export function useTradeAccount() {
+    // 获取资金账户列表
     const getTradeAccountList = () => {
         if (!loading.value) {
             tradeAccountList.length = 0;
@@ -54,29 +55,34 @@ export function useTradeAccount() {
                     })
                 }
 
-                selectedTradeAccount();
+                tradeAccountChange(getSelectedAccountId());
                 loading.value = false;
             })
         }
     }
 
-    // 设置选中当前账户
-    const selectedTradeAccount = () => {
-        tradePositionList.length = 0;
-        tradeAccount.value = tradeAccountList.find((account) => account.accountid === getSelectedAccountId());
-
-        if (tradeAccount.value) {
-            tradePositionList.push(...tradeAccount.value.positionList);
+    // 切换资金账户
+    const tradeAccountChange = (accountId: number) => {
+        const account = tradeAccountList.find((account) => account.accountid === accountId);
+        if (account) {
+            tradePositionList.length = 0;
+            tradeAccount.value = account;
+            tradePositionList.push(...account.positionList);
+            setSelectedAccount(account); // 为了兼容以前代码,待优化后期废除
         }
     }
 
+    // 期货账户列表
+    const futuresAccountList = computed(() => tradeAccountList.filter((account) => account.taaccounttype === 1));
+
     return {
         loading,
         tradeAccountList,
         tradePositionList,
         tradeAccount,
+        futuresAccountList,
         getTradeAccountList,
-        selectedTradeAccount,
+        tradeAccountChange,
     }
 }
 

+ 4 - 11
src/layout/components/bottom.vue

@@ -5,7 +5,7 @@
       <firstMenu :list="orderList" :value="'title'" @selectMenu="selectMenu">
         <div class="right-menu-content">
           <!-- 资金信息 -->
-          <a-select class="capitalSelect" style="width: 180px" @change="accountChange" v-model:value="selectedAccountId">
+          <a-select class="capitalSelect" style="width: 180px" @change="tradeAccountChange" v-model:value="selectedAccountId">
             <a-select-option v-for="item in tradeAccountList" :value="item.accountid" :key="item.accountid">{{item.accountid}}</a-select-option>
           </a-select>
           <div class="conditionIcon icon iconfont icon-shouqi" @click="handleShowBottom"></div>
@@ -27,8 +27,7 @@ import { OperationTabMenu } from '@/services/go/commonService/interface';
 import { handleOrderData } from '@/common/setup/order/orderData';
 import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
 import { handleShowBottom, getShowBottomValue } from '@/common/config/constrolBottom';
-import { getAllTaAccount, getSelectedAccount, setSelectedAccount } from '@/services/bus/account';
-import { AccountListItem } from '@/services/dataCenter/interafce/account';
+import { getSelectedAccount } from '@/services/bus/account';
 import Bus from '@/utils/eventBus/index';
 import { isOemByEnum, OemType } from '@/common/config/projectName';
 import { initData } from '@/common/methods';
@@ -50,17 +49,11 @@ export default defineComponent({
     [enumOrderComponents.commodity_contract]: defineAsyncComponent(() => import('@/views/order/commodity_contract/index.vue')),
   },
   setup() {
-    const { tradeAccountList, getTradeAccountList, selectedTradeAccount } = useTradeAccount();
+    const { tradeAccountList, getTradeAccountList, tradeAccountChange } = useTradeAccount();
     const { orderList, componentId } = handleOrderData();
     const selectedAccount = getSelectedAccount();
     const selectedAccountId = ref<number>(selectedAccount.accountid);
 
-    function accountChange(id: number) {
-      const item = getAllTaAccount().find((e) => e.accountid === id) as AccountListItem;
-      setSelectedAccount(item);
-      selectedTradeAccount();
-    }
-
     // 资金变化,重新加载数据
     Bus.$on('moneyChangedNtf_UI', () => {
       getTradeAccountList();
@@ -88,7 +81,7 @@ export default defineComponent({
       getShowBottomValue,
       handleShowBottom,
       selectedAccountId,
-      accountChange,
+      tradeAccountChange,
       isCapitalLeft,
     };
   },

+ 8 - 4
src/views/market/futures/compoments/futures-trade/index.less

@@ -77,8 +77,8 @@
             border          : 1px solid #FF4848 !important;
             background-color: #2F1B1C !important;
 
-            span:first-child {
-                border-bottom: 1px dashed #5E1616;
+            span:not(:first-child) {
+                border-top: 1px dashed #5E1616;
             }
         }
 
@@ -87,8 +87,8 @@
             border          : 1px solid #1DDFAF !important;
             background-color: #20322A !important;
 
-            span:first-child {
-                border-bottom: 1px dashed #095936;
+            span:not(:first-child) {
+                border-top: 1px dashed #095936;
             }
         }
 
@@ -96,6 +96,10 @@
             color           : #FFA235 !important;
             border          : 1px solid #FFA235 !important;
             background-color: #3D3325 !important;
+
+            span:not(:first-child) {
+                border-top: 1px dashed #653F0D;
+            }
         }
     }
 

+ 37 - 20
src/views/market/futures/compoments/futures-trade/index.vue

@@ -5,9 +5,12 @@
       <div class="futures_trade__left">
         <div class="futures_trade__form">
           <a-form class="inlineForm" ref="formRef" :model="formData" :rules="rules">
+            <a-form-item label="现货合同" v-if="isHedging">
+              <span class="white">{{ selectedRow.spotcontractid }}</span>
+            </a-form-item>
             <a-form-item label="账号">
-              <a-select class="inlineFormSelect" placeholder="请选择" v-model:value="formData.AccountID" @change="getPositionList">
-                <a-select-option v-for="item in accountList" :value="item.accountid" :key="item.accountid">{{ item.accountname }} - {{item.accountid}}</a-select-option>
+              <a-select class="inlineFormSelect" placeholder="请选择" v-model:value="formData.AccountID" @change="tradeAccountChange">
+                <a-select-option v-for="item in futuresAccountList" :value="item.accountid" :key="item.accountid">{{ item.accountname }} - {{item.accountid}}</a-select-option>
               </a-select>
             </a-form-item>
             <a-form-item label="合约">
@@ -15,9 +18,6 @@
                 <a-select-option v-for="item in goodsList" :value="item.goodsid" :key="item.goodsid">{{ item.goodsname }}</a-select-option>
               </a-select>
             </a-form-item>
-            <a-form-item label="现货合同" v-if="isHedging">
-              <span class="white">{{ selectedRow.spotcontractid }}</span>
-            </a-form-item>
             <a-form-item label="价格类型">
               <a-select class="inlineFormSelect" placeholder="请选择" v-model:value="selectedPriceType" @change="priceTypeChange">
                 <a-select-option v-for="item in priceTypeList" :value="item.priceType" :key="item.priceType">{{ item.priceName }}</a-select-option>
@@ -52,14 +52,13 @@
             <span>{{sellPrice}}</span>
             <span>卖出</span>
           </a-button>
-          <!--如果是套保交易隐藏按钮-->
-          <a-button class="close" :loading="loading" @click="submit('close')" :disabled="positionList.length === 0" v-if="!isHedging">
+          <a-button class="close" :loading="loading" @click="submit('close')" :disabled="positionList.length === 0">
             <!--根据持仓方向显示平仓价格-->
             <span v-if="selectedPosition">{{selectedPosition.buyorsell === BuyOrSell.buy ? sellPrice : buyPrice}}</span>
             <span>平仓</span>
           </a-button>
         </div>
-        <div class="futures_trade__table tableDatas" v-show="positionList.length && !isHedging">
+        <div class="futures_trade__table tableDatas" v-show="positionList.length">
           <a-table class="dialogTable" :columns="getColumns()" :data-source="positionList" :rowKey="(record,index)=>index" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio' }"></a-table>
         </div>
       </div>
@@ -85,6 +84,7 @@ import { GoodsQuote } from '@/services/go/ermcp/goodsInfo/interface';
 import { QueryErmcpTradePositionRsp } from '@/services/go/ermcp/futures/interface';
 import { Ermcp3SellBuyContract } from '@/services/go/ermcp/purchase/interface';
 import { getGoodsQuoteList } from '@/services/bus/goods';
+import { useTradeAccount } from '@/hooks/account';
 import { message } from 'ant-design-vue';
 
 export default defineComponent({
@@ -112,7 +112,8 @@ export default defineComponent({
       cancel();
     }
 
-    const { rules, formData, accountList, allPositionList, getPositionList } = handleForm(selectedGoods.value);
+    const { futuresAccountList, tradePositionList, tradeAccount, tradeAccountChange } = useTradeAccount();
+    const { rules, formData } = handleForm(selectedGoods.value);
     const formRef = ref();
     const loading = ref<boolean>(false);
 
@@ -132,14 +133,31 @@ export default defineComponent({
 
     // 持仓列表
     const positionList = computed(() => {
-      const result = allPositionList.value.filter((item) => item.goodsid === selectedGoods.value.goodsid);
-      const { goodscode, goodsid, buyorsell } = props.selectedRow;
-      // 查找选中的持仓单据
-      const index = result.findIndex((item) => item.goodscode === goodscode && item.goodsid === goodsid && item.buyorsell === buyorsell);
-      if (index > -1) {
-        onSelectChange([index], [result[index]])
+      if (selectedGoods.value) {
+        const { goodscode, goodsid } = selectedGoods.value;
+        // 判断是否套保交易
+        if (isHedging) {
+          // 买卖方向,根据合同类型判断
+          const buyorsell = props.selectedRow.contracttype === 1 ? BuyOrSell.buy : BuyOrSell.sell;
+          const index = tradePositionList.findIndex((item) => item.goodscode === goodscode && item.goodsid === goodsid && item.buyorsell === buyorsell);
+          if (index > -1) {
+            const result = [tradePositionList[index]];
+            onSelectChange([0], result);
+            return result;
+          }
+          return [];
+        } else {
+          // 过滤出当前商品的持仓单据
+          const result = tradePositionList.filter((item) => item.goodsid === goodsid);
+          // 查找选中的持仓单据
+          const index = result.findIndex((item) => item.goodscode === goodscode && item.buyorsell === props.selectedRow.buyorsell);
+          if (index > -1) {
+            onSelectChange([index], [result[index]])
+          }
+          return result;
+        }
       }
-      return result;
+      return [];
     });
     // 选中的价格类型
     const selectedPriceType = ref(1);
@@ -298,9 +316,8 @@ export default defineComponent({
           formData.OrderPrice = buyorsell === BuyOrSell.buy ? sellPrice.value : buyPrice.value; // 根据持仓方向选择平仓价格
           formData.ChannelBuildType = BuildType.close;
 
-          const account = accountList.find((el) => el.accountid === formData.AccountID)!;
           // 判断是否母账号
-          if (account.ismain) {
+          if (tradeAccount.value?.ismain) {
             if (selectedGoods.value.outerdealmode === 3 && curtdpositionenabled > 0) {
               formData.CloseTodayQty = curtdpositionenabled;
             }
@@ -320,7 +337,7 @@ export default defineComponent({
       cancel,
       loading,
       visible,
-      accountList,
+      futuresAccountList,
       positionList,
       rules,
       formRef,
@@ -330,7 +347,7 @@ export default defineComponent({
       buyPrice,
       sellPrice,
       selectedGoods,
-      getPositionList,
+      tradeAccountChange,
       goodsChange,
       selectedRowKeys,
       selectedPosition,

+ 1 - 18
src/views/market/futures/compoments/futures-trade/setup.ts

@@ -1,5 +1,5 @@
 import moment from "moment";
-import { reactive, ref } from "vue";
+import { reactive } from "vue";
 import { GoodsQuote } from '@/services/go/ermcp/goodsInfo/interface';
 import { ChannelOrderReq } from '@/services/proto/futures/interface';
 import { v4 as uuidv4 } from 'uuid';
@@ -8,8 +8,6 @@ import { getBuyOrSellName } from '@/common/constants/enumsName';
 import { geLoginID_number } from '@/services/bus/login';
 import { getUserId } from '@/services/bus/user';
 import { RuleObject } from 'ant-design-vue/es/form/interface';
-import { getAccountTypeList } from '@/services/bus/account';
-import { queryErmcpTradePosition } from '@/services/go/ermcp/futures';
 import { QueryErmcpTradePositionRsp } from '@/services/go/ermcp/futures/interface';
 import { getSelectedAccountId } from '@/services/bus/account';
 
@@ -83,18 +81,6 @@ export function handleForm(selectedRow: GoodsQuote) {
         TimeValidType: 1, // uint32 时间有效类型
     })
 
-    // 账号列表
-    const accountList = getAccountTypeList([1]);
-
-    // 所有持仓列表
-    const allPositionList = ref<QueryErmcpTradePositionRsp[]>([]);
-    const getPositionList = (id: number) => {
-        queryErmcpTradePosition({ accountID: id }).then((res) => {
-            allPositionList.value = res;
-        })
-    }
-    getPositionList(formData.AccountID)
-
     // 验证交易价格
     const verifyOrderPrice = async (rule: RuleObject, value: number) => {
         if (value) {
@@ -111,10 +97,7 @@ export function handleForm(selectedRow: GoodsQuote) {
 
     return {
         rules,
-        accountList,
-        allPositionList,
         formData,
-        getPositionList,
     }
 }
 

+ 1 - 118
src/views/order/funding_information/components/funding_information_funding_summary/setup.tsx

@@ -1,11 +1,4 @@
-import APP from '@/services';
-import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
-import { getMarketTradePropertyByGoodsId } from '@/services/bus/market';
-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';
-import { getFreeze } from '@/services/bus/account';
 import { getTaacountStatus, getPayCurrencyTypeEnumItemName } from '@/common/constants/enumsName';
 
 export function getColumns() {
@@ -91,114 +84,4 @@ function handlePriceColor(value: number, text: string) {
         className = 'down-quote-color'
     }
     return <span class={className}>{text}</span>;
-}
-
-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 === 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 tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid)
-            let temp = 0
-            if (tradeproperty === 1) {
-                // 资金 只算 收益权
-                const profitloos = useProfitloss(current)
-                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
-    }
-    // 净值
-    // 根据系统参数“307 账户净值是否减冻结资金 - 0:不减 1:减“
-    //0.净值=期末余额+市值+浮动盈亏(收益权)
-    //1.净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
-    function netWorth(taaccount: Taaccount) {
-        const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
-        // 浮动盈亏
-        const free = getSystemParam('037', '1') ? (otherfreezemargin + outamountfreeze) : 0
-
-        const profitloss = handleProfitloss(taaccount, false) as number
-        // 市值
-        const price = handleHoldPrice(accountid)
-        const decimalplace = getDecimalplace()
-        return (currentbalance + profitloss + price - free).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 }
-}
-
+}