Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

yu jie vor 4 Jahren
Ursprung
Commit
838848ca6b

+ 2 - 5
src/services/socket/protobuf/buildReq.ts

@@ -188,11 +188,8 @@ function parseSoleProtoRsp(rspPackage: any, funCodeName: string): ParseRsp {
             return { isSuccess: true, result: reqPackage };
         } if (RetCode === -1) { // 管理端错误消息
             return { isSuccess: false, result: RetDesc };
-        } else {    // 数据库获取的错误信息
-            // sb服务   定义好的错误规则信息又修改了
-            // 原本一开始 RetCode -1 代表着管理端错误信息,现在管理端 RetCode 不为 -1 也包括管理端错误信息,
-            // 数据库中存放的错误信息枚举,只包含http请求的,不包含管理端proto的。所有又要添加一层判断
-            const errMsg = RetDesc ? RetDesc : getErrorInfoByCode(String(RetCode));
+        } else {
+            const errMsg = getErrorInfoByCode(String(RetCode));
             const result = errMsg ? errMsg : `未知错误:${RetCode}`;
             return { isSuccess: false, result };
         }

+ 23 - 51
src/views/market/spot_trade/components/buy-sell-market/components/delisting/index.vue

@@ -54,7 +54,7 @@
             </a-col>
           </a-row>
           <a-row :gutter="24"
-                 v-if="isBuy() && !isSale()">
+                 v-if="isBuy() && isWR()">
             <a-col :span="24">
               <a-form-item label="现货仓单"
                            name="LadingBillId">
@@ -75,9 +75,9 @@
                            class="relative"
                            name="num">
                 <a-input-number class="dialogInput yellowInput"
-                                @change="numChange"
                                 style="width: 260px"
                                 :min="0"
+                                :max="getMaxNum()"
                                 v-model:value="formState.num" />
                 <span class="input-enumdicname-absolute">{{selectedRow.enumdicname}}</span>
                 <div class="labelTip">({{selectedRow.minivalue}}{{selectedRow.enumdicname}}起)</div>
@@ -94,7 +94,7 @@
                           class="formSlider" />
                 <div class="unit">
                   <span>0</span>
-                  <span>{{uiParam.maxNum}}{{selectedRow.enumdicname}}</span>
+                  <span>{{getMaxNum()}}{{selectedRow.enumdicname}}</span>
                 </div>
               </a-form-item>
             </a-col>
@@ -103,20 +103,22 @@
           <a-row :gutter="24">
             <a-col :span="24"
                    class="mt-20">
-              <a-form-item label="摘牌金额">
-                <span class="white ml8">{{uiParam.amount}}</span>
+              <a-form-item :label="isFloat() ? '估算金额' : '摘牌金额'">
+                <span class="white ml8">{{getMoney()}}</span>
               </a-form-item>
             </a-col>
           </a-row>
           <a-row :gutter="24">
             <a-col :span="24"
                    class="mt-20">
-              <a-form-item label="履约保证金">
+              <a-form-item :label="getMargin() ? '履约保证金' : ''">
                 <a-row>
-                  <a-col :span="8">
-                    <span class="white ml8">{{uiParam.marginPrice}}</span>
+                  <a-col :span="8"
+                         v-if="getMargin()">
+                    <span class="white ml8">{{getMargin()}}</span>
                   </a-col>
-                  <a-col :span="4" class="tr">
+                  <a-col :span="4"
+                         class="tr">
                     <span class="grey1">可用资金</span>
                   </a-col>
                   <a-col :span="12">
@@ -157,14 +159,13 @@ import moment from 'moment';
 import { ModalEnum } from '@/common/constants/modalNameEnum';
 import { HdWRDealOrderReq } from '@/services/proto/warehousetrade/interface';
 import { _closeModal } from '@/common/setup/modal/modal';
-import { handleForm, handleIs, handleSpotWarrant } from './setup';
+import { handleForm, handleNumAndMoney, handleSpotWarrant, getWrPosition } from './setup';
+import { handleIs } from '../../setup';
 import { validateAction } from '@/common/setup/form';
 import { ListingForm } from './interface';
 import { BuyOrSell } from '@/common/constants/enumCommon';
 import { EnumRouterName } from '@/common/constants/enumRouterName';
-import { ListedViewModel, WrParam } from '../../setup';
-import { getAllTaAccount, getCanUseMoney, getFreeze, getSelectedAccount, setSelectedAccount } from '@/services/bus/account';
-import { AccountListItem } from '@/services/dataCenter/interafce/account';
+import { getCanUseMoney } from '@/services/bus/account';
 export default defineComponent({
     name: ModalEnum.spot_trade_warehouse_financing_delisting,
     components: { Drawer, PlusOutlined, MinusOutlined },
@@ -186,14 +187,9 @@ export default defineComponent({
             type: Number as PropType<BuyOrSell>,
             default: BuyOrSell.buy,
         },
-        goodsPrice: {
-            type: Object as PropType<Number | String>,
-            default: '--',
-        },
     },
 
     setup(props, context) {
-        console.log('props', props);
         const { visible, cancel } = _closeModal(context);
         // 资金账号
         const accountList = getAccountTypeList([2]);
@@ -206,36 +202,11 @@ export default defineComponent({
         }
         const loading = ref<boolean>(false);
         // 判断
-        const { isSale, isBuy, isFloat } = handleIs(props.enumName, props.buyOrSell);
+        const { isWR, isBuy, isFloat } = handleIs(props.enumName, props.buyOrSell);
         // 现货仓单
-        const { wrHoldList, allWR } = handleSpotWarrant(props.enumName, props.buyOrSell, props.parantSelectedRow, loading);
-        // 获取计算额与最大值
-        const { getCalculate, uiParam } = ListedViewModel(props.enumName);
-        function action() {
-            // 价格
-            let orderPrice = 0;
-            if (isFloat()) {
-                if (props.goodsPrice !== '--') {
-                    orderPrice = (props.goodsPrice as number) + props.selectedRow.pricemove;
-                }
-            } else {
-                orderPrice = props.selectedRow.fixedprice;
-            }
-            const param: WrParam = {
-                orderPrice,
-                availableFunds: Number(getCanUseMoney(getSelectedAccount() as AccountListItem)),
-                deListNum: formState.num,
-                listedNum: props.selectedRow.orderqty,
-            };
-            if (isBuy() && !isSale()) {
-                param.availableFunds = allWR.value.find((e) => e.ladingbillid === formState.LadingBillId)?.enableqty;
-            }
-            getCalculate(param);
-        }
-        action();
-        function numChange() {
-            action();
-        }
+        const { wrHoldList } = handleSpotWarrant(props.enumName, props.buyOrSell, props.parantSelectedRow, loading);
+        getWrPosition(props.enumName, props.buyOrSell, loading);
+        const { getMaxNum, getMoney, getMargin } = handleNumAndMoney(props.enumName, props.buyOrSell, props.selectedRow, props.parantSelectedRow, formState);
         function submit() {
             validateAction<ListingForm>(formRef, formState).then((res) => {
                 // 首先确定  这是仓单贸易的有仓单挂摘牌 HasWr = 1
@@ -258,7 +229,7 @@ export default defineComponent({
                     WRFactorTypeId: props.parantSelectedRow.wrfactortypeid, // uint64 仓单要素ID(wrholdlb的WRFactorTypeId字段),卖的时候填写
                     TradeDate: moment().format('YYYYMMDD'), // string 交易日
                     DeliveryMonth: '', // string 交收月
-                    HasWr: isSale() ? 0 : 1, // uint32 是否有仓单-0:没有仓单 1:有仓单
+                    HasWr: isWR(), // uint32 是否有仓单-0:没有仓单 1:有仓单
                     IsFinancing: 0, // uint32 是否融资购买(买摘牌时有效)-0:否 1:是
                     ProductDetailID: 0, // uint64 金融机构产品组合ID(融资购买时有效)
                 };
@@ -283,16 +254,17 @@ export default defineComponent({
             wrHoldList,
             loading,
             submit,
-            isSale,
+            isWR,
             isBuy,
             isFloat,
-            numChange,
             rules,
             formState,
             formRef,
-            uiParam,
             getCanUseMoney,
             getSelectedAccount,
+            getMaxNum,
+            getMoney,
+            getMargin,
         };
     },
 });

+ 117 - 31
src/views/market/spot_trade/components/buy-sell-market/components/delisting/setup.ts

@@ -1,9 +1,12 @@
 import { BuyOrSell } from "@/common/constants/enumCommon";
 import { EnumRouterName } from "@/common/constants/enumRouterName";
 import { queryResultLoadingAndInfo } from "@/common/methods/request/resultInfo";
-import { queryHoldLB } from '@/services/go/wrtrade';
-import { WrHoldLB, WrOrderQuote, WrOrderQuoteDetail } from "@/services/go/wrtrade/interface";
+import { getAccountTypeList, getCanUseMoney } from "@/services/bus/account";
+import { AccountListItem } from "@/services/dataCenter/interafce/account";
+import { queryHoldLB, queryWrPosition } from '@/services/go/wrtrade';
+import { QueryWrPositionReq, WrHoldLB, WrOrderQuote, WrOrderQuoteDetail, WrPosition } from "@/services/go/wrtrade/interface";
 import { reactive, Ref, ref, UnwrapRef } from "vue";
+import { getGoodsPrice, getRules, handleIs } from "../../setup";
 import { ListingForm, Wrhold } from "./interface";
 
 export function handleForm(data: WrOrderQuoteDetail) {
@@ -22,41 +25,28 @@ export function handleForm(data: WrOrderQuoteDetail) {
     return { rules, formState, formRef }
 }
 
-
-export function handleIs(enumName: EnumRouterName, buyOrSell: BuyOrSell) {
-    /**
-     *
-     * @returns true => 仓单预售; false => 仓单贸易
-     */
-    function isSale(): boolean {
-        return enumName === EnumRouterName.warehouse_pre_sale_price ||
-            enumName === EnumRouterName.warehouse_pre_sale_floating_price
-    }
-    /**
-     *
-     * @returns true => 买; false =>卖
-     */
-    function isBuy() {
-        return buyOrSell === BuyOrSell.buy
-    }
-    /**
-     *
-     * @returns  true => 浮动价; false =>一口价
-     */
-    function isFloat() {
-        return enumName === EnumRouterName.warehouse_receipt_trade_floating_price ||
-            enumName === EnumRouterName.warehouse_pre_sale_floating_price
+// 预售仓单汇总
+const wrPostion = ref<WrPosition[]>([])
+export function getWrPosition(enumName: EnumRouterName, buyOrSell: BuyOrSell, loading: Ref<boolean>) {
+    const { isWR, isBuy } = handleIs(enumName, buyOrSell)
+    if (isBuy() && !isWR()) {
+        const param: QueryWrPositionReq = {
+            haswr: 0,
+            querytype: 2,
+        };
+        queryResultLoadingAndInfo(queryWrPosition, loading, param).then(res => {
+            wrPostion.value = res;
+        })
     }
-    return { isSale, isBuy, isFloat }
 }
 
+const allWR = ref<WrHoldLB[]>([])
 // 处理现货仓单
 export function handleSpotWarrant(enumName: EnumRouterName, buyOrSell: BuyOrSell, selectedRow: WrOrderQuote, loading: Ref<boolean>) {
-    const { isSale, isBuy } = handleIs(enumName, buyOrSell)
-    const allWR = ref<WrHoldLB[]>([])
+    const { isWR, isBuy } = handleIs(enumName, buyOrSell)
     const wrHoldList = ref<Wrhold[]>([])
     if (isBuy()) {
-        if (!isSale()) {
+        if (isWR()) {
             queryResultLoadingAndInfo(queryHoldLB, loading).then(res => {
                 allWR.value = res;
                 wrHoldList.value = res.filter((e: WrHoldLB) => e.wrfactortypeid === String(selectedRow.wrfactortypeid)).map((e: WrHoldLB) => {
@@ -66,5 +56,101 @@ export function handleSpotWarrant(enumName: EnumRouterName, buyOrSell: BuyOrSell
             })
         }
     }
-    return { wrHoldList, allWR }
+    return { wrHoldList }
+}
+
+export function handleNumAndMoney(enumName: EnumRouterName, buyOrSell: BuyOrSell, selectedRow: WrOrderQuoteDetail, parantSelectedRow: WrOrderQuote, formState: UnwrapRef<ListingForm>) {
+    const { isWR, isBuy, isFloat } = handleIs(enumName, buyOrSell)
+    // 资金账号
+    const accountList = getAccountTypeList([2]);
+    // 获取选中的资金账号
+    const getSelectedAccount = () => accountList.find((e) => e.accountid === formState.accountid);
+    // 交易规则
+    const rules = getRules().value
+    // 是否有规则
+    const hasRule = () => rules.length > 0;
+    //保证金模式 1: 比率 2: 固定
+    const marginMethod = (buymarginalgorithm: number) => buymarginalgorithm === 1
+    const { fixedprice, orderqty, pricemove } = selectedRow;
+    // 获取摘牌最大可摘量
+    function getMaxNum() {
+        let result = 0;
+        if (hasRule()) {
+            const { buymarginvalue, buymarginalgorithm } = rules[0]
+            // 可用资金
+            const canUseMoney = Number(getCanUseMoney(getSelectedAccount() as AccountListItem))
+            if (!isBuy()) {
+                if (isFloat()) {
+                    const goodsPrice = getGoodsPrice()
+                    // 估算总价=挂牌基差+期货合约价;
+                    if (goodsPrice.value && goodsPrice.value !== '--') {   // 有实时行情价格
+                        // 估算总价
+                        const predictTotal = pricemove + (goodsPrice.value as number);
+                        // 买方履约保证金比例*估算总价
+                        const marginMoney = marginMethod(buymarginalgorithm) ? (buymarginvalue * predictTotal) : (buymarginvalue + predictTotal)
+                        // 浮动价 摘买 最大数量=min{可用资金/(买方履约保证金比例*估算总价),挂牌数量}
+                        result = Math.min(orderqty, canUseMoney / marginMoney)
+                    }
+                } else {
+                    // 买方履约保证金比例*挂牌价格
+                    const marginMoney = marginMethod(buymarginalgorithm) ? (buymarginvalue * fixedprice) : (buymarginvalue + fixedprice)
+                    //  一口价 摘买 最大数量=min{挂牌数量,可用资金/(买方履约保证金比例*挂牌价格)
+                    result = Math.min(orderqty, canUseMoney / marginMoney)
+                }
+            } else {
+                if (isWR()) {
+                    if (formState.LadingBillId) {
+                        // 现货库存数量
+                        const warehouseNum = allWR.value.find((e) => e.ladingbillid === formState.LadingBillId)?.enableqty;
+                        // 仓单贸易 一口价/浮动价 摘卖 最大数量=min(现货库存可用数量,挂牌数量),现货库存数量为所选仓单数量
+                        if (warehouseNum) {
+                            result = Math.min(orderqty, warehouseNum)
+                        }
+                    }
+                } else {
+                    // 获取头寸
+                    const item = wrPostion.value.find(e => String(e.wrfactortypeid) === String(parantSelectedRow.wrfactortypeid))
+                    if (item) {
+                        result = item.enalbeqty
+                    }
+                }
+            }
+        }
+        return Math.floor(result)
+    }
+    //  摘牌金额
+    function getMoney() {
+        let result = 0
+        if (isFloat()) {
+            const goodsPrice = getGoodsPrice()
+            if (goodsPrice.value && goodsPrice.value !== '--') {   // 有实时行情价格
+                // 估算总价=挂牌基差+期货合约价;
+                const predictTotal = pricemove + (goodsPrice.value as number);
+                // 估算总额=估算总价*摘牌数量;
+                result = predictTotal * formState.num
+            }
+        } else {
+            // 摘牌金额=挂牌价格*摘牌数量
+            result = formState.num * orderqty
+        }
+        return Number(result.toFixed(2))
+    }
+    // 履约保证金
+    function getMargin() {
+        // fixed sell  履约保证金=卖方履约保证金比例*摘牌金额
+        // fixed bull  履约保证金=买方履约保证金比例*摘牌金额
+        // floor sell  履约保证金=卖方履约保证金比例*估算总额,履约保证金为0则括号内容不显示
+        //  floor  buy 履约保证金=买方履约保证金比例*估算总额
+        let result = 0
+        if (hasRule()) {
+            const { buymarginvalue, sellmarginvalue } = rules[0]
+            if (isBuy()) {
+                result = sellmarginvalue * getMoney()
+            } else {
+                result = buymarginvalue * getMoney()
+            }
+        }
+        return Number(result.toFixed(2))
+    }
+    return { getMaxNum, getMoney, getMargin }
 }

+ 24 - 19
src/views/market/spot_trade/components/buy-sell-market/index.vue

@@ -21,7 +21,7 @@
         <div class="arrowRightIcon"></div>
       </div>
       <div class="titleBtn titleBtn3"
-           v-if="!getHasWR(enumName)">
+           v-if="!isWR(enumName)">
         <div class="arrowLeftIcon"></div>
         <div class="name">
           <a-month-picker :allowClear="false"
@@ -33,7 +33,7 @@
       </div>
       <div class="green">
         <div class="numBlock"
-             v-if="isFloatPrice()">
+             v-if="isFloat()">
           <div class="first">卖基差</div>
           <div class="last">{{selectedRow.sellpricemove}}</div>
         </div>
@@ -49,7 +49,7 @@
       </div>
       <div class="red ml35">
         <div class="numBlock"
-             v-if="isFloatPrice()">
+             v-if="isFloat()">
           <div class="first">买基差</div>
           <div class="last">{{selectedRow.buypricemove}}</div>
         </div>
@@ -64,7 +64,7 @@
         </div>
       </div>
       <div class="market"
-           v-if="isFloatPrice()">
+           v-if="isFloat()">
         <div class="first">{{selectedRow.goodscode}}</div>
         <div class="last red">{{getGoodsPrice()}}</div>
         <LineChartOutlined />
@@ -107,12 +107,12 @@ import { defineAsyncComponent, defineComponent, BtnList, ModalEnum } from '@/com
 import { _closeModal } from '@/common/setup/modal/modal';
 import { WrOrderQuote } from '@/services/go/wrtrade/interface';
 import { LeftOutlined } from '@ant-design/icons-vue';
-import { handleChildComponentMethod, handleFinacing, getHasWR, handlePriceRule } from './setup';
+import { handleFinacing, handlePriceRule, handleIs, setGoodsPrice } from './setup';
 import Buy from './components/buy/index.vue';
 import Sell from './components/sell/index.vue';
 import { LineChartOutlined, DownOutlined } from '@ant-design/icons-vue';
 import { handleModalComponent } from '@/common/setup/asyncComponent';
-import { onMounted, PropType, ref } from 'vue';
+import { onMounted, PropType, ref, provide } from 'vue';
 import { handleSpotBtnList } from '../../setup';
 import { v4 } from 'uuid';
 import { addSubscribeQuotation, removeSubscribeQuotation } from '@/services/socket/quota';
@@ -122,7 +122,7 @@ import TimerUtils from '@/utils/timer/timerUtil';
 import { BtnList as BtnListType } from '@/common/components/btnList/interface';
 import moment, { Moment } from 'moment';
 import { getMarketByTradeMode } from '@/services/bus/market';
-import { TradeMode } from '@/common/constants/enumCommon';
+import { BuyOrSell, TradeMode } from '@/common/constants/enumCommon';
 
 export default defineComponent({
     emits: ['cancel', 'update'],
@@ -157,29 +157,34 @@ export default defineComponent({
             // 获取计算规则
             handlePriceRule(loading, marketInfo.marketid);
         }
-
+        const { isWR, isFloat } = handleIs(props.enumName, BuyOrSell.buy);
         // 买卖大厅 配置数据
         // 表格操作按钮列表
         const { firstBtn, buyMarket, sellMarket } = handleSpotBtnList(props.enumName);
-        /*** ====== 处理浮动价 =======******/
-        // 是否为浮动价
-        function isFloatPrice() {
-            return props.enumName === EnumRouterName.warehouse_receipt_trade_floating_price || props.enumName === EnumRouterName.warehouse_pre_sale_floating_price;
-        }
         // 获取浮动价商品实时价格
 
         function getGoodsPrice() {
             const goods = getGoodsByCode(props.selectedRow.goodscode);
+            let result: number | string = '--';
             if (goods) {
                 const n = Math.pow(10, goods.decimalplace);
                 const quoteData = getQuoteDayInfoByCode(props.selectedRow.goodscode);
-                return quoteData ? quoteData.ask / n : '--';
-            } else {
-                return '--';
+                // 期货合约取价顺序:现价->实时结算价->昨结算价
+                if (quoteData) {
+                    if (quoteData.last) {
+                        result = quoteData.last / n;
+                    } else if (quoteData.settle) {
+                        result = quoteData.settle / n;
+                    } else if (quoteData.presettle) {
+                        result = quoteData.presettle / n;
+                    }
+                }
             }
+            setGoodsPrice(result);
+            return typeof result === 'number' ? result.toFixed(goods?.decimalplace) : result;
         }
         const uuid = v4();
-        if (isFloatPrice()) {
+        if (isFloat()) {
             // 如果是浮动价需要行情订阅
             const arr = [{ exchangeCode: 250, goodsCode: props.selectedRow.goodscode, subState: 0 }];
             addSubscribeQuotation(uuid, arr);
@@ -228,7 +233,7 @@ export default defineComponent({
             buyRef,
             sellRef,
             cancel,
-            isFloatPrice,
+            isFloat,
             getGoodsPrice,
             visible,
             firstBtn,
@@ -239,7 +244,7 @@ export default defineComponent({
             openComponent,
             enumName: props.enumName,
             handleBtnList,
-            getHasWR,
+            isWR,
             timeChange,
         };
     },

+ 33 - 133
src/views/market/spot_trade/components/buy-sell-market/setup.ts

@@ -1,3 +1,4 @@
+import { BuyOrSell } from '@/common/constants/enumCommon';
 import { EnumRouterName } from '@/common/constants/enumRouterName';
 import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
 import { TableKey } from '@/common/methods/table/interface';
@@ -77,27 +78,34 @@ export function getSellMarketParam(enumName: EnumRouterName) {
     return { wrpricetype, haswr, tableKey }
 }
 
-// 是否有仓单
-export function getHasWR(enumName: EnumRouterName): 0 | 1 {
-    if (enumName === EnumRouterName.warehouse_receipt_trade_price || enumName === EnumRouterName.warehouse_receipt_trade_floating_price) {
-        return 1
-    } else {
-        return 0
+export function handleIs(enumName: EnumRouterName, buyOrSell: BuyOrSell) {
+    /**
+     *
+     * @returns 1 => 仓单贸易; 0 => 仓单预售
+     */
+    function isWR(): 0 | 1 {
+        if (enumName === EnumRouterName.warehouse_receipt_trade_price || enumName === EnumRouterName.warehouse_receipt_trade_floating_price) {
+            return 1
+        } else {
+            return 0
+        }
     }
-}
-
-// true: 固定价; false: 浮动价
-export function isFixed(enumName: EnumRouterName) {
-    return enumName === EnumRouterName.warehouse_receipt_trade_price || enumName === EnumRouterName.warehouse_pre_sale_price;
-}
-
-
-export function handleChildComponentMethod() {
-    const childRef = ref<null | { queryTableAction: Function }>(null);
-    function loadChildComponentData() {
-        childRef.value?.queryTableAction();
+    /**
+     *
+     * @returns true => 买; false =>卖
+     */
+    function isBuy() {
+        return buyOrSell === BuyOrSell.buy
+    }
+    /**
+     *
+     * @returns  true => 浮动价; false =>一口价
+     */
+    function isFloat() {
+        return enumName === EnumRouterName.warehouse_receipt_trade_floating_price ||
+            enumName === EnumRouterName.warehouse_pre_sale_floating_price
     }
-    return { childRef, loadChildComponentData }
+    return { isWR, isBuy, isFloat }
 }
 
 // 获取金额计算规则
@@ -130,119 +138,11 @@ export function getFinacingList(): WrFAProductDetail[] {
     return list.value
 }
 
-/**
- * 我负责计算摘牌页面需要显示的值
- * 这里分四种情况
- * 若履约保证金为0,则不显示括号内容
- * type 1: 一口价 摘牌买入 摘牌最大数量 = min 挂牌数量,可用资金/(买方履约保证金比例*挂牌价格)                                                                            摘牌金额=挂牌价格*摘牌数量
- * type 2: 一口价 摘牌卖出 摘牌最大数量 = min(现货库存可用数量,挂牌数量),现货库存数量为所选仓单数量 && 履约保证金=卖方履约保证金比例*摘牌金额,履约保证金为0则括号内容不显示       摘牌金额=挂牌价格*摘牌数量
- * type 3: 浮动价 摘牌买入 摘牌最大数量 = min {可用资金/(买方履约保证金比例*估算总价),挂牌数量} && 履约保证金=履约保证金比例*估算总额,履约保证金为0则括号内容不显示 && 估算总额=估算总价*摘牌数量 && 估算总价=挂牌基差+期货合约价 && 期货合约取价顺序:现价->实时结算价->昨结算价
- * type 4:浮动价 摘牌卖出 摘牌最大数量 = min(现货库存可用数量,挂牌数量),现货库存数量为所选仓单数量 && 履约保证金=履约保证金比例*估算总额
- *
- * type 1:  in => 输入 {
- *     挂牌价格, 可用资金, 摘牌数量,  市场交易参数配置, 挂牌数量
- * } out => {
- *     履约保证金, 摘牌金额, 摘牌最大数量
- * }
- *
- * type 2: in => 输入 {
- *     挂牌价格, 仓单数量, 摘牌数量,  市场交易参数配置, 挂牌数量
- * } out => {
- *     履约保证金, 摘牌金额, 摘牌最大数量
- * }
- *
- * type 3: in => 输入 {
- *     期货合约价 + 基差, 可用资金,  摘牌数量,  市场交易参数配置, 挂牌数量
- * } out => {
- *     履约保证金, 估算总额, 摘牌最大数量
- * }
- *
- * type 4: in => 输入 {
- *     期货合约价 + 基差, 仓单数量, 摘牌数量, 市场交易参数配置, 挂牌数量
- * } out => {
- *     履约保证金, 估算总额, 摘牌最大数量
- * }
- */
-export function ListedViewModel(enumType: EnumRouterName) {
-
-    let marginPrice = 0  // 履约保证金
-    let amount = 0 // 摘牌金额 或 估算总额
-    let maxNum = 0 // 摘牌最大数量
-
-    // 负责把输入的数据 转换成 ui需要显示的数据
-    function getCalculate(param: WrParam) {
-        const rule = rules.value;
-        if (rule.length) {
-            const obj = rule[0]
-            switch (enumType) {
-                case EnumRouterName.warehouse_receipt_trade_floating_price: //  浮动价 摘牌买入
-                case EnumRouterName.warehouse_receipt_trade_price:   //  一口价 摘牌买入
-                    if (param.availableFunds === undefined) { // 这里防止异常
-                        maxNum = 0
-                    } else {
-                        // 摘牌最大数量 = min 挂牌数量,可用资金/(买方履约保证金比例*挂牌价格)
-                        if (obj.buymarginalgorithm === 1) {  //  买方保证金模式 1: 比率 2: 固定
-                            maxNum = Math.min(param.listedNum, param.availableFunds / obj.buymarginvalue * param.orderPrice)
-                        } else {
-                            maxNum = Math.min(param.listedNum, param.availableFunds / (obj.buymarginvalue + param.orderPrice))
-                        }
-                    }
-                    // 摘牌金额 = 挂牌价格 * 摘牌数量
-                    amount = param.orderPrice * param.deListNum
-                    // 履约保证金=买方履约保证金比例*摘牌金额,履约保证金为0则括号内容不显示
-                    if (obj.buymarginalgorithm === 1) { //卖方保证金方式 - 1:比率 2:固定
-                        marginPrice = obj.buymarginvalue * amount
-                    } else {
-                        marginPrice = obj.buymarginvalue + amount
-                    }
-                    break
-                case EnumRouterName.warehouse_pre_sale_floating_price: // 浮动价 摘牌卖出
-                case EnumRouterName.warehouse_pre_sale_price:  // 一口价  摘牌卖出
-                    if (param.warehouseNum === undefined) { // 这里防止异常
-                        maxNum = 0
-                    } else {
-                        // 摘牌最大数量 = min(现货库存可用数量,挂牌数量),现货库存数量为所选仓单数量
-                        maxNum = Math.min(param.listedNum, param.warehouseNum)
-                    }
-                    // 摘牌金额 = 挂牌价格 * 摘牌数量
-                    amount = param.orderPrice * param.deListNum
-                    // 履约保证金=卖方履约保证金比例*摘牌金额,履约保证金为0则括号内容不显示
-                    if (obj.sellmarginalgorithm === 1) { //卖方保证金方式 - 1:比率 2:固定
-                        marginPrice = obj.sellmarginvalue * amount
-                    } else {
-                        marginPrice = obj.sellmarginvalue + amount
-                    }
-                    break
-            }
-        }
-
-    }
-
-    const uiParam: UiParam = {
-        marginPrice: marginPrice,
-        amount: amount,
-        maxNum: maxNum
-    }
-
-    return { getCalculate, uiParam }
-}
-
-/**
- * 需要传入的数据集合
- */
-export interface WrParam {
-    orderPrice: number  // 挂牌价格 (浮动价是期货合约价 + 基差)  也传这个 (会变)
-    availableFunds?: number //可用资金(当前账号的可用) 摘牌买入传可用 (可能会变)
-    warehouseNum?: number  // 仓单数量(如果当前是用自己仓单卖商品给其他人 则需要传自己仓单商品的总数) 摘牌卖出传选择的仓单数量 (可能会变)
-    deListNum: number     // 摘牌数量 (当前选择数量)  (会变)
-    listedNum: number     // 挂牌数量  (当前单据的挂牌数量) (不变)
+// 商品实时价格
+const goodsPrice = ref<string | number>('--')
+export function setGoodsPrice(value: string | number) {
+    goodsPrice.value = value
 }
-
-/**
- *  需要给ui的数据集合
- */
-export interface UiParam {
-    marginPrice: number  // 履约保证金
-    amount: number       // 摘牌金额 或 估算总额
-    maxNum: number       // 摘牌最大数量
+export function getGoodsPrice(): Ref<string | number> {
+    return goodsPrice
 }

+ 11 - 10
src/views/market/spot_trade/components/post_buying/index.vue

@@ -28,7 +28,7 @@
               </a-form-item>
             </a-col>
             <a-col :span="24"
-                   v-if="isFixed(enumName)">
+                   v-if="!isFloat()">
               <a-form-item label="挂牌价格"
                            name="FixedPrice">
                 <a-input-number class="commonInput"
@@ -58,7 +58,7 @@
               </a-form-item>
             </a-col>
             <a-col :span="24"
-                   v-if="!getHasWR(enumName)">
+                   v-if="!isWR()">
               <a-form-item label="交收月"
                            name="DeliveryMonth">
                 <a-month-picker style="width: 260px"
@@ -147,8 +147,8 @@ import { handleForm } from './setup';
 import { validateAction } from '@/common/setup/form';
 import { FormParam } from './interface';
 import { EnumRouterName } from '@/common/constants/enumRouterName';
-import { getHasWR } from '../buy-sell-market/setup';
-import { isFixed } from '../buy-sell-market/setup';
+import { handleIs } from '../buy-sell-market/setup';
+import { BuyOrSell } from '@/common/constants/enumCommon';
 
 export default defineComponent({
     emits: ['cancel', 'update'],
@@ -170,6 +170,7 @@ export default defineComponent({
     },
     setup(props, context) {
         const { visible, cancel } = _closeModal(context);
+        const { isWR, isFloat } = handleIs(props.enumName, BuyOrSell.buy);
         const loading = ref<boolean>(false);
         const accountList = getAccountTypeList([2]);
         const { rules, formState, formRef } = handleForm();
@@ -205,7 +206,7 @@ export default defineComponent({
                         // MatchUserIDs: 0, // 仓单贸易对手资金账号ID集合(指定对手时填写) uint32
                         OrderQty: res.OrderQty, // 委托数量(可挂部分数据量) ======
                         DeliveryGoodsID: props.selectedRow.deliverygoodsid, // 交割商品商品ID  // 有仓单求购
-                        WRPriceType: isFixed(props.enumName) ? 1 : 2, // 价格方式 1:固定价 2:浮动价
+                        WRPriceType: isFloat() ? 2 : 1, // 价格方式 1:固定价 2:浮动价
                         FixedPrice: res.FixedPrice, // 固定价格
                         PriceFactor: 1, // 价格系数(浮动价时填写)
                         PriceMove: res.PriceMove, // 升贴水(浮动价时填写)
@@ -223,11 +224,11 @@ export default defineComponent({
                         Attachment2: '', // 附件2
                         Remark: '', // 备注
                         ApplyID: 0, // 申请ID
-                        WRTradeGoods: isFixed(props.enumName) ? [] : [wrGoodsInfo],
+                        WRTradeGoods: isFloat() ? [wrGoodsInfo] : [],
                         CanPart: 1, // 是否允许部份摘牌0:不允许;1:允许
                         WRStandardID: props.selectedRow.wrstandardid,
-                        HasWr: getHasWR(props.enumName), // 无仓单挂牌  是否有无仓单
-                        DeliveryMonth: getHasWR(props.enumName) ? '' : moment(res.DeliveryMonth).format('YYYY-MM'),
+                        HasWr: isWR(), // 无仓单挂牌  是否有无仓单
+                        DeliveryMonth: isWR() ? '' : moment(res.DeliveryMonth).format('YYYY-MM'),
                     };
                     requestResultLoadingAndInfo(hdWROrder, param, loading, ['求购成功', '求购失败:']).then(() => {
                         cancel(true);
@@ -243,8 +244,8 @@ export default defineComponent({
             rules,
             formState,
             formRef,
-            isFixed,
-            getHasWR,
+            isFloat,
+            isWR,
         };
     },
 });