huangbin 4 lat temu
rodzic
commit
87cdf62367

+ 46 - 0
src/common/setup/deliveryRelation/index.ts

@@ -0,0 +1,46 @@
+import { queryDeliveryRelation } from "@/services/go/delivery";
+import { QueryDeliveryRelationRsp } from '@/services/go/delivery/interface';
+import { ref, watchEffect } from "vue";
+
+// 所有交割关系
+const allDeliveryRelation = ref<QueryDeliveryRelationRsp[]>([])
+export function handleDeliveryRelation() {
+    function hasDR() {
+        return allDeliveryRelation.value.length !== 0
+    }
+    /**
+     * 查询交割商品关系
+     */
+    function queryDR() {
+        queryDeliveryRelation({}).then(res => {
+            allDeliveryRelation.value = res
+        })
+    }
+    /**
+     * 更新交割商品
+     */
+    function updateDeliveryRelation() {
+        queryDR()
+    }
+    if (!hasDR()) {
+        queryDR()
+    }
+    /**
+     * 通过goodsid 查找对应的交割商品
+     * @param goodsid
+     * @returns
+     */
+    function getItemDeliveryRelationByGoodsId(goodsid: number) {
+        const result = ref<QueryDeliveryRelationRsp>()
+        const fn = () => allDeliveryRelation.value.find(e => e.goodsid === goodsid)
+        const stop = watchEffect(() => {
+            result.value = fn()
+        })
+        if (hasDR()) {
+            stop()
+        }
+        return result
+        // return allDeliveryRelation.value.find(e => e.goodsid === goodsid)
+    }
+    return { allDeliveryRelation, updateDeliveryRelation, getItemDeliveryRelationByGoodsId }
+}

+ 6 - 0
src/services/bus/goods.ts

@@ -97,4 +97,10 @@ export function getGoodsGroupsByTradeMode(trademode: TradeMode): Goodsgroup[] {
         console.warn(`trademode:${trademode}市场信息不存在`)
     }
     return result
+}
+
+// 通过goodsid 获取商品合约单位
+export function getGoodsAgreeunitByGoodsId(goodsid: number): number | null {
+    const result = getGoodsList().find(el => el.goodsid === goodsid)
+    return result ? result.agreeunit : null
 }

+ 97 - 126
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_settlement/index.vue

@@ -1,104 +1,95 @@
 <template>
-    <!-- 交收-->
-    <Drawer
-        :title="'交收'"
-        :placement="'right'"
-        class="bottom486"
-        :visible="visible"
-        @cancel="cancel"
-    >
-        <div class="listed c_c_s_s">
-            <a-form class="inlineForm dialogForm" ref="formRef" :model="formState" :rules="rules">
-                <div class="formBar">
-                    <div class="formtop">
-                        <div class="firstTitle">
-                            <span>合约数量 10,</span>
-                            <span>可交收数量 50 吨</span>
-                        </div>
-                        <div class="secondLine">
-                            <div class="left">持有人/商品/仓库</div>
-                            <div class="middle">升贴水/数量</div>
-                            <div class="right">选择数量</div>
-                        </div>
-                        <a-checkbox-group
-                            class="commonCheckboxGroup"
-                            v-model:value="checked"
-                            @change="change"
-                        >
-                            <div
-                                class="lineBar"
-                                v-for="(item, index) in tableList"
-                                :key="index + '11'"
-                            >
-                                <div class="line1">
-                                    <div class>
-                                        <a-checkbox :value="item.ladingbillid"></a-checkbox>
-                                    </div>
-                                    <div class="name">{{item.username}}</div>
-                                </div>
-                                <div class="line2">
-                                    <div class="left">
-                                        <div>{{item.wrtypename}}</div>
-                                        <div>{{item.warehousename}}</div>
-                                    </div>
-                                    <div class="middle">
-                                        <div>{{item.pricemove}}</div>
-                                        <div>{{item.avalidqty}}{{item.enumdicname}}</div>
-                                    </div>
-                                    <div class="right">
-                                        <template
-                                            class="inputNumberBlock"
-                                            :class="isChecked(item.ladingbillid) ? '' : 'disabled'"
-                                        >
-                                            <a-input-number
-                                                class="dialogInput dialogInput34"
-                                                v-model:value="item.num"
-                                                style="width: 130px !important; height: 34px;"
-                                                :disabled="!isChecked(item.ladingbillid)"
-                                                :min="0"
-                                            ></a-input-number>
-                                            <MinusOutlined />
-                                            <PlusOutlined />
-                                        </template>
-                                    </div>
-                                </div>
-                            </div>
-                        </a-checkbox-group>
-                    </div>
+  <!-- 交收-->
+  <Drawer :title="'交收'"
+          :placement="'right'"
+          class="bottom486"
+          :visible="visible"
+          @cancel="cancel">
+    <div class="listed c_c_s_s">
+      <a-form class="inlineForm dialogForm"
+              ref="formRef">
+        <div class="formBar">
+          <div class="formtop">
+            <div class="firstTitle">
+              <span>合约数量 {{selectedRow.enableqty}}</span>
+              <span>可交收数量 {{getCanSettlementNum()}} {{selectedRow.goodunit}}</span>
+            </div>
+            <div class="secondLine">
+              <div class="left">持有人/商品/仓库</div>
+              <div class="middle">升贴水/数量</div>
+              <div class="right">选择数量</div>
+            </div>
+            <a-checkbox-group class="commonCheckboxGroup"
+                              v-model:value="checked"
+                              @change="checkGroupChange">
+              <div class="lineBar"
+                   v-for="(item, index) in tableList"
+                   :key="index + '11'">
+                <div class="line1">
+                  <div class>
+                    <a-checkbox @change="checkboxChange(item)"
+                                :value="item.ladingbillid"></a-checkbox>
+                  </div>
+                  <div class="name">{{item.username}}</div>
                 </div>
-                <div class="fixedBtns">
-                    <div class="formbottom">
-                        <div class="line1">
-                            <div>
-                                <span>已点选数量</span>
-                                <span class="white">40吨</span>
-                                <span>,需合约数量</span>
-                                <span class="white">8</span>
-                            </div>
-                            <div class="yellow">升贴水1100</div>
-                        </div>
-                        <div class="line2">
-                            <div>点价合约</div>
-                            <div class="right">
-                                <div>C2109</div>
-                                <div>1398.00</div>
-                            </div>
-                        </div>
-                        <div class="line3">预估贷款:71,000.00</div>
-                    </div>
-
-                    <a-form-item class="btnCenter mt10">
-                        <a-button
-                            class="listedBtn"
-                            :loading="loading"
-                            :disabled="loading"
-                            @click="submit"
-                        >提交</a-button>
-                    </a-form-item>
+                <div class="line2">
+                  <div class="left">
+                    <div>{{item.wrtypename}}</div>
+                    <div>{{item.warehousename}}</div>
+                  </div>
+                  <div class="middle">
+                    <div>{{item.pricemove}}</div>
+                    <div>{{item.avalidqty}}{{item.enumdicname}}</div>
+                  </div>
+                  <div class="right">
+                    <template class="inputNumberBlock"
+                              :class="isChecked(item.ladingbillid) ? '' : 'disabled'">
+                      <a-input-number class="dialogInput dialogInput34"
+                                      v-model:value="item.num"
+                                      style="width: 130px !important; height: 34px;"
+                                      :disabled="!isChecked(item.ladingbillid)"
+                                      :max="item.avalidqty"
+                                      :min="0"></a-input-number>
+                      <MinusOutlined @click="decrease(item)" />
+                      <PlusOutlined @click="increase(item)" />
+                    </template>
+                  </div>
                 </div>
-            </a-form>
+              </div>
+            </a-checkbox-group>
+          </div>
+        </div>
+        <div class="fixedBtns">
+          <div class="formbottom">
+            <div class="line1">
+              <div>
+                <span>已点选数量</span>
+                <span class="white">{{selctedNum()}} {{selectedRow.goodunit}}</span>
+                <span>,需合约数量</span>
+                <span class="white">{{getNeedContractNum()}}</span>
+              </div>
+              <div class="yellow">升贴水1100</div>
+            </div>
+            <div class="line2">
+              <div>点价合约</div>
+              <div class="right">
+                <div>{{selectedRow.goodscode}}</div>
+                <div>{{getDeliveryGoodsPrice()}}</div>
+              </div>
+            </div>
+            <div class="line3">预估贷款:{{getEstimatedPayment()}}</div>
+          </div>
+
+          <a-form-item class="btnCenter mt10">
+            <a-button class="listedBtn"
+                      :loading="loading"
+                      :disabled="loading"
+                      @click="submit">提交</a-button>
+          </a-form-item>
         </div>
-    </Drawer>
+      </a-form>
+    </div>
+  </Drawer>
 </template>
 
 <script lang="ts">
@@ -109,7 +100,7 @@ import { ModalEnum } from '@/common/constants/modalNameEnum';
 import { _closeModal } from '@/common/setup/modal/modal';
 // import { handleForm } from './setup';
 import { validateAction } from '@/common/setup/form';
-import { FormState } from './interface';
+import { DBType, FormState } from './interface';
 
 import UploadImg from '@/common/components/uploadImg/index.vue';
 import { getUploadImg } from '@/common/setup/upload';
@@ -125,11 +116,7 @@ import { useQueryData } from '@/common/setup/request';
 import { queryWrDeliveryAvalidHoldLB } from '@/services/go/wrtrade';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
-
-interface DBType extends WrDeliveryAvalidHoldLB {
-    checked: boolean;
-    num: number;
-}
+import { handleCheck, getTableList, handleCalculation } from './setup';
 
 export default defineComponent({
     name: ModalEnum.commodity_contract_summary_settlement,
@@ -148,25 +135,10 @@ export default defineComponent({
     setup(props, context) {
         const { visible, cancel } = _closeModal(context);
         const loading = ref<boolean>(false);
-
-        const param: QueryWrDeliveryAvalidHoldLBReq = {
-            goodsid: props.selectedRow.goodsid,
-            accountid: getSelectedAccountId(),
-        };
-        const tableList = ref<DBType[]>([]);
-        queryWrDeliveryAvalidHoldLB(param).then((res) => {
-            tableList.value = res.map((e) => {
-                return { ...e, checked: false, num: 0 };
-            });
-        });
-
-        const checked = ref<string>();
-        function change(checkedValue: string[]) {
-            checked.value = checkedValue[checkedValue.length - 1];
-        }
-        function isChecked(value: string) {
-            return value === checked.value;
-        }
+        // 合约交收可点选仓单
+        const { tableList } = getTableList(props.selectedRow.goodsid);
+        // check 是否选中逻辑
+        const { checked, selected, checkGroupChange, isChecked, checkboxChange } = handleCheck();
 
         function submit() {
             // validateAction<FormState>(formRef, formState).then((param) => {
@@ -189,12 +161,11 @@ export default defineComponent({
             submit,
             tableList,
             loading,
-            change,
+            checkGroupChange,
+            checkboxChange,
             checked,
             isChecked,
-            // rules,
-            // formState,
-            // formRef,
+            ...handleCalculation(props.selectedRow),
         };
     },
 });

+ 7 - 0
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_settlement/interface.ts

@@ -1,4 +1,11 @@
+import { WrDeliveryAvalidHoldLB } from "@/services/go/wrtrade/interface";
+
 export interface FormState {
     // price: number,
     num: number,
+}
+
+export interface DBType extends WrDeliveryAvalidHoldLB {
+    checked: boolean;
+    num: number;
 }

+ 137 - 14
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_settlement/setup.ts

@@ -1,15 +1,138 @@
-import { reactive, ref, UnwrapRef } from "vue";
-import { FormState } from "./interface";
-
-export function handleForm() {
-    const formRef = ref();
-    const formState: UnwrapRef<FormState> = reactive({
-        // price: 0,
-        num: 0
-    })
-    const rules = {
-        // price: [{ require, message: '请输入挂牌价', trigger: 'blur', }],
-        num: [{ require, message: '请输入交收数量', trigger: 'blur', type: 'number' }],
-    }
-    return { rules, formState, formRef }
+import { handleDeliveryRelation } from "@/common/setup/deliveryRelation";
+import { getSelectedAccountId } from "@/services/bus/account";
+import { getQuoteDayInfoByCode } from "@/services/bus/goods";
+import { QueryTradePositionRsp } from "@/services/go/ermcp/order/interface";
+import { queryWrDeliveryAvalidHoldLB } from "@/services/go/wrtrade";
+import { QueryWrDeliveryAvalidHoldLBReq } from "@/services/go/wrtrade/interface";
+import { ref } from "vue";
+import { DBType } from "./interface";
+
+// 查询合约交收可点选仓单
+export function getTableList(goodsid: number) {
+    const param: QueryWrDeliveryAvalidHoldLBReq = {
+        goodsid,
+        accountid: getSelectedAccountId(),
+    };
+    const tableList = ref<DBType[]>([]);
+    queryWrDeliveryAvalidHoldLB(param).then((res) => {
+        tableList.value = res.map((e) => {
+            return { ...e, checked: false, num: 0 };
+        });
+    });
+    return { tableList }
+}
+
+// 选中的交收合约
+const selected = ref<DBType>()
+
+export function handleCheck() {
+    const checked = ref<string>();
+
+    function checkGroupChange(checkedValue: string[]) {
+        checked.value = checkedValue[checkedValue.length - 1];
+    }
+    function isChecked(value: string) {
+        return value === checked.value;
+    }
+    function checkboxChange(item: DBType) {
+        selected.value = item;
+    }
+    return { checked, selected, checkGroupChange, isChecked, checkboxChange }
+}
+
+export function handleCalculation(selectedRow: QueryTradePositionRsp) {
+    // 商品合约单位
+    const { agreeunit, goodsid, goodscode, decimalplace, enableqty } = selectedRow
+    // 交割商品
+    const { getItemDeliveryRelationByGoodsId } = handleDeliveryRelation()
+    const deliveryRetation = getItemDeliveryRelationByGoodsId(goodsid)
+    function selctedNum() {
+        return selected.value ? selected.value.num : '--'
+    }
+    // 选中数量的 最小变动值 = 合约单位 * 最小交割系数 * 仓单商品的单位r2
+    function getStepValue() {
+        if (deliveryRetation.value) {
+            const { rratio2, mindeliveryqty } = deliveryRetation.value
+            return agreeunit * mindeliveryqty * rratio2
+        } else {
+            return agreeunit
+        }
+    }
+    // 可交收数量 = 合约可用手数 * 合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1)
+    function getCanSettlementNum() {
+        if (deliveryRetation.value) {
+            const { rratio1, rratio2, mindeliveryqty } = deliveryRetation.value
+            const result = enableqty * agreeunit * mindeliveryqty * (rratio2 / rratio1)
+            return result.toFixed(2)
+        } else {
+            return '--'
+        }
+    }
+    // 需要合约手数 = (选中的数量 / (合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1))) / (p1合约系数 / x合约系数)
+    function getNeedContractNum() {
+        let result = 0
+        if (selected.value?.num) {
+            if (deliveryRetation.value) {
+                const { rratio1, rratio2, mindeliveryqty, xdeliveryratio, pdeliveryratio } = deliveryRetation.value
+                result = selected.value.num / (agreeunit * mindeliveryqty * (rratio2 / rratio1)) / pdeliveryratio / xdeliveryratio
+            }
+        }
+        return result ? result.toFixed(decimalplace) : '--'
+    }
+    // 预估货款 = 需要合约手数  * 合约交割价 * 合约单位 + 升贴水
+    function getEstimatedPayment() {
+        const num = getNeedContractNum()
+        const price = getDeliveryGoodsPrice()
+        let result = 0
+        if (selected.value) {
+            if (num !== '--' && price !== '--') {
+                if (deliveryRetation.value) {
+                    result = (+num) * (+price) * agreeunit + selected.value.pricemove
+                }
+            }
+        }
+        return result ? result.toFixed(decimalplace) : '--'
+    }
+    /**
+     * 合约交割价取价规则
+     * 1.优先实时结算价
+     * 2.其次卖一价
+     * 3.再次是买一价与成交价中的最高价
+     * 4.最后取昨日结算价
+     * 所有权(X): 不取交割价,默认设为0,不影响交割流程
+     */
+    function getDeliveryGoodsPrice() {
+        const item = getQuoteDayInfoByCode(goodscode);
+        const has = (value: any) => value && value !== '--'
+        let result = 0
+        if (item) {
+            const { settle, ask, bid, last, presettle } = item
+            if (has(settle)) {
+                result = settle
+            } else if (has(ask)) {
+                result = ask
+            } else if (has(bid) && has(last)) {
+                result = Math.max(bid, last)
+            } else if (has(presettle)) {
+                result = presettle
+            }
+        }
+        return has(result) ? result.toFixed(decimalplace) : '--'
+    }
+
+    // 增加
+    function increase(value: DBType) {
+        if (value.num < value.avalidqty) {
+            value.num += getStepValue()
+            value.num = +value.num.toFixed(decimalplace)
+        }
+    }
+    // 减少
+    function decrease(value: DBType) {
+        if (value.num > 0) {
+            value.num -= getStepValue()
+            value.num = +value.num.toFixed(decimalplace)
+        }
+    }
+    return { getStepValue, getCanSettlementNum, getNeedContractNum, getEstimatedPayment, getDeliveryGoodsPrice, increase, decrease, selctedNum }
 }

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

@@ -1,52 +1,47 @@
 <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 v-if="btnList.length" #expandedRowRender="{ record }">
-                <BtnList
-                    :btnList="btnList"
-                    :record="record"
-                    class="btn-list-sticky"
-                    @click="openComponent"
-                />
-            </template>
-            <template #createtime="{ record }">
-                <a>{{ formatTime(record.createtime) }}</a>
-            </template>
-            <!-- 现价 -->
-            <template #lastprice="{ record }">
-                <a>{{ getLastprice(record) }}</a>
-            </template>
-            <!-- 持仓金额  -->
-            <template #holderprice="{ record }">
-                <a>{{ getHolderprice(record) }}</a>
-            </template>
-            <!-- 持仓盈亏 -->
-            <template #profitloss="{ record }">
-                <a>{{ getProfitloss(record) }}</a>
-            </template>
-        </a-table>
-        <component
-            :is="componentId"
-            v-if="componentId"
-            :selectedRow="selectedRow"
-            :tableList="tableList"
-            @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 v-if="btnList.length"
+                #expandedRowRender="{ record }">
+        <BtnList :btnList="btnList"
+                 :record="record"
+                 class="btn-list-sticky"
+                 @click="openComponent" />
+      </template>
+      <template #createtime="{ record }">
+        <a>{{ formatTime(record.createtime) }}</a>
+      </template>
+      <!-- 现价 -->
+      <template #lastprice="{ record }">
+        <a>{{ getLastprice(record) }}</a>
+      </template>
+      <!-- 持仓金额  -->
+      <template #holderprice="{ record }">
+        <a>{{ getHolderprice(record) }}</a>
+      </template>
+      <!-- 持仓盈亏 -->
+      <template #profitloss="{ record }">
+        <a>{{ getProfitloss(record) }}</a>
+      </template>
+    </a-table>
+    <component :is="componentId"
+               v-if="componentId"
+               :selectedRow="selectedRow"
+               :tableList="tableList"
+               @cancel="closeComponent"></component>
+  </section>
 </template>
 
 <script lang="ts">
@@ -61,6 +56,7 @@ import { queryTradePosition } from '@/services/go/ermcp/order';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
 import { getQuoteDayInfoByCode } from '@/services/bus/goods';
+import { handleDeliveryRelation } from '@/common/setup/deliveryRelation';
 
 export default defineComponent({
     name: enumOrderComponents.commodity_contract_summary,
@@ -73,6 +69,8 @@ export default defineComponent({
         // 表格列表数据
         const { loading, tableList, queryTable } = queryTableList<QueryTradePositionRsp>();
         const { subscribeAction } = handleSubcriteQuote();
+        // 交割商品
+        handleDeliveryRelation();
         // 获取列表数据
         const queryTableAction = () => {
             queryTable(queryTradePosition).then((res) => {