huangbin 4 yıl önce
ebeveyn
işleme
04426d68e9

+ 18 - 1
src/common/setup/table/tableQuote.ts

@@ -11,7 +11,7 @@ import { onBeforeUnmount, onMounted, Ref, ref, watchEffect } from "vue";
  * @param itemTableHeight 表格每一行的高度
  * @param selector 当前的滚动区域的选择器
  */
-export function handleSubcriteQuote<T extends object>(tableList: Ref<T[]>, codeKey = 'goodscode', itemTableHeight = 31, selector = '.ant-table-body') {
+export function handleSubcriteOnDemandQuote<T extends object>(tableList: Ref<T[]>, codeKey = 'goodscode', itemTableHeight = 31, selector = '.ant-table-body') {
     const beforeScrollTop = ref<number>(0)
     const uuid = v4();
     onMounted(() => {
@@ -88,6 +88,23 @@ export function handleSubcriteQuote<T extends object>(tableList: Ref<T[]>, codeK
     }
 }
 
+// 处理行情订阅,注意这里不是按需订阅
+export function handleSubcriteQuote() {
+    const uuid = v4();
+    function subscribeAction(goodscode: string[]) {
+        removeSubscribeQuotation(uuid);
+        const goodsList = goodscode.map(el => {
+            return { exchangeCode: 250, goodsCode: el, subState: 0 };
+        })
+        //  行情订阅
+        addSubscribeQuotation(uuid, goodsList);
+    }
+    onBeforeUnmount(() => {
+        removeSubscribeQuotation(uuid);
+    });
+    return { subscribeAction }
+}
+
 function isPrice(price1: number | string, price2: number | string) {
     if (price2 && price2 !== '--' && price1 && price1 !== '--') {
         return true

+ 2 - 2
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_basis_difference/index.vue

@@ -70,7 +70,7 @@ import { contextMenu, defineAsyncComponent, defineComponent } from '@/common/exp
 
 import { handleDeliveryRelation } from '../setup';
 
-import { handleSubcriteQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
+import { handleSubcriteOnDemandQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
 import { QueryDeliveryRelationRsp } from '@/services/go/delivery/interface';
 import { columnsList } from '../setup';
 
@@ -99,7 +99,7 @@ export default defineComponent({
         ];
         const { deliverGoods, getQuoteList, findDeilverGoodsByGoodsCode } = handleDeliveryRelation([2, 4]);
         // 行情按需订阅
-        handleSubcriteQuote<QueryDeliveryRelationRsp>(deliverGoods);
+        handleSubcriteOnDemandQuote<QueryDeliveryRelationRsp>(deliverGoods);
 
         return {
             ...handleTableEventAndData<QueryQuoteDayRsp>(param),

+ 63 - 65
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_listing_transfer/index.vue

@@ -1,67 +1,65 @@
 <template>
-    <!--订单交易 挂牌转让-->
-    <div class="topTableHeight">
-        <a-table
-            :columns="columns"
-            class="srcollYTable"
-            :scroll="{ x: '100%', y: 'calc(100vh - 384px)' }"
-            :pagination="false"
-            :loading="loading"
-            :expandedRowKeys="expandedRowKeys"
-            :customRow="Rowclick"
-            rowKey="goodscode"
-            ref="tableRef"
-            :data-source="getQuoteList()"
-        >
-            <template #totalturnover="{ text }">
-                <span>{{changeUnit(text)}}</span>
-            </template>
-            <!-- 涨跌 -->
-            <template #change="{ record }">
-                <span>{{quoteChange(record, record.decimalplace)}}</span>
-            </template>
-            <!-- 幅度 -->
-            <template #amplitude="{ record }">
-                <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
-            </template>
-            <!-- 振幅 -->
-            <template #vibration="{ record }">
-                <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
-            </template>
-            <template #index="{ index }">
-                <span>{{index + 1}}</span>
-            </template>
-            <!-- 买价 -->
-            <template #bid="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 卖价 -->
-            <template #ask="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最新价 -->
-            <template #last="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最低价 -->
-            <template #lowest="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最高价 -->
-            <template #highest="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-        </a-table>
-        <!-- 右键 -->
-        <contextMenu :contextMenu="contextMenu" @cancel="closeContext" :list="btnList"></contextMenu>
-        <component
-            :is="componentId"
-            v-if="componentId"
-            :selectedRow="selectedRow"
-            :deliverGoods="findDeilverGoodsByGoodsCode(selectedRow.goodscode)"
-            @cancel="closeComponent"
-        ></component>
-    </div>
+  <!--订单交易 挂牌转让-->
+  <div class="topTableHeight">
+    <a-table :columns="columns"
+             class="srcollYTable"
+             :scroll="{ x: '100%', y: 'calc(100vh - 384px)' }"
+             :pagination="false"
+             :loading="loading"
+             :expandedRowKeys="expandedRowKeys"
+             :customRow="Rowclick"
+             rowKey="goodscode"
+             ref="tableRef"
+             :data-source="getQuoteList()">
+      <template #totalturnover="{ text }">
+        <span>{{changeUnit(text)}}</span>
+      </template>
+      <!-- 涨跌 -->
+      <template #change="{ record }">
+        <span>{{quoteChange(record, record.decimalplace)}}</span>
+      </template>
+      <!-- 幅度 -->
+      <template #amplitude="{ record }">
+        <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
+      </template>
+      <!-- 振幅 -->
+      <template #vibration="{ record }">
+        <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
+      </template>
+      <template #index="{ index }">
+        <span>{{index + 1}}</span>
+      </template>
+      <!-- 买价 -->
+      <template #bid="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 卖价 -->
+      <template #ask="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最新价 -->
+      <template #last="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最低价 -->
+      <template #lowest="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最高价 -->
+      <template #highest="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+    </a-table>
+    <!-- 右键 -->
+    <contextMenu :contextMenu="contextMenu"
+                 @cancel="closeContext"
+                 :list="btnList"></contextMenu>
+    <component :is="componentId"
+               v-if="componentId"
+               :selectedRow="selectedRow"
+               :deliverGoods="findDeilverGoodsByGoodsCode(selectedRow.goodscode)"
+               @cancel="closeComponent"></component>
+  </div>
 </template>
 
 <script lang="ts">
@@ -70,7 +68,7 @@ import { contextMenu, defineAsyncComponent, defineComponent } from '@/common/exp
 
 import { handleDeliveryRelation } from '../setup';
 
-import { handleSubcriteQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
+import { handleSubcriteOnDemandQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
 import { QueryDeliveryRelationRsp } from '@/services/go/delivery/interface';
 import { columnsList } from '../setup';
 
@@ -100,7 +98,7 @@ export default defineComponent({
         ];
         const { deliverGoods, getQuoteList, findDeilverGoodsByGoodsCode } = handleDeliveryRelation([1, 3]);
         // 行情按需订阅
-        handleSubcriteQuote<QueryDeliveryRelationRsp>(deliverGoods);
+        handleSubcriteOnDemandQuote<QueryDeliveryRelationRsp>(deliverGoods);
 
         return {
             ...handleTableEventAndData<QueryQuoteDayRsp>(param),

+ 63 - 65
src/views/market/spot_trade/spot_trade_reference_market/index.vue

@@ -1,67 +1,65 @@
 <template>
-    <!--参考行情-->
-    <div class="topTableHeight">
-        <a-table
-            :columns="columns"
-            class="srcollYTable"
-            :scroll="{ x: '100%', y: 'calc(100vh - 384px)' }"
-            :pagination="false"
-            :loading="loading"
-            :expandedRowKeys="expandedRowKeys"
-            :customRow="Rowclick"
-            rowKey="goodscode"
-            ref="tableRef"
-            :data-source="goodsList"
-        >
-            <template #totalturnover="{ text }">
-                <span>{{changeUnit(text)}}</span>
-            </template>
-            <!-- 涨跌 -->
-            <template #change="{ record }">
-                <span>{{quoteChange(record, record.decimalplace)}}</span>
-            </template>
-            <!-- 幅度 -->
-            <template #amplitude="{ record }">
-                <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
-            </template>
-            <!-- 振幅 -->
-            <template #vibration="{ record }">
-                <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
-            </template>
-            <template #index="{ index }">
-                <span>{{index + 1}}</span>
-            </template>
-            <!-- 买价 -->
-            <template #bid="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 卖价 -->
-            <template #ask="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最新价 -->
-            <template #last="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最低价 -->
-            <template #lowest="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-            <!-- 最高价 -->
-            <template #highest="{ text, record }">
-                <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
-            </template>
-        </a-table>
-        <!-- 右键 -->
-        <contextMenu :contextMenu="contextMenu" @cancel="closeContext" :list="firstBtn"></contextMenu>
-        <component
-            :is="componentId"
-            v-if="componentId"
-            :enumName="name"
-            :selectedRow="selectedRow"
-            @cancel="closeComponent"
-        ></component>
-    </div>
+  <!--参考行情-->
+  <div class="topTableHeight">
+    <a-table :columns="columns"
+             class="srcollYTable"
+             :scroll="{ x: '100%', y: 'calc(100vh - 384px)' }"
+             :pagination="false"
+             :loading="loading"
+             :expandedRowKeys="expandedRowKeys"
+             :customRow="Rowclick"
+             rowKey="goodscode"
+             ref="tableRef"
+             :data-source="goodsList">
+      <template #totalturnover="{ text }">
+        <span>{{changeUnit(text)}}</span>
+      </template>
+      <!-- 涨跌 -->
+      <template #change="{ record }">
+        <span>{{quoteChange(record, record.decimalplace)}}</span>
+      </template>
+      <!-- 幅度 -->
+      <template #amplitude="{ record }">
+        <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
+      </template>
+      <!-- 振幅 -->
+      <template #vibration="{ record }">
+        <span>{{quoteAmplituOfVibration(record, record.decimalplace)}}</span>
+      </template>
+      <template #index="{ index }">
+        <span>{{index + 1}}</span>
+      </template>
+      <!-- 买价 -->
+      <template #bid="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 卖价 -->
+      <template #ask="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最新价 -->
+      <template #last="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最低价 -->
+      <template #lowest="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+      <!-- 最高价 -->
+      <template #highest="{ text, record }">
+        <span :class="handleQuotePriceColor(text, record.presettle)">{{text}}</span>
+      </template>
+    </a-table>
+    <!-- 右键 -->
+    <contextMenu :contextMenu="contextMenu"
+                 @cancel="closeContext"
+                 :list="firstBtn"></contextMenu>
+    <component :is="componentId"
+               v-if="componentId"
+               :enumName="name"
+               :selectedRow="selectedRow"
+               @cancel="closeComponent"></component>
+  </div>
 </template>
 
 <script lang="ts">
@@ -71,7 +69,7 @@ import { QueryOrderQuoteReq } from '@/services/go/wrtrade/interface';
 import { queryOrderQuote } from '@/services/go/wrtrade';
 import { handleComposeTable } from '@/views/market/spot_trade/setup';
 import { ref } from 'vue';
-import { handleSubcriteQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
+import { handleSubcriteOnDemandQuote, handleQuotePriceColor, quoteChange, quoteAmplitude, quoteAmplituOfVibration } from '@/common/setup/table/tableQuote';
 import { QueryDeliveryRelationRsp } from '@/services/go/delivery/interface';
 import { getGoodsListByTrade, getQutoGoodsByTradeMode } from '@/services/bus/goods';
 import { TradeMode } from '@/common/constants/enumCommon';
@@ -121,7 +119,7 @@ export default defineComponent({
         // 行情商品
         const goodsList = getQutoGoodsByTradeMode(TradeMode.quote99);
         // 行情按需订阅
-        handleSubcriteQuote<QueryQuoteDayRsp>(goodsList);
+        handleSubcriteOnDemandQuote<QueryQuoteDayRsp>(goodsList);
         // 获取列表数据
         const queryTableAction = () => {
             const param: QueryOrderQuoteReq = {

+ 59 - 2
src/views/order/commodity_contract/components/commodity_contract_summary/index.vue

@@ -23,6 +23,18 @@
       <template #createtime="{ record }">
         <a>{{ formatTime(record.createtime) }}</a>
       </template>
+      <!-- 现价 -->
+      <template #lastprice="{ record }">
+        <a>{{ getLastprice(record) }}</a>
+      </template>
+      <!-- 持仓金额  -->
+      <template #holderprice="{ record }">
+        <a>{{ getHolderprice(record) }}</a>
+      </template>
+      <!-- 持仓盈亏 -->
+      <template #profitloss="{ record }">
+        <a>{{ getProfitloss(record) }}</a>
+      </template>
     </a-table>
     <component :is="componentId"
                v-if="componentId"
@@ -37,11 +49,12 @@ import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEn
 import { getRecordItemTab } from '@/common/setup/order/orderData';
 import { handleComposeOrderTable } from '@/common/setup/table/compose';
 import { ComposeOrderTableParam } from '@/common/setup/table/interface';
-import { getOperateTypeEnumItemName, getOperateTypeName } from '@/common/constants/enumsName';
 import { formatTime } from '@/common/methods';
 import { expandIcon } from '@/common/setup/table/clolumn';
 import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
+import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
+import { getQuoteDayInfoByCode } from '@/services/bus/goods';
 
 export default defineComponent({
     name: enumOrderComponents.commodity_contract_summary,
@@ -53,9 +66,16 @@ export default defineComponent({
     setup() {
         // 表格列表数据
         const { loading, tableList, queryTable } = queryTableList<QueryTradePositionRsp>();
+        const { subscribeAction } = handleSubcriteQuote();
         // 获取列表数据
         const queryTableAction = () => {
-            queryTable(queryTradePosition);
+            queryTable(queryTradePosition).then((res) => {
+                const goodsList = res.map((el) => {
+                    return el.goodscode;
+                });
+                //  行情订阅
+                subscribeAction(goodsList);
+            });
         };
         // 表格通用逻辑
         const param: ComposeOrderTableParam = {
@@ -63,12 +83,49 @@ export default defineComponent({
             tableName: 'table_pcweb_spot_trade_bottom_commodity_contract_summary',
             recordList: getRecordItemTab(),
         };
+        // 现价
+        function getLastprice({ goodscode, decimalplace }: QueryTradePositionRsp) {
+            const item = getQuoteDayInfoByCode(goodscode);
+            let result = '';
+            if (item) {
+                const { last, presettle } = item;
+                if (last) {
+                    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;
+            }
+        }
         return {
             ...handleComposeOrderTable<QueryTradePositionRsp>(param),
             loading,
             tableList,
             formatTime,
             expandIcon,
+            getLastprice,
+            getHolderprice,
+            getProfitloss,
         };
     },
 });