Ver código fonte

修改商品订单 合约汇总 平仓、协议平仓

huangbin 4 anos atrás
pai
commit
509f67ee3f

+ 1 - 1
public/config/app.config.json

@@ -1,3 +1,3 @@
 {
-    "apiUrl": "http://192.168.31.139:8080/cfg?key=test_139"
+    "apiUrl": "http://192.168.31.135:8080/cfg?key=test_135"
 }

+ 4 - 4
src/services/bus/goods.ts

@@ -3,7 +3,7 @@ import { initData } from '@/common/methods';
 import APP from '@/services';
 import { Ref, ref } from 'vue';
 import { Goods } from '../go/ermcp/goodsInfo/interface';
-import { QueryQuoteDayRsp } from '../go/quote/interface';
+import { QueryQuoteDay, QueryQuoteDayRsp } from '../go/quote/interface';
 import { Goodsgroup, Market } from '../go/useInfo/interface';
 import { getMarketByTradeMode } from './market';
 
@@ -32,7 +32,7 @@ export function getGoodsListByTrade(trademode: TradeMode): Ref<Goods[]> {
 
 // 通过trademode 获取行情,并获取goodsname
 export function getQutoGoodsByTradeMode(trademode: TradeMode) {
-    const result = ref<QueryQuoteDayRsp[]>([])
+    const result = ref<QueryQuoteDay[]>([])
     initData(() => {
         // 获取市场信息
         const marketInfo = getMarketByTradeMode(trademode)
@@ -44,8 +44,8 @@ export function getQutoGoodsByTradeMode(trademode: TradeMode) {
                 // 找到行情数据
                 const quote = getQuoteDayInfoByCode(el.goodscode);
                 if (quote) {
-                    Object.assign(quote, { goodsname: el.goodsname, goodsid: el.goodsid })
-                    result.value.push(quote)
+                    const obj = { ...quote, goodsname: el.goodsname, goodsid: el.goodsid }
+                    result.value.push(obj)
                 }
                 console.log('result', result)
             })

+ 4 - 2
src/services/bus/holdPosition.ts

@@ -1,3 +1,4 @@
+import { BuyOrSell } from "@/common/constants/enumCommon";
 import { QueryTradePositionRsp } from "../go/ermcp/order/interface";
 import { getQuoteDayInfoByCodeFindPrice } from "./goods";
 
@@ -10,8 +11,9 @@ 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);
+        const { averageprice, decimalplace, agreeunit, curpositionqty, buyorsell } = record;
+        const temp = buyorsell === BuyOrSell.buy ? 1 : -1
+        return ((+lastPrice - averageprice) * curpositionqty * agreeunit * temp).toFixed(decimalplace);
     } else {
         return lastPrice;
     }

+ 5 - 0
src/services/go/quote/interface.ts

@@ -219,3 +219,8 @@ export interface QueryQuoteDayRsp {
     totalvolume: number;
     utclasttime: string;
 }
+
+export interface QueryQuoteDay extends QueryQuoteDayRsp {
+    goodsid: number;
+    goodsname: string;
+}

+ 5 - 0
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/components/setup.ts

@@ -17,6 +17,11 @@ export const useUserType = () => {
     return getUserAccountType() === UserType.investment
 }
 
+// 判断是否是 机构
+export const isInstitution = () => {
+    return getUserAccountType() === UserType.institution
+}
+
 // 交易账号
 export function useBlocksAccount<T extends { accountid: number | undefined }>(formState: UnwrapRef<T>) {
     // 资金账号

+ 16 - 10
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/setup.ts

@@ -16,22 +16,28 @@ const allGoodsList = ref<RefGoodsList[]>([])
 export function findItemGoods(goodscode: string) {
     return refGoods.value.find(el => el.goodscode === goodscode)!
 }
+
+const { loading, queryTable } = queryTableList<QueryQuoteGoodsListRsp>();
+
+export function getSwapList() {
+    // 组装 参数
+    const marketids = getMarketIdsByTradeMode(TradeMode.DiaoQi)
+    const param: QueryQuoteGoodsListReq = {
+        usertype: getUserAccountType(),
+    }
+    if (marketids) {
+        param.marketids = marketids
+    }
+    return queryTable(queryQuoteGoodsList, param)
+}
+
 // 获取 商品掉期 商品列表
 export const useSwapList = () => {
-    const { loading, queryTable } = queryTableList<QueryQuoteGoodsListRsp>();
     // 行情商品
     const goodsList = ref<RefGoodsList[]>([])
     initData(() => {
-        // 组装 参数
-        const marketids = getMarketIdsByTradeMode(TradeMode.DiaoQi)
-        const param: QueryQuoteGoodsListReq = {
-            usertype: getUserAccountType(),
-        }
-        if (marketids) {
-            param.marketids = marketids
-        }
         // 开始查询 商品掉期
-        queryTable(queryQuoteGoodsList, param).then(res => {
+        getSwapList().then(res => {
             refGoods.value = res
             goodsList.value.length = 0
             allGoodsList.value.length = 0

+ 46 - 13
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_deal_closed/index.vue

@@ -29,10 +29,15 @@
                 <div class="line1">
                   <div class>
                     <a-checkbox @change="checkboxChange(item)"
+                                :disabled="item.holderdays"
                                 :value="item.tradeid"></a-checkbox>
                   </div>
-                  <div class="name">{{item.tradeid}}</div>
-                  <div class="date">{{formatTime(item.tradetime, 'd')}}</div>
+                  <div class="name">{{ item.tradeid }}
+                    <template v-if="item.holderdays">
+                      <span class="red">{{item.holderdays}}</span>天后可平
+                    </template>
+                  </div>
+                  <div class="date">{{formatTime(item.expiredate, 'd')}}</div>
                 </div>
                 <div class="line2">
                   <div class="left">{{item.buyorsell === BuyOrSell.buy ? '买入' : '卖出'}}</div>
@@ -41,7 +46,8 @@
                     <div>{{item.holderprice}}</div>
                     <div>{{item.holderamount}}</div>
                   </div>
-                  <div class="right red">+100</div>
+                  <div class="right red">
+                    {{useProfit(item, goodscode)}}</div>
                 </div>
               </div>
             </a-checkbox-group>
@@ -65,7 +71,7 @@
             <a-col :span="24">
               <a-form-item label="平仓金额"
                            class="mb10 not-copy ">
-                <span class="white">50400.20</span>
+                <span class="white">{{getMoney()}}</span>
               </a-form-item>
             </a-col>
           </a-row>
@@ -104,8 +110,11 @@ import { message } from 'ant-design-vue';
 import Long from 'long';
 import { defineComponent, PropType } from 'vue';
 import { BargainList, FormState } from './interface';
-import { handleForm, useCheckd, usePrice } from './setup';
+import { handleForm, usePrice } from './setup';
 import { formatTime } from '@/common/methods';
+import { useProfit, useCheckd } from '../setup';
+import { QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
+import { findGoodsCode } from '../../setup';
 
 export default defineComponent({
     name: ModalEnum.commodity_contract_summary_settlement,
@@ -120,10 +129,16 @@ export default defineComponent({
             type: Number as PropType<BuyOrSell>,
             default: BuyOrSell.buy,
         },
+        swapList: {
+            type: Array as PropType<QueryQuoteGoodsListRsp[]>,
+            default: [],
+        },
     },
     setup(props, context) {
         const { visible, cancel } = _closeModal(context);
         const { rules, formState, formRef } = handleForm();
+        const goodscode = findGoodsCode(props.selectedRow.goodsid, props.selectedRow.goodscode, props.swapList);
+
         // 选中逻辑
         const { checked, selected, checkGroupChange, checkboxChange } = useCheckd();
 
@@ -134,16 +149,31 @@ export default defineComponent({
             userid: getUserId(),
             goodsid: props.selectedRow.goodsid,
         };
+        // 平仓金额
+        function getMoney() {
+            let result = '--';
+            if (selected.value && formState.price) {
+                const { holderqty, agreeunit, decimalplace } = selected.value;
+                result = (+formState.price * holderqty * agreeunit).toFixed(decimalplace);
+            }
+            return result;
+        }
         queryTable(queryTradeHolderDetail, param).then((res) => {
+            let index = 0; // 默认勾选
             tableList.value = res.map((e, i) => {
-                if (i) {
-                    return { ...e, checked: false };
+                if (index === i) {
+                    if (e.holderdays === 0) {
+                        checked.value = e.tradeid;
+                        const result = { ...e, checked: true };
+                        selected.value = result;
+                        index = -1;
+                        return result;
+                    } else {
+                        index++;
+                        return { ...e, checked: false };
+                    }
                 } else {
-                    // 默认勾选第一个
-                    checked.value = e.tradeid;
-                    const result = { ...e, checked: true };
-                    selected.value = result;
-                    return result;
+                    return { ...e, checked: false };
                 }
             });
         });
@@ -185,6 +215,9 @@ export default defineComponent({
             checkboxChange,
             BuyOrSell,
             formatTime,
+            useProfit,
+            goodscode,
+            getMoney,
         };
     },
 });
@@ -249,7 +282,7 @@ export default defineComponent({
                     width: 100%;
                     height: 40px;
                     line-height: 40px;
-                    font-size: 16px;
+                    font-size: 12px;
                     color: @m-white6;
                     white-space: nowrap;
                     text-overflow: ellipsis;

+ 1 - 21
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_deal_closed/setup.ts

@@ -1,7 +1,7 @@
 import { validateCommon } from "@/common/setup/validate";
 import { RuleObject } from "ant-design-vue/lib/form/interface";
 import { reactive, ref, UnwrapRef } from "vue";
-import { BargainList, FormState } from "./interface";
+import { FormState } from "./interface";
 
 export function handleForm() {
     const formRef = ref();
@@ -31,25 +31,5 @@ export function usePrice(formState: UnwrapRef<FormState>) {
     return { increasePirce, decreasePrice }
 }
 
-export function useCheckd() {
-    const checked = ref<string>();
-    const selected = ref<BargainList>()
-    function checkGroupChange(checkedValue: string[]) {
-        checked.value = checkedValue[checkedValue.length - 1];
-    }
-    function checkboxChange(item: BargainList) {
-        selected.value = item;
-    }
-    return { checked, selected, checkGroupChange, checkboxChange }
-}
-
-// 计算盈亏
-export function useProfit(item: BargainList) {
-    const { buyorsell, holderprice, agreeunit, holderqty } = item
-    // let result = '--'
-    // if(buyorsell === BuyOrSell.buy) {
 
-    // } else {
 
-    // }
-}

+ 52 - 21
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_order_closed/index.vue

@@ -29,10 +29,15 @@
                 <div class="line1">
                   <div class>
                     <a-checkbox @change="checkboxChange(item)"
+                                :disabled="item.holderdays"
                                 :value="item.tradeid"></a-checkbox>
                   </div>
-                  <div class="name">{{ item.tradeid }}</div>
-                  <div class="date">{{ formatTime(item.tradetime, 'd') }}</div>
+                  <div class="name">{{ item.tradeid }}
+                    <template v-if="item.holderdays">
+                      <span class="red">{{item.holderdays}}</span>天后可平
+                    </template>
+                  </div>
+                  <div class="date">{{ formatTime(item.expiredate, 'd') }}</div>
                 </div>
                 <div class="line2">
                   <div class="left">{{ item.buyorsell === BuyOrSell.buy ? '买入' : '卖出' }}</div>
@@ -41,32 +46,28 @@
                     <div>{{ item.holderprice }}</div>
                     <div>{{ item.holderamount }}</div>
                   </div>
-                  <div class="right red">+100</div>
+                  <div class="right red">
+                    {{useProfit(item, goodscode)}}</div>
                 </div>
               </div>
             </a-checkbox-group>
           </div>
         </div>
         <div class="fixedBtns">
-          <a-row :gutter="24"
-                 v-if="false">
+          <a-row :gutter="24">
             <a-col :span="24"
                    class="mt12">
               <a-form-item label="估算价"
                            name="price"
                            class="inputIconBox mb10 not-copy">
-                <a-input-number class="commonInput not-copy"
-                                v-model:value="formState.price"
-                                style="width: 200px"
-                                :min="0" />
-                <MinusOutlined @click="decreasePrice" />
-                <PlusOutlined @click="increasePirce" />
+                <!-- 估算价取标的商品行情的最新价 -->
+                <span class="white">{{getQuoteDayInfoByCodeFindPrice(goodscode)}}</span>
               </a-form-item>
             </a-col>
             <a-col :span="24">
               <a-form-item label="估算金额"
                            class="mb10 not-copy">
-                <span class="white">50400.20</span>
+                <span class="white">{{getMoney()}}</span>
               </a-form-item>
             </a-col>
           </a-row>
@@ -105,8 +106,12 @@ import { message } from 'ant-design-vue';
 import Long from 'long';
 import { defineComponent, PropType } from 'vue';
 import { BargainList, FormState } from './interface';
-import { handleForm, useCheckd, usePrice } from './setup';
+import { handleForm, usePrice } from './setup';
 import { formatTime } from '@/common/methods';
+import { useProfit, useCheckd } from '../setup';
+import { QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
+import { findGoodsCode } from '../../setup';
+import { getQuoteDayInfoByCodeFindPrice } from '@/services/bus/goods';
 
 export default defineComponent({
     name: ModalEnum.commodity_contract_summary_settlement,
@@ -121,8 +126,14 @@ export default defineComponent({
             type: Number as PropType<BuyOrSell>,
             default: BuyOrSell.buy,
         },
+        swapList: {
+            type: Array as PropType<QueryQuoteGoodsListRsp[]>,
+            default: [],
+        },
     },
     setup(props, context) {
+        const goodscode = findGoodsCode(props.selectedRow.goodsid, props.selectedRow.goodscode, props.swapList);
+
         const { visible, cancel } = _closeModal(context);
         const { rules, formState, formRef } = handleForm();
         // 选中逻辑
@@ -135,17 +146,33 @@ export default defineComponent({
             userid: getUserId(),
             goodsid: props.selectedRow.goodsid,
         };
+        // 估算金额=估算价*平仓数量*合约单位。
+        function getMoney() {
+            let result = '--';
+            const lastPrice = getQuoteDayInfoByCodeFindPrice(goodscode);
+            if (lastPrice && lastPrice !== '--' && selected.value) {
+                const { holderqty, agreeunit, decimalplace } = selected.value;
+                result = (+lastPrice * holderqty * agreeunit).toFixed(decimalplace);
+            }
+            return result;
+        }
 
         queryTable(queryTradeHolderDetail, param).then((res) => {
+            let index = 0; // 默认勾选
             tableList.value = res.map((e, i) => {
-                if (i) {
-                    return { ...e, checked: false };
+                if (index === i) {
+                    if (e.holderdays === 0) {
+                        checked.value = e.tradeid;
+                        const result = { ...e, checked: true };
+                        selected.value = result;
+                        index = -1;
+                        return result;
+                    } else {
+                        index++;
+                        return { ...e, checked: false };
+                    }
                 } else {
-                    // 默认勾选第一个
-                    checked.value = e.tradeid;
-                    const result = { ...e, checked: true };
-                    selected.value = result;
-                    return result;
+                    return { ...e, checked: false };
                 }
             });
         });
@@ -193,6 +220,10 @@ export default defineComponent({
             checkboxChange,
             BuyOrSell,
             formatTime,
+            useProfit,
+            goodscode,
+            getQuoteDayInfoByCodeFindPrice,
+            getMoney,
         };
     },
 });
@@ -257,7 +288,7 @@ export default defineComponent({
                     width: 100%;
                     height: 40px;
                     line-height: 40px;
-                    font-size: 16px;
+                    font-size: 12px;
                     color: @m-white6;
                     white-space: nowrap;
                     text-overflow: ellipsis;

+ 1 - 24
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_order_closed/setup.ts

@@ -1,7 +1,7 @@
 import { validateCommon } from "@/common/setup/validate";
 import { RuleObject } from "ant-design-vue/lib/form/interface";
 import { reactive, ref, UnwrapRef } from "vue";
-import { BargainList, FormState } from "./interface";
+import { FormState } from "./interface";
 
 export function handleForm() {
     const formRef = ref();
@@ -30,26 +30,3 @@ export function usePrice(formState: UnwrapRef<FormState>) {
     }
     return { increasePirce, decreasePrice }
 }
-
-export function useCheckd() {
-    const checked = ref<string>();
-    const selected = ref<BargainList>()
-    function checkGroupChange(checkedValue: string[]) {
-        checked.value = checkedValue[checkedValue.length - 1];
-    }
-    function checkboxChange(item: BargainList) {
-        selected.value = item;
-    }
-    return { checked, selected, checkGroupChange, checkboxChange }
-}
-
-// 计算盈亏
-export function useProfit(item: BargainList) {
-    const { buyorsell, holderprice, agreeunit, holderqty } = item
-    // let result = '--'
-    // if(buyorsell === BuyOrSell.buy) {
-
-    // } else {
-
-    // }
-}

+ 31 - 0
src/views/order/commodity_contract/components/commodity_contract_summary/components/setup.ts

@@ -0,0 +1,31 @@
+import { BuyOrSell } from "@/common/constants/enumCommon";
+import { getQuoteDayInfoByCodeFindPrice } from "@/services/bus/goods";
+import { ref } from "vue";
+import { BargainList } from "./commodity_contract_summary_deal_closed/interface";
+
+// 计算盈亏
+// 浮动盈亏	持仓单:
+// 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率)
+// 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额)
+export function useProfit(item: BargainList, goodcode: string) {
+    // 最新价
+    const lastPrice = getQuoteDayInfoByCodeFindPrice(goodcode);
+    if (lastPrice && lastPrice !== '--') {
+        const { holderprice, holderqty, agreeunit, decimalplace, buyorsell } = item
+        const temp = buyorsell === BuyOrSell.buy ? 1 : -1
+        return ((+lastPrice - holderprice) * holderqty * agreeunit * temp).toFixed(decimalplace)
+    } else {
+        return lastPrice
+    }
+}
+export function useCheckd() {
+    const checked = ref<string>();
+    const selected = ref<BargainList>()
+    function checkGroupChange(checkedValue: string[]) {
+        checked.value = checkedValue[checkedValue.length - 1];
+    }
+    function checkboxChange(item: BargainList) {
+        selected.value = item;
+    }
+    return { checked, selected, checkGroupChange, checkboxChange }
+}

+ 29 - 12
src/views/order/commodity_contract/components/commodity_contract_summary/index.vue

@@ -47,6 +47,7 @@
                v-if="componentId"
                :selectedRow="selectedRow"
                :tableList="tableList"
+               :swapList="swapList"
                @cancel="closeComponent"></component>
   </section>
 </template>
@@ -68,6 +69,11 @@ import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
 import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { getBuyOrSellName, getChannelBuildName } from '@/common/constants/enumsName';
+import { isInstitution } from '@/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/components/setup';
+import { useIsDiaoQi, findGoodsCode } from './setup';
+import { getSwapList } from '@/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/setup';
+import { ref } from 'vue';
+import { QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
 
 const tabColumns = [
     {
@@ -197,21 +203,27 @@ export default defineComponent({
         const { subscribeAction } = handleSubcriteQuote();
         // 交割商品
         handleDeliveryRelation();
-
+        const swapList = ref<QueryQuoteGoodsListRsp[]>([]);
         // 挂牌点选商品
         //         const { deliverGoods, getQuoteList, goodsList, } = handleDeliveryRelation([1, 3]);
         //         // 参考行情商品
         // const goodsList = getQutoGoodsByTradeMode(TradeMode.quote99);
+
         // 获取列表数据
         const queryTableAction = () => {
-            queryTable(queryTradePosition).then((res) => {
-                const result: string[] = [];
-                res.forEach((el) => {});
-                const goodsList = res.map((el) => {
-                    return el.goodscode;
+            Promise.all([queryTable(queryTradePosition), 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(goodsList);
+                subscribeAction([...goodsSet]);
             });
         };
         // 表格通用逻辑
@@ -221,16 +233,20 @@ export default defineComponent({
             recordList: getRecordItemTab(),
         };
         // 现价
-        function getLastprice({ goodscode, decimalplace }: QueryTradePositionRsp) {
-            const lastPrice = getQuoteDayInfoByCodeFindPrice(goodscode);
-            return lastPrice === '--' ? lastPrice : Number(lastPrice).toFixed(decimalplace);
+        function getLastprice(record: QueryTradePositionRsp) {
+            let result: number | string = '--';
+            const goodscode = findGoodsCode(record.goodsid, record.goodscode, swapList.value);
+            if (goodscode) {
+                result = getQuoteDayInfoByCodeFindPrice(goodscode);
+            }
+            return result;
         }
-
         function handleBtnList(record: QueryTradePositionRsp, btnList: BtnListType[]) {
             // 挂牌点选
             const listing = ['commodity_contract_summary_transfer', 'commodity_contract_summary_settlement'];
             // 贸易圈
-            const diaoqi = ['commodity_contract_summary_deal_closed', 'commodity_contract_summary_order_closed'];
+            // 只有机构 才有平仓
+            const diaoqi = isInstitution() ? ['commodity_contract_summary_deal_closed', 'commodity_contract_summary_order_closed'] : ['commodity_contract_summary_deal_closed'];
             const arr = findGoodsTradeModeById(record.goodsid) === TradeMode.DiaoQi ? diaoqi : listing;
             return btnList.filter((e) => arr.includes(e.code));
         }
@@ -246,6 +262,7 @@ export default defineComponent({
             handleBtnList,
             tabColumns,
             getBuyOrSellName,
+            swapList,
         };
     },
 });

+ 16 - 0
src/views/order/commodity_contract/components/commodity_contract_summary/setup.ts

@@ -0,0 +1,16 @@
+// 获取最新价
+
+import { TradeMode } from "@/common/constants/enumCommon";
+import { findGoodsTradeModeById } from "@/services/bus/goods";
+import { QueryQuoteGoodsListRsp } from "@/services/go/Tjmd/interface";
+
+export const useIsDiaoQi = (goodsid: number) => {
+    return findGoodsTradeModeById(goodsid) === TradeMode.DiaoQi
+}
+
+
+// 商品掉期取参考行情最新价,挂牌点选取自己行情的最新价
+export function findGoodsCode(goodsid: number, goodscode: string, swapList: QueryQuoteGoodsListRsp[]) {
+    const result = useIsDiaoQi(goodsid) ? swapList.find((el) => goodsid === goodsid)?.refgoodscode : goodscode;
+    return result ? result : ''
+}