huangbin 4 yıl önce
ebeveyn
işleme
b7d9d34185

+ 217 - 168
src/views/order/pre_sale_warehouse_receipt/components/pre_sale_warehouse_receipt_order_summary/components/listed/index.vue

@@ -1,189 +1,211 @@
 <template>
-    <!-- 预售仓单 现货明细 挂牌 -->
-    <Drawer :title="'挂牌'" :placement="'right'" class="delistingBottom" :visible="visible" @cancel="cancel">
-        <div class="listed">
-            <div class="condition">
-                <a-button class="conditionBtn">{{selectedRow.deliverygoodsname}}</a-button>
-                <a-button class="conditionBtn">{{selectedRow.wrtypename}}</a-button>
-                <a-button class="conditionBtn">{{selectedRow.warehousename}}</a-button>
-            </div>
-            <div class="formBar">
-                <a-form
-                    class="inlineForm dialogForm"
-                    ref="formRef"
-                    :model="formState"
-                    :rules="rules"
-                >
-                    <a-row :gutter="24">
-                        <a-col :span="12">
-                            <a-form-item label="挂牌方式" name="WRPriceType">
-                                <a-select
-                                    class="inlineFormSelect"
-                                    default-value="1"
-                                    v-model:value="formState.WRPriceType"
-                                    style="width: 140px"
-                                >
-                                    <a-select-option :value="1">一口价</a-select-option>
-                                    <a-select-option :value="2">浮动价</a-select-option>
-                                </a-select>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="12" v-if="formState.WRPriceType === 1">
-                            <a-form-item label="挂牌价" name="FixedPrice">
-                                <a-input-number
-                                    class="dialogInput"
-                                    style="width: 140px"
-                                    :min="0"
-                                    v-model:value="formState.FixedPrice"
-                                    placeholder="请输入挂牌价"
-                                />
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="12" v-if="formState.WRPriceType === 2">
-                            <a-form-item label="基差" name="PriceMove">
-                                <a-input-number
-                                    class="commonInput"
-                                    v-model:value="formState.PriceMove"
-                                    style="width: 140px"
-                                />
-                            </a-form-item>
-                        </a-col>
-                    </a-row>
-                    <a-row :gutter="24">
-                        <a-col :span="12">
-                            <a-form-item label="挂牌数量" name="OrderQty">
-                                <a-input-number
-                                    class="dialogInput"
-                                    style="width: 140px"
-                                    :min="0"
-                                    v-model:value="formState.OrderQty"
-                                    placeholder="请输入挂牌数量"
-                                />
-                                <span class="input-enumdicname">{{selectedRow.enumdicname}}</span>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="12">
-                            <a-form-item label="起摘数量" class="relative" name="DelistMinQty">
-                                <a-input-number
-                                    class="commonInput"
-                                    :min="0"
-                                    v-model:value="formState.DelistMinQty"
-                                    style="width: 140px"
-                                />
-                                <span class="input-enumdicname">{{selectedRow.enumdicname}}</span>
-                                <div class="tip">最小单位:1{{selectedRow.enumdicname}}</div>
-                            </a-form-item>
-                        </a-col>
-                    </a-row>
-                    <a-row :gutter="24">
-                        <a-col :span="12" class="mt-20">
-                            <a-form-item>
-                                <a-slider
-                                    v-model:value="formState.OrderQty"
-                                    ::min="0"
-                                    :max="selectedRow.creditenableqty"
-                                    class="formSlider"
-                                />
-                                <div class="unit">
-                                    <span>0</span>
-                                    <span>{{selectedRow.creditenableqty}}{{selectedRow.enumdicname}}</span>
-                                </div>
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="12">&nbsp;</a-col>
-                    </a-row>
-                    <a-row :gutter="24">
-                        <a-col :span="12">
-                            <a-form-item label="交收月" name="DeliveryMonth">
-                                <a-month-picker
-                                    style="width: 140px"
-                                    v-model:value="formState.DeliveryMonth"
-                                    :allowClear="false"
-                                    class="commonDatePicker dialogDatePicker"
-                                />
-                            </a-form-item>
-                        </a-col>
-                        <a-col :span="12">
-                            <a-form-item>&nbsp;</a-form-item>
-                        </a-col>
-                    </a-row>
+  <!-- 预售仓单 现货明细 挂牌 -->
+  <Drawer :title="'挂牌'"
+          :placement="'right'"
+          class="delistingBottom"
+          :visible="visible"
+          @cancel="cancel">
+    <div class="listed">
+      <div class="condition">
+        <a-button class="conditionBtn">{{selectedRow.deliverygoodsname}}</a-button>
+        <a-button class="conditionBtn">{{selectedRow.wrtypename}}</a-button>
+        <a-button class="conditionBtn">{{selectedRow.warehousename}}</a-button>
+      </div>
+      <div class="formBar">
+        <a-form class="inlineForm dialogForm"
+                ref="formRef"
+                :model="formState"
+                :rules="rules">
+          <a-row :gutter="24">
+            <a-col :span="12">
+              <a-form-item label="挂牌方式"
+                           name="WRPriceType">
+                <a-select class="inlineFormSelect"
+                          default-value="1"
+                          v-model:value="formState.WRPriceType"
+                          style="width: 140px">
+                  <a-select-option :value="1">一口价</a-select-option>
+                  <a-select-option :value="2">浮动价</a-select-option>
+                </a-select>
+              </a-form-item>
+            </a-col>
+            <a-col :span="12"
+                   v-if="!isFloat()">
+              <a-form-item label="挂牌价"
+                           name="FixedPrice">
+                <a-input-number class="dialogInput"
+                                style="width: 140px"
+                                :min="0"
+                                v-model:value="formState.FixedPrice"
+                                placeholder="请输入挂牌价" />
+              </a-form-item>
+            </a-col>
+            <a-col :span="12"
+                   v-if="isFloat()">
+              <a-form-item label="基差"
+                           name="PriceMove">
+                <a-input-number class="commonInput"
+                                v-model:value="formState.PriceMove"
+                                style="width: 140px" />
+              </a-form-item>
+            </a-col>
+          </a-row>
+          <a-row :gutter="24">
+            <a-col :span="12">
+              <a-form-item label="挂牌数量"
+                           name="OrderQty">
+                <a-input-number class="dialogInput"
+                                style="width: 140px"
+                                :min="0"
+                                v-model:value="formState.OrderQty"
+                                placeholder="请输入挂牌数量" />
+                <span class="input-enumdicname">{{selectedRow.enumdicname}}</span>
+              </a-form-item>
+            </a-col>
+            <a-col :span="12">
+              <a-form-item label="起摘数量"
+                           class="relative"
+                           name="DelistMinQty">
+                <a-input-number class="commonInput"
+                                :min="0"
+                                v-model:value="formState.DelistMinQty"
+                                style="width: 140px" />
+                <span class="input-enumdicname">{{selectedRow.enumdicname}}</span>
+                <div class="tip">最小单位:1{{selectedRow.enumdicname}}</div>
+              </a-form-item>
+            </a-col>
+          </a-row>
+          <a-row :gutter="24">
+            <a-col :span="12"
+                   class="mt-20">
+              <a-form-item>
+                <a-slider v-model:value="formState.OrderQty"
+                          ::min="0"
+                          :max="selectedRow.enableqty"
+                          class="formSlider" />
+                <div class="unit">
+                  <span>0</span>
+                  <span>{{selectedRow.enableqty}}{{selectedRow.enumdicname}}</span>
+                </div>
+              </a-form-item>
+            </a-col>
+            <a-col :span="12">&nbsp;</a-col>
+          </a-row>
+          <a-row :gutter="24">
+            <a-col :span="12">
+              <a-form-item label="交收月"
+                           name="DeliveryMonth">
+                <a-month-picker style="width: 140px"
+                                v-model:value="formState.DeliveryMonth"
+                                :allowClear="false"
+                                class="commonDatePicker dialogDatePicker" />
+              </a-form-item>
+            </a-col>
+            <a-col :span="12">
+              <a-form-item>&nbsp;</a-form-item>
+            </a-col>
+          </a-row>
 
-                    <a-row :gutter="24" v-if="formState.WRPriceType === 2">
-                        <a-col :span="24">
-                            <a-form-item label="行情商品" name="goodsid">
-                                <!-- <a-select class="inlineFormSelect"
+          <a-row :gutter="24"
+                 v-if="isFloat()">
+            <a-col :span="24">
+              <a-form-item label="行情商品"
+                           name="goodsid">
+                <!-- <a-select class="inlineFormSelect"
                           style="width: 135px"
                           placeholder="请择交易所">
                                 </a-select>-->
-                                <a-select
-                                    class="inlineFormSelect ml5"
-                                    @change="handleGoodsGroups"
-                                    style="width: 135px"
-                                    v-model:value="formState.goodsgroupid"
-                                    placeholder="请选择商品"
-                                >
-                                    <a-select-option
-                                        v-for="item in goodsGroup"
-                                        :value="item.goodsgroupid"
-                                        :key="item.goodsgroupid"
-                                    >{{item.goodsgroupname}}</a-select-option>
-                                </a-select>
-                                <a-select
-                                    class="inlineFormSelect ml5"
-                                    style="width: 135px"
-                                    v-model:value="formState.goodsid"
-                                    @change="handleGoodsChange"
-                                    placeholder="请选择合约"
-                                >
-                                    <a-select-option
-                                        v-for="item in goodsList"
-                                        :value="item.goodsid"
-                                        :key="item.goodsid"
-                                    >{{item.goodsname}}</a-select-option>
-                                </a-select>
-                            </a-form-item>
-                        </a-col>
-                    </a-row>
-                    <a-row :gutter="24" type="flex" justify="center">
-                        <a-col :span="24">
-                            <a-form-item class="tc">
-                                <a-button
-                                    class="listedBtn"
-                                    :loading="loading"
-                                    :disabled="loading"
-                                    @click="submit"
-                                >卖出</a-button>
-                                <a-button class="ml10 cancelBtn" @click="cancel">取消</a-button>
-                            </a-form-item>
-                        </a-col>
-                    </a-row>
-                </a-form>
-            </div>
-        </div>
-    </Drawer>
+                <a-select class="inlineFormSelect ml5"
+                          @change="handleGoodsGroups"
+                          style="width: 135px"
+                          v-model:value="formState.goodsgroupid"
+                          placeholder="请选择商品">
+                  <a-select-option v-for="item in goodsGroup"
+                                   :value="item.goodsgroupid"
+                                   :key="item.goodsgroupid">{{item.goodsgroupname}}
+                  </a-select-option>
+                </a-select>
+                <a-select class="inlineFormSelect ml5"
+                          style="width: 135px"
+                          v-model:value="formState.goodsid"
+                          @change="handleGoodsChange"
+                          placeholder="请选择合约">
+                  <a-select-option v-for="item in goodsList"
+                                   :value="item.goodsid"
+                                   :key="item.goodsid">{{item.goodsname}}</a-select-option>
+                </a-select>
+              </a-form-item>
+            </a-col>
+          </a-row>
+          <a-row :gutter="24">
+            <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"
+                   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(handleSelectedAccount())}}</span>
+                  </a-col>
+                </a-row>
+              </a-form-item>
+            </a-col>
+          </a-row>
+          <a-row :gutter="24"
+                 type="flex"
+                 justify="center">
+            <a-col :span="24">
+              <a-form-item class="tc">
+                <a-button class="listedBtn"
+                          :loading="loading"
+                          :disabled="loading"
+                          @click="submit">卖出</a-button>
+                <a-button class="ml10 cancelBtn"
+                          @click="cancel">取消</a-button>
+              </a-form-item>
+            </a-col>
+          </a-row>
+        </a-form>
+      </div>
+    </div>
+  </Drawer>
 </template>
 
 <script lang="ts">
-import { defineComponent, PropType, ref } from 'vue';
+import { defineComponent, onMounted, PropType, ref } from 'vue';
 import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
 import Drawer from '@/common/components/drawer/index.vue';
 import { QueryWrPositionReq, WrHoldLB, WrPosition } from '@/services/go/wrtrade/interface';
-import { getInTaAccount, getUserId } from '@/services/bus/account';
+import { getAccountTypeList, getInTaAccount, getSelectedAccount, getUserId } from '@/services/bus/account';
 import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
 import { hdWROrder } from '@/services/proto/warehousetrade';
-import { v4 as uuidv4 } from 'uuid';
+import { v4 as uuidv4, v4 } from 'uuid';
 import moment from 'moment';
 import { ModalEnum } from '@/common/constants/modalNameEnum';
 import { _closeModal } from '@/common/setup/modal/modal';
-import { handleGoods, handlePasswordForm } from './setup';
 import { validateAction } from '@/common/setup/form';
 import { ListingForm } from './interface';
-import { getMarketRunByTradeMode } from '@/services/bus/market';
+import { getMarketByTradeMode, getMarketRunByTradeMode } from '@/services/bus/market';
 import { message } from 'ant-design-vue';
 import { getGoodsGroupsByTradeMode } from '@/services/bus/goods';
 import { BuyOrSell, TradeMode } from '@/common/constants/enumCommon';
 import { HdWROrderReq, WRGoodsInfo } from '@/services/proto/warehousetrade/interface';
 import Bus from '@/utils/eventBus';
+import { handleGoods, handleForm, handleNumAndPrice, handlePriceRule } from './setup';
+import { addSubscribeQuotation, removeSubscribeQuotation } from '@/services/socket/quota';
+import { getCanUseMoney } from '@/services/bus/account';
 
 export default defineComponent({
     name: ModalEnum.spot_warrant_spot_details_listed,
@@ -196,18 +218,40 @@ export default defineComponent({
         },
     },
     setup(props, context) {
-        const { visible, cancel } = _closeModal(context);
-        const { rules, formState, formRef } = handlePasswordForm(props.selectedRow);
-        const data = props.selectedRow;
         const loading = ref<boolean>(false);
+        const marketInfo = getMarketByTradeMode(TradeMode.WarehouseReceiptTrade);
+        if (marketInfo) {
+            // 获取计算规则
+            handlePriceRule(loading, marketInfo.marketid);
+        }
+        const { visible, cancel } = _closeModal(context);
+        const { rules, formState, formRef } = handleForm(props.selectedRow);
         const { goodsGroup, goodsList, groupsChange, findGoodsCode } = handleGoods();
+        // 切换商品组
         function handleGoodsGroups(value: number) {
             groupsChange(value);
             formRef.value.validate();
         }
-        function handleGoodsChange() {
+        const uuid = v4();
+        // 切换商品
+        function handleGoodsChange(id: number) {
+            //行情订阅
+            removeSubscribeQuotation(uuid);
+            const goodsCode = goodsList.value.find((e) => e.goodsid === id)?.goodscode as string;
+            const arr = [{ exchangeCode: 250, goodsCode: goodsCode, subState: 0 }];
+            addSubscribeQuotation(uuid, arr);
             formRef.value.validate();
         }
+        onMounted(() => {
+            removeSubscribeQuotation(uuid);
+        });
+        const { getMoney, getMargin, isFloat } = handleNumAndPrice();
+        // 处理内部资金账号
+        function handleSelectedAccount() {
+            const item = getSelectedAccount();
+            const list = getAccountTypeList([2]);
+            return item.taaccounttype === 2 ? item : list[0];
+        }
         function submit() {
             const marketInfo = getMarketRunByTradeMode(17);
             if (marketInfo) {
@@ -236,7 +280,7 @@ export default defineComponent({
                         IsSpecified: 0, // 是否指定对手 0:不指定 1:指定 uint32
                         // MatchUserIDs: 0, // 仓单贸易对手资金账号ID集合(指定对手时填写) uint32
                         OrderQty: res.OrderQty, // 委托数量(可挂部分数据量) ======
-                        DeliveryGoodsID: data.deliverygoodsid, // 交割商品商品ID
+                        DeliveryGoodsID: props.selectedRow.deliverygoodsid, // 交割商品商品ID
                         WRPriceType: res.WRPriceType, // 价格方式 1:固定价 2:浮动价
                         FixedPrice: res.FixedPrice, // 固定价格
                         PriceFactor: 1, // 价格系数(浮动价时填写)
@@ -282,6 +326,11 @@ export default defineComponent({
             goodsList,
             handleGoodsGroups,
             handleGoodsChange,
+            isFloat,
+            getMoney,
+            getMargin,
+            getCanUseMoney,
+            handleSelectedAccount,
         };
     },
 });

+ 66 - 16
src/views/order/pre_sale_warehouse_receipt/components/pre_sale_warehouse_receipt_order_summary/components/listed/setup.ts

@@ -1,24 +1,27 @@
 import { TradeMode } from '@/common/constants/enumCommon';
+import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
 import { validateCommon } from '@/common/setup/validate';
-import { getGoodsGroupsByTradeMode, getGoodsList } from '@/services/bus/goods';
+import { getGoodsGroupsByTradeMode, getGoodsList, getQuoteDayInfoByCodeFindPrice } from '@/services/bus/goods';
 import { Goods } from "@/services/go/ermcp/goodsInfo/interface";
-import { WrPosition } from "@/services/go/wrtrade/interface";
+import { queryWrMarketTradeConfig } from '@/services/go/wrtrade';
+import { WrMarketTradeConfig, WrPosition } from "@/services/go/wrtrade/interface";
 import { RuleObject } from 'ant-design-vue/lib/form/interface';
-import { reactive, ref, UnwrapRef } from "vue";
+import { reactive, Ref, ref, UnwrapRef } from "vue";
 import { ListingForm } from "./interface";
 
-export function handlePasswordForm(data: WrPosition) {
+const formState: UnwrapRef<ListingForm> = reactive({
+    WRPriceType: 1,
+    FixedPrice: 0,
+    OrderQty: 0,
+    DelistMinQty: 0,
+    PriceMove: 1,
+    goodsgroupid: undefined,
+    goodsid: undefined,
+    DeliveryMonth: ''
+})
+export function handleForm(data: WrPosition) {
     const formRef = ref();
-    const formState: UnwrapRef<ListingForm> = reactive({
-        WRPriceType: 1,
-        FixedPrice: 0,
-        OrderQty: 0,
-        DelistMinQty: 0,
-        PriceMove: 1,
-        goodsgroupid: undefined,
-        goodsid: undefined,
-        DeliveryMonth: ''
-    })
+
     const v_group = async (rule: RuleObject, value: number) => {
         if (formState.goodsgroupid) {
             return validateCommon(value, '请选择合约');
@@ -49,11 +52,10 @@ export function handlePasswordForm(data: WrPosition) {
     return { rules, formState, formRef }
 }
 
-
+const goodsList = ref<Goods[]>([])
 export function handleGoods() {
     const goodsGroup = getGoodsGroupsByTradeMode(TradeMode.quote99);
     const allGoods = getGoodsList()
-    const goodsList = ref<Goods[]>([])
     function groupsChange(id: number) {
         goodsList.value = allGoods.filter(e => e.goodsgroupid === id)
     }
@@ -61,4 +63,52 @@ export function handleGoods() {
         return allGoods.find(e => e.goodsid === id)?.goodscode
     }
     return { goodsGroup, goodsList, groupsChange, findGoodsCode }
+}
+
+
+// 获取金额计算规则
+const rules = ref<WrMarketTradeConfig[]>([])
+export function handlePriceRule(loading: Ref<boolean>, marketid: number) {
+    queryResultLoadingAndInfo(queryWrMarketTradeConfig, loading, { marketid }).then(res => {
+        rules.value = res;
+    })
+}
+
+export function handleNumAndPrice() {
+    function isFloat() {
+        return formState.WRPriceType === 2;
+    }
+    // 获取选中的资金账号
+    const hasRules = () => rules.value.length > 0
+    //  摘牌金额
+    function getMoney() {
+        let result = 0
+        if (isFloat()) {
+            if (hasRules()) {
+                const goodsCode = goodsList.value.find(e => e.goodsid === formState.goodsid)?.goodscode as string
+                const goodsPrice = getQuoteDayInfoByCodeFindPrice(goodsCode);
+                if (goodsPrice && goodsPrice !== '--') {
+                    // 浮动价挂牌金额=(基差价格+期货合约最新价)*挂牌数量
+                    result = (formState.PriceMove + (goodsPrice as number)) * formState.OrderQty
+                }
+            }
+        } else {
+            // 摘牌金额=挂牌价格*摘牌数量
+            result = formState.OrderQty * formState.FixedPrice
+        }
+        return Number(result.toFixed(2))
+    }
+    // 履约保证金
+    function getMargin() {
+        if (hasRules()) {
+            const { sellmarginvalue } = rules.value[0]
+            // 浮动价 履约保证金=估算总额*买方履约保证金比例
+            // 一口价 履约保证金=挂牌金额*买方履约保证金比例
+            return Number((getMoney() * sellmarginvalue).toFixed(2))
+        } else {
+            return 0
+        }
+
+    }
+    return { getMoney, getMargin, isFloat }
 }