Sfoglia il codice sorgente

修改挂牌数量 验证

huangbin 4 anni fa
parent
commit
48bb4f0d10

+ 36 - 0
src/hooks/form/verify.ts

@@ -0,0 +1,36 @@
+import { RuleObject } from "ant-design-vue/lib/form/interface";
+
+// 验证 挂牌数量
+/**
+ *
+ * @param delistingQty 起摘数量
+ * @param 挂牌数量对应的key
+ * @param minivalue 最小单位
+ * @param maxValue 最大数量(可选)
+ * @returns
+ */
+export const useVerifyListingNum = <T extends object, k extends keyof T>(formState: T, key: k, minivalue: number, maxValue?: number) => {
+    const v_num = async (rule: RuleObject, value: number) => {
+        if (value) {
+            if (formState[key] && value < (formState[key] as unknown as number)) {
+                return Promise.reject(`挂牌数量不能小于起摘数量`)
+            }
+            if (value < minivalue) {
+                return Promise.reject(`挂牌数量不能小于${minivalue}`)
+            }
+            if (maxValue && value > maxValue) {
+                return Promise.reject(`挂牌数量不能大于${maxValue}`)
+            }
+            if (value % minivalue) {
+                return Promise.reject(`挂牌数量不是${minivalue}的倍数`)
+            }
+
+            return Promise.resolve();
+
+        } else {
+            return Promise.reject('请输入挂牌数量')
+        }
+    };
+    return { v_num }
+}
+

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

@@ -406,6 +406,7 @@ export interface WrHoldLB {
     wrstandardid: number;//现货商品ID
     wrstandardname: string;//商品名称
     wrtypename: string;//商品
+    minivalue: number;
 }
 
 /**

+ 136 - 84
src/views/market/spot_trade/components/post_buying/index.vue

@@ -1,70 +1,116 @@
 <template>
-    <!-- 挂牌求购 -->
-    <Drawer :title="'挂牌求购'" :placement="'right'" :visible="visible" @cancel="cancel" class="top">
-        <div class="post_buying">
-            <a-form class="inlineForm dialogForm" ref="formRef" :model="formState" :rules="rules">
-                <div class="formBar">
-                    <a-row :gutter="24">
-                        <a-col :span="24">
-                            <a-form-item label="交易账户" name="accountid">
-                                <a-select class="inlineFormSelect" style="width: 260px" v-model:value="formState.accountid" placeholder="请选择">
-                                    <a-select-option v-for="item in accountList" :value="item.accountid" :key="item.accountid">{{ item.accountid }}</a-select-option>
-                                </a-select>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" v-if="!isFloat()">
-                            <a-form-item label="挂牌价格" name="FixedPrice">
-                                <a-input-number class="commonInput" style="width: 260px" :min="0" v-model:value="formState.FixedPrice" />
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" v-else>
-                            <a-form-item label="基差" name="PriceMove">
-                                <a-input-number class="commonInput" style="width: 260px" v-model:value="formState.PriceMove" />
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" v-if="isFloat()">
-                            <a-form-item label="估算价" name="PriceMove">
-                                <span class="white">{{ getPrice() }}</span>
-                            </a-form-item>
-                        </a-col>
+  <!-- 挂牌求购 -->
+  <Drawer :title="'挂牌求购'"
+          :placement="'right'"
+          :visible="visible"
+          @cancel="cancel"
+          class="top">
+    <div class="post_buying">
+      <a-form class="inlineForm dialogForm"
+              ref="formRef"
+              :model="formState"
+              :rules="rules">
+        <div class="formBar">
+          <a-row :gutter="24">
+            <a-col :span="24">
+              <a-form-item label="交易账户"
+                           name="accountid">
+                <a-select class="inlineFormSelect"
+                          style="width: 260px"
+                          v-model:value="formState.accountid"
+                          placeholder="请选择">
+                  <a-select-option v-for="item in accountList"
+                                   :value="item.accountid"
+                                   :key="item.accountid">{{ item.accountid }}</a-select-option>
+                </a-select>
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   v-if="!isFloat()">
+              <a-form-item label="挂牌价格"
+                           name="FixedPrice">
+                <a-input-number class="commonInput"
+                                style="width: 260px"
+                                :min="0"
+                                v-model:value="formState.FixedPrice" />
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   v-else>
+              <a-form-item label="基差"
+                           name="PriceMove">
+                <a-input-number class="commonInput"
+                                style="width: 260px"
+                                v-model:value="formState.PriceMove" />
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   v-if="isFloat()">
+              <a-form-item label="估算价"
+                           name="PriceMove">
+                <span class="white">{{ getPrice() }}</span>
+              </a-form-item>
+            </a-col>
 
-                        <a-col :span="24">
-                            <a-form-item label="挂牌数量" name="OrderQty">
-                                <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>
-                        </a-col>
-                        <a-col :span="24" v-if="!isWR()">
-                            <a-form-item label="交收月" name="DeliveryMonth">
-                                <a-month-picker style="width: 260px" v-model:value="formState.DeliveryMonth" :allowClear="false" class="commonDatePicker dialogDatePicker" />
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" class="mt-10">
-                            <a-form-item>
-                                <a-slider :min="0" v-model:value="formState.OrderQty" :max="getMaxNum()" class="formSlider" />
-                                <div class="unit">
-                                    <span>{{ getMaxNum() ? selectedRow.minivalue : 0 }}</span>
-                                    <span>{{ getMaxNum() }}{{ selectedRow.enumdicname }}</span>
-                                </div>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24">
-                            <a-form-item label="起摘数量" class="relative">
-                                <a-input class="commonInput" :suffix="selectedRow.enumdicname" :min="selectedRow.minivalue" style="width: 260px !important" />
-                                <div class="tip">最小单位:{{ selectedRow.minivalue }}{{ selectedRow.enumdicname }}</div>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" class="relative mt20">
-                            <a-form-item :label="isFloat() ? '估算金额' : '挂牌金额'">
-                                <span class="white ml8">{{ getMoney() }}</span>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24" v-if="getMargin()">
-                            <a-form-item :label="getMargin() ? '履约保证金' : ''">
-                                <!-- <a-row>
+            <a-col :span="24">
+              <a-form-item label="挂牌数量"
+                           name="OrderQty">
+                <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>
+            </a-col>
+            <a-col :span="24"
+                   v-if="!isWR()">
+              <a-form-item label="交收月"
+                           name="DeliveryMonth">
+                <a-month-picker style="width: 260px"
+                                v-model:value="formState.DeliveryMonth"
+                                :allowClear="false"
+                                class="commonDatePicker dialogDatePicker" />
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   class="mt-10">
+              <a-form-item>
+                <a-slider :min="0"
+                          v-model:value="formState.OrderQty"
+                          :max="getMaxNum()"
+                          class="formSlider" />
+                <div class="unit">
+                  <span>{{ getMaxNum() ? selectedRow.minivalue : 0 }}</span>
+                  <span>{{ getMaxNum() }}{{ selectedRow.enumdicname }}</span>
+                </div>
+              </a-form-item>
+            </a-col>
+            <a-col :span="24">
+              <a-form-item label="起摘数量"
+                           name="DelistMinQty"
+                           class="relative">
+                <a-input-number class="commonInput"
+                                :suffix="selectedRow.enumdicname"
+                                v-model:value="formState.DelistMinQty"
+                                :min="0"
+                                style="width: 260px !important" />
+                <div class="tip">最小单位:{{ selectedRow.minivalue }}{{ selectedRow.enumdicname }}</div>
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   class="relative mt20">
+              <a-form-item :label="isFloat() ? '估算金额' : '挂牌金额'">
+                <span class="white ml8">{{ getMoney() }}</span>
+              </a-form-item>
+            </a-col>
+            <a-col :span="24"
+                   v-if="getMargin()">
+              <a-form-item :label="getMargin() ? '履约保证金' : ''">
+                <!-- <a-row>
                                 <a-col :span="8">-->
-                                <span class="white ml8">{{ getMargin() }}</span>
-                                <!-- </a-col>
+                <span class="white ml8">{{ getMargin() }}</span>
+                <!-- </a-col>
                                     <a-col :span="4" class="tr">
                                         <span class="grey1">可用资金</span>
                                     </a-col>
@@ -74,26 +120,31 @@
                                         >{{getCanUseMoney(getSelectedAccount())}}</span>
                                     </a-col>
                                 </a-row>-->
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="24">
-                            <a-form-item label="可用资金">
-                                <span class="white ml8">{{ getCanUseMoney(getSelectedAccount()) }}</span>
-                            </a-form-item>
-                        </a-col>
-                    </a-row>
-                </div>
-                <a-row :gutter="24">
-                    <a-col :span="24" class="fixedBtns">
-                        <a-form-item class="btnCenter">
-                            <a-button class="listedBtn" @click="submit" :loading="loading">买入</a-button>
-                            <a-button class="ml10 cancelBtn" @click="cancel" :disabled="loading">取消</a-button>
-                        </a-form-item>
-                    </a-col>
-                </a-row>
-            </a-form>
+              </a-form-item>
+            </a-col>
+            <a-col :span="24">
+              <a-form-item label="可用资金">
+                <span class="white ml8">{{ getCanUseMoney(getSelectedAccount()) }}</span>
+              </a-form-item>
+            </a-col>
+          </a-row>
         </div>
-    </Drawer>
+        <a-row :gutter="24">
+          <a-col :span="24"
+                 class="fixedBtns">
+            <a-form-item class="btnCenter">
+              <a-button class="listedBtn"
+                        @click="submit"
+                        :loading="loading">买入</a-button>
+              <a-button class="ml10 cancelBtn"
+                        @click="cancel"
+                        :disabled="loading">取消</a-button>
+            </a-form-item>
+          </a-col>
+        </a-row>
+      </a-form>
+    </div>
+  </Drawer>
 </template>
 
 <script lang="ts">
@@ -140,7 +191,7 @@ 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 { rules, formState, formRef } = handleForm(props.selectedRow);
         const loading = ref<boolean>(false);
         const accountList = getAccountTypeList([2]);
         if (accountList.length) {
@@ -205,6 +256,7 @@ export default defineComponent({
                         CanPart: 1, // 是否允许部份摘牌0:不允许;1:允许
                         WRStandardID: props.selectedRow.wrstandardid,
                         HasWr: isWR(), // 无仓单挂牌  是否有无仓单
+                        DelistMinQty: res.DelistMinQty, // 起摘数量
                         DeliveryMonth: isWR() ? '' : moment(res.DeliveryMonth).format('YYYY-MM'),
                         FactoryItems:
                             props.selectedRow.wrResult != undefined

+ 1 - 0
src/views/market/spot_trade/components/post_buying/interface.ts

@@ -7,6 +7,7 @@ export interface FormParam {
     OrderQty: number,
     PriceMove: number,
     DeliveryMonth: Moment,
+    DelistMinQty: number,
 }
 
 

+ 21 - 11
src/views/market/spot_trade/components/post_buying/setup.ts

@@ -1,29 +1,39 @@
 import { BuyOrSell } from "@/common/constants/enumCommon";
 import { EnumRouterName } from "@/common/constants/enumRouterName";
+import { useVerifyListingNum } from '@/hooks/form/verify';
 import { getAccountTypeList, getCanUseMoney } from "@/services/bus/account";
 import { getRules } from '@/services/bus/rules';
 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 { onBeforeUnmount, reactive, ref, UnwrapRef } from "vue";
 import { getGoodsPrice, handleIs } from "../buy-sell-market/setup";
-import { FormParam } from "./interface";
+import { FormParam, TempWrOrderQuoteDetail } from "./interface";
 
-const formState: UnwrapRef<FormParam> = reactive({
-    accountid: undefined,
-    FixedPrice: 0,
-    OrderQty: 0,
-    PriceMove: 0,
-    DeliveryMonth: moment()
-})
-export function handleForm() {
+function initFormData(): FormParam {
+    return {
+        accountid: undefined,
+        FixedPrice: 0,
+        OrderQty: 0,
+        PriceMove: 0,
+        DelistMinQty: 0,
+        DeliveryMonth: moment()
+    }
+}
+const formState: UnwrapRef<FormParam> = reactive(initFormData())
+export function handleForm(selectedRow: TempWrOrderQuoteDetail) {
     const formRef = ref();
+    formState.OrderQty = selectedRow.minivalue
+    const { v_num } = useVerifyListingNum<FormParam, 'DelistMinQty'>(formState, 'DelistMinQty', selectedRow.minivalue)
     const rules = {
         FixedPrice: [{ required: true, message: '请输入挂牌价格', trigger: 'blur', type: 'number', }],
-        OrderQty: [{ required: true, message: '请输入挂牌数量', trigger: 'blur', type: 'number', min: 1 }],
+        OrderQty: [{ required: true, validator: v_num, trigger: 'change', type: 'number' }],
         PriceMove: [{ required: true, message: '请输入基差', trigger: 'blur', type: 'number' }],
         accountid: [{ required: true, message: '请输入交易账号' }],
     }
+    onBeforeUnmount(() => {
+        Object.assign(formState, initFormData(), { OrderQty: selectedRow.minivalue })
+    })
     return { rules, formState, formRef }
 }
 

+ 6 - 11
src/views/order/pre_sale_warehouse_receipt/components/pre_sale_warehouse_receipt_order_summary/components/listed/setup.ts

@@ -1,6 +1,7 @@
 import { TradeMode } from '@/common/constants/enumCommon';
 import { validateCommon } from '@/common/setup/validate';
 import { handleForm as useForm } from '@/common/setup/warehouse_receipt_trade/listing';
+import { useVerifyListingNum } from '@/hooks/form/verify';
 import { getGoodsGroupsByTradeMode, getIPOGoodsList, getQuoteDayInfoByCodeFindPrice } from '@/services/bus/goods';
 import { getRules } from '@/services/bus/rules';
 import { Goods } from "@/services/go/ermcp/goodsInfo/interface";
@@ -32,6 +33,8 @@ function initFormData(): ListingForm {
 
 const formState: UnwrapRef<ListingForm> = reactive(initFormData())
 export function handleForm(data: WrPosition) {
+    const { minivalue, creditenableqty } = data
+    formState.OrderQty = data.minivalue
     const { rules, formRef } = useForm();
 
     const v_group = async (rule: RuleObject, value: number) => {
@@ -41,17 +44,9 @@ export function handleForm(data: WrPosition) {
             return Promise.reject('请选择商品')
         }
     };
-    const v_num = async (rule: RuleObject, value: number) => {
-        if (value) {
-            if (value > data.creditenableqty || value < 1) {
-                return Promise.reject('提示挂牌数量有误')
-            } else {
-                return Promise.resolve();
-            }
-        } else {
-            return Promise.reject('请输入挂牌数量')
-        }
-    };
+
+    const { v_num } = useVerifyListingNum<ListingForm, 'DelistMinQty'>(formState, 'DelistMinQty', minivalue, creditenableqty)
+
     const rule = {
         FixedPrice: [{ required: true, message: '请输入挂牌价格', trigger: 'blur', type: 'number', min: 1, }],
         OrderQty: [{ required: true, validator: v_num, trigger: 'blur', type: 'number' }],

+ 5 - 12
src/views/order/spot_warran/components/spot_warrant_spot_details/components/listing/setup.ts

@@ -1,6 +1,7 @@
 import { TradeMode } from '@/common/constants/enumCommon';
 import { validateCommon } from '@/common/setup/validate';
 import { handleForm as useForm } from '@/common/setup/warehouse_receipt_trade/listing';
+import { useVerifyListingNum } from '@/hooks/form/verify';
 import { getGoodsGroupsByTradeMode, getIPOGoodsList, getQuoteDayInfoByCodeFindPrice } from '@/services/bus/goods';
 import { getRules } from '@/services/bus/rules';
 import { Goods } from "@/services/go/ermcp/goodsInfo/interface";
@@ -33,6 +34,8 @@ function initFormData(): ListingForm {
 const formState: UnwrapRef<ListingForm> = reactive(initFormData())
 
 export function handleForm(data: WrHoldLB) {
+    const { minivalue, enableqty } = data
+    formState.OrderQty = data.minivalue
     const { rules, formRef } = useForm();
 
     const v_group = async (rule: RuleObject, value: number) => {
@@ -42,17 +45,7 @@ export function handleForm(data: WrHoldLB) {
             return Promise.reject('请选择商品')
         }
     };
-    const v_num = async (rule: RuleObject, value: number) => {
-        if (value) {
-            if (value > data.enableqty || value < 1) {
-                return Promise.reject('提示挂牌数量有误')
-            } else {
-                return Promise.resolve();
-            }
-        } else {
-            return Promise.reject('请输入挂牌数量')
-        }
-    };
+    const { v_num } = useVerifyListingNum<ListingForm, 'DelistMinQty'>(formState, 'DelistMinQty', minivalue, enableqty)
 
     const rule = {
         FixedPrice: [{ required: true, message: '请输入挂牌价格', trigger: 'blur', type: 'number', min: 1, }],
@@ -63,7 +56,7 @@ export function handleForm(data: WrHoldLB) {
     }
     Object.assign(rules, rule)
     onBeforeUnmount(() => {
-        Object.assign(formState, initFormData())
+        Object.assign(formState, initFormData(), { OrderQty: data.minivalue })
     })
     return { rules, formState, formRef }
 }

+ 31 - 38
src/views/order/spot_warran/components/spot_warrant_spot_details/index.vue

@@ -1,49 +1,42 @@
 <template>
-    <!-- 现货明细 -->
-    <section>
-        <a-table
-            :columns="columns"
-            class="srcollYTable expandLeftTable"
-            :scroll="{ x: '100%', y: '190px' }"
-            :pagination="false"
-            :loading="loading"
-            :expandedRowKeys="expandedRowKeys"
-            :customRow="Rowclick"
-            :expandIcon="expandIcon"
-            :expandIconAsCell="false"
-            rowKey="key"
-            :data-source="tableList"
-        >
-            <!-- 额外的展开行 -->
-            <template #expandedRowRender="{ record }">
-                <BtnList
-                    :btnList="btnList"
-                    :record="record"
-                    class="btn-list-sticky"
-                    @click="openComponent"
-                    v-if="record.enableqty > 0"
-                />
-            </template>
-        </a-table>
-        <component
-            :is="componentId"
-            v-if="componentId"
-            :selectedRow="selectedRow"
-            @cancel="closeComponent"
-        ></component>
-    </section>
+  <!-- 现货明细 -->
+  <section>
+    <a-table :columns="columns"
+             class="srcollYTable expandLeftTable"
+             :scroll="{ x: '100%', y: '190px' }"
+             :pagination="false"
+             :loading="loading"
+             :expandedRowKeys="expandedRowKeys"
+             :customRow="Rowclick"
+             :expandIcon="expandIcon"
+             :expandIconAsCell="false"
+             rowKey="key"
+             :data-source="tableList">
+      <!-- 额外的展开行 -->
+      <template #expandedRowRender="{ record }">
+        <BtnList :btnList="btnList"
+                 :record="record"
+                 class="btn-list-sticky"
+                 @click="openComponent"
+                 v-if="record.enableqty > 0" />
+      </template>
+    </a-table>
+    <component :is="componentId"
+               v-if="componentId"
+               :selectedRow="selectedRow"
+               @cancel="closeComponent"></component>
+  </section>
 </template>
 
 <script lang="ts">
 import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
-import { EnumRouterName } from '@/common/constants/enumRouterName';
-import { queryTableList, BtnList, contextMenu, defineAsyncComponent, defineComponent, ModalEnum, ComposeTableParam, handleComposeTable } from '@/common/export/commonTable';
-import { queryHoldLB, queryWrOrderDetail, queryWrPosition } from '@/services/go/wrtrade';
-import { QueryHoldLBReq, QueryWrOrderDetailReq, QueryWrPositionReq, WrHoldLB, WrOrderDetail, WrPosition } from '@/services/go/wrtrade/interface';
+import { BtnList, defineAsyncComponent, defineComponent, ModalEnum, queryTableList } from '@/common/export/commonTable';
 import { getRecordItemTab } from '@/common/setup/order/orderData';
+import { expandIcon } from '@/common/setup/table/clolumn';
 import { handleComposeOrderTable } from '@/common/setup/table/compose';
 import { ComposeOrderTableParam } from '@/common/setup/table/interface';
-import { expandIcon } from '@/common/setup/table/clolumn';
+import { queryHoldLB } from '@/services/go/wrtrade';
+import { WrHoldLB } from '@/services/go/wrtrade/interface';
 export default defineComponent({
     name: enumOrderComponents.spot_warrant_spot_details,
     components: {