huangbin há 4 anos atrás
pai
commit
e5f10d6bf8

+ 1 - 0
src/services/go/wrtrade/interface.ts

@@ -41,6 +41,7 @@ export interface WrOrderQuote {
     wrstandardid: number;//商品id
     wrstandardname: string;//商品名称
     deliverymonth: string;//交收月
+    minivalue: number;
 }
 
 /**

+ 45 - 25
src/views/market/spot_trade/components/post_buying/index.vue

@@ -53,6 +53,7 @@
                 <a-input-number class="commonInput"
                                 style="width: 260px"
                                 :min="0"
+                                :max="getMaxNum()"
                                 v-model:value="formState.OrderQty" />
                 <span class="input-enumdicname">{{selectedRow.enumdicname}}</span>
               </a-form-item>
@@ -75,8 +76,8 @@
                           :max="99999999"
                           class="formSlider" />
                 <div class="unit">
-                  <span>0</span>
-                  <span>99999999{{selectedRow.enumdicname}}</span>
+                  <span>{{selectedRow.minivalue}}</span>
+                  <span>{{getMaxNum()}}{{selectedRow.enumdicname}}</span>
                 </div>
               </a-form-item>
             </a-col>
@@ -85,28 +86,35 @@
                            class="relative">
                 <a-input class="commonInput"
                          :suffix="selectedRow.enumdicname"
+                         :min="selectedRow.minivalue"
                          style="width: 260px" />
-                <div class="tip">最小单位:1{{selectedRow.enumdicname}}</div>
+                <div class="tip">最小单位:{{selectedRow.minivalue}}{{selectedRow.enumdicname}}</div>
               </a-form-item>
             </a-col>
-            <!-- <a-col :span="24">
-              <a-form-item label="挂牌金额"
-                           class="relative">
-                <a-input class="commonInput"
-                         :suffix="selectedRow.enumdicname"
-                         style="width: 260px" />
-                <div class="tip">最小单位:1{{selectedRow.enumdicname}}</div>
+            <a-col :span="24"
+                   class="relative">
+              <a-form-item :label="isFloat() ? '估算金额' : '摘牌金额'">
+                <span class="white ml8">{{getMoney()}}</span>
               </a-form-item>
             </a-col>
-            <a-col :span="24">
-              <a-form-item label="履约保证金"
-                           class="relative">
-                <a-input class="commonInput"
-                         :suffix="selectedRow.enumdicname"
-                         style="width: 260px" />
-                <div class="tip">最小单位:1{{selectedRow.enumdicname}}</div>
+            <a-col :span="24"
+                   class="relative">
+              <a-form-item :label="getMargin() ? '履约保证金' : ''">
+                <a-row>
+                  <a-col :span="8"
+                         v-if="getMargin()">
+                    <span class="white ml8">{{getMargin()}}</span>
+                  </a-col>
+                  <a-col :span="4"
+                         class="tr">
+                    <span class="grey1">可用资金</span>
+                  </a-col>
+                  <a-col :span="12">
+                    <span class="white ml8"> {{getCanUseMoney(getSelectedAccount())}}</span>
+                  </a-col>
+                </a-row>
               </a-form-item>
-            </a-col> -->
+            </a-col>
           </a-row>
           <a-row :gutter="24"
                  type="flex"
@@ -130,26 +138,25 @@
 <script lang="ts">
 import { defineComponent, PropType, ref } from 'vue';
 import { Des } from '@/common/components/commonDes';
-import { QhjAgreementConfig } from '@/services/go/ermcp/qhj/interface';
 import { _closeModal } from '@/common/setup/modal/modal';
 import { ModalEnum } from '@/common/constants/modalNameEnum';
 import Drawer from '@/common/components/drawer/index.vue';
 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
-import { hdWROrder, wRListingCancelOrder } from '@/services/proto/warehousetrade';
+import { hdWROrder } from '@/services/proto/warehousetrade';
 import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
-import { HdWROrderReq, WRGoodsInfo } from '@/services/proto/warehousetrade/interface';
-import { getAccountTypeList, getInTaAccount, getUserId } from '@/services/bus/account';
+import { WRGoodsInfo } from '@/services/proto/warehousetrade/interface';
+import { getAccountTypeList, getUserId } from '@/services/bus/account';
 import { v4 as uuidv4 } from 'uuid';
 import moment, { Moment } from 'moment';
 import { getMarketRunByTradeMode } from '@/services/bus/market';
 import { WrOrderQuote } from '@/services/go/wrtrade/interface';
-import { handleForm } from './setup';
+import { handleForm, handleNumAndPrice } from './setup';
 import { validateAction } from '@/common/setup/form';
 import { FormParam } from './interface';
 import { EnumRouterName } from '@/common/constants/enumRouterName';
 import { handleIs } from '../buy-sell-market/setup';
 import { BuyOrSell } from '@/common/constants/enumCommon';
-
+import { getCanUseMoney } from '@/services/bus/account';
 export default defineComponent({
     emits: ['cancel', 'update'],
     name: ModalEnum.spot_trade_warehouse_post_buying,
@@ -171,10 +178,18 @@ export default defineComponent({
     setup(props, context) {
         const { visible, cancel } = _closeModal(context);
         const { isWR, isFloat } = handleIs(props.enumName, BuyOrSell.buy);
+        const { rules, formState, formRef } = handleForm();
         const loading = ref<boolean>(false);
         const accountList = getAccountTypeList([2]);
-        const { rules, formState, formRef } = handleForm();
+        if (accountList.length) {
+            formState.accountid = accountList[0].accountid;
+        }
+        function getSelectedAccount() {
+            return accountList.find((e) => e.accountid === formState.accountid);
+        }
         formState.DeliveryMonth = props.time;
+
+        const { getMaxNum, getMoney, getMargin } = handleNumAndPrice(props.enumName, props.selectedRow);
         function submit() {
             const marketInfo = getMarketRunByTradeMode(17);
             if (marketInfo) {
@@ -246,6 +261,11 @@ export default defineComponent({
             formRef,
             isFloat,
             isWR,
+            getMaxNum,
+            getMoney,
+            getMargin,
+            getSelectedAccount,
+            getCanUseMoney,
         };
     },
 });

+ 57 - 7
src/views/market/spot_trade/components/post_buying/setup.ts

@@ -1,16 +1,22 @@
+import { BuyOrSell } from "@/common/constants/enumCommon";
+import { EnumRouterName } from "@/common/constants/enumRouterName";
+import { getAccountTypeList, getCanUseMoney } from "@/services/bus/account";
+import { AccountListItem } from "@/services/dataCenter/interafce/account";
+import { WrOrderQuote } from "@/services/go/wrtrade/interface";
 import moment from "moment";
 import { reactive, ref, UnwrapRef } from "vue";
+import { getGoodsPrice, getRules, handleIs } from "../buy-sell-market/setup";
 import { FormParam } from "./interface";
 
+const formState: UnwrapRef<FormParam> = reactive({
+    accountid: undefined,
+    FixedPrice: 0,
+    OrderQty: 0,
+    PriceMove: 0,
+    DeliveryMonth: moment()
+})
 export function handleForm() {
     const formRef = ref();
-    const formState: UnwrapRef<FormParam> = reactive({
-        accountid: undefined,
-        FixedPrice: 0,
-        OrderQty: 0,
-        PriceMove: 0,
-        DeliveryMonth: moment()
-    })
     const rules = {
         FixedPrice: [{ required: true, message: '请输入挂牌价格', trigger: 'blur', type: 'number', }],
         OrderQty: [{ required: true, message: '请输入挂牌数量', trigger: 'blur', type: 'number', min: 1 }],
@@ -19,3 +25,47 @@ export function handleForm() {
     }
     return { rules, formState, formRef }
 }
+
+
+export function handleNumAndPrice(enumName: EnumRouterName, selectedRow: WrOrderQuote) {
+    const { isFloat } = handleIs(enumName, BuyOrSell.buy)
+    // 资金账号
+    const accountList = getAccountTypeList([2]);
+    // 获取选中的资金账号
+    const getSelectedAccount = () => accountList.find((e) => e.accountid === formState.accountid);
+    // 交易规则
+    const rules = getRules().value
+    // 挂牌最大数量
+    function getMaxNum() {
+        // 可用资金
+        const canUseMoney = Number(getCanUseMoney(getSelectedAccount() as AccountListItem))
+        // 挂牌最大数量=可用资金/(买方履约保证金比例*挂牌价格)
+        const margin = getMargin()
+        return margin ? Math.floor(canUseMoney / getMargin()) : selectedRow.minivalue
+    }
+    //  摘牌金额
+    function getMoney() {
+        let result = 0
+        if (isFloat()) {
+            const goodsPrice = getGoodsPrice()
+            if (goodsPrice.value && goodsPrice.value !== '--') {   // 有实时行情价格
+                // 估算总价=挂牌基差+期货合约价;
+                const predictTotal = formState.PriceMove + (goodsPrice.value as number);
+                // 估算总额=估算总价*摘牌数量;
+                result = predictTotal * formState.OrderQty
+            }
+        } else {
+            // 摘牌金额=挂牌价格*摘牌数量
+            result = formState.OrderQty * formState.FixedPrice
+        }
+        return Number(result.toFixed(2))
+    }
+    // 履约保证金
+    function getMargin() {
+        const { buymarginvalue } = rules[0]
+        // 浮动价 履约保证金=估算总额*买方履约保证金比例
+        // 一口价 履约保证金=挂牌金额*买方履约保证金比例
+        return Number((getMoney() * buymarginvalue).toFixed(2))
+    }
+    return { getMaxNum, getMoney, getMargin }
+}