huangbin il y a 4 ans
Parent
commit
1d90858686

+ 19 - 90
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_deal_closed/index.vue

@@ -18,7 +18,7 @@
               <div class="middle">数量/价格/金额</div>
               <div class="right">到期日/盈亏</div>
             </div>
-            <a-checkbox-group class="commonCheckboxGroup"
+            <!-- <a-checkbox-group class="commonCheckboxGroup"
                               v-model:value="checked"
                               @change="checkGroupChange">
               <div class="lineBar"
@@ -55,11 +55,11 @@
                   </div>
                 </div>
               </div>
-            </a-checkbox-group>
+            </a-checkbox-group> -->
           </div>
         </div>
         <div class="fixedBtns">
-          <div class="formbottom">
+          <!-- <div class="formbottom">
             <div class="line1">
               <div>
                 <span>已点选数量</span>
@@ -79,7 +79,7 @@
             </div>
             <div v-if="isBaseSpread()"
                  class="line3">预估货款:{{getEstimatedPayment()}}</div>
-          </div>
+          </div> -->
 
           <a-form-item class="btnCenter mt10">
             <a-button class="listedBtn"
@@ -106,8 +106,7 @@ import { BuyOrSell } from '@/common/constants/enumCommon';
 import Long from 'long';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
-import { handleCheck, getTableList, handleCalculation } from './setup';
-import { DeliveryOrder } from '@/services/proto/warehousetrade';
+import { DeliveryOrder, tradeHoldTransferApply } from '@/services/proto/warehousetrade';
 import { v4 } from 'uuid';
 import moment from 'moment';
 import { DeliveryOrderReq, TradeHoldTransferApplyReq } from '@/services/proto/warehousetrade/interface';
@@ -120,6 +119,10 @@ import { QueryTjmdTransferApplyRsp } from '@/services/go/Tjmd/interface';
 import { GetLoginID } from '@/services/go/useInfo';
 import { queryTradeHolderDetail } from '@/services/go/order';
 import { QueryTradeHolderDetailReq } from '@/services/go/order/interface';
+import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
+import { validateAction } from '@/common/setup/form';
+import { FormState } from './interface';
+import { handleForm } from './setup';
 
 export default defineComponent({
     name: ModalEnum.commodity_contract_summary_settlement,
@@ -137,6 +140,7 @@ export default defineComponent({
     },
     setup(props, context) {
         const { visible, cancel } = _closeModal(context);
+        const { rules, formState, formRef } = handleForm();
         // 表格列表数据
         const { loading, tableList, queryTable } = queryTableList<QueryTjmdTransferApplyRsp>();
         const param: QueryTradeHolderDetailReq = {
@@ -146,84 +150,23 @@ export default defineComponent({
         };
         queryTable(queryTradeHolderDetail, param);
 
-        const { goodsid } = props.selectedRow;
-        // 合约交收可点选仓单
-        // const { tableList } = getTableList(goodsid);
-        // check 是否选中逻辑
-        const { checked, selected, deliveryGoods, checkGroupChange, isChecked, checkboxChange, isBaseSpread } = handleCheck();
-        // 各种计算
-        const { getStepValue, getCanSettlementNum, getNeedContractNum, getEstimatedPayment, XQty, PQty, getDeliveryGoodsPrice, increase, decrease, selctedNum } = handleCalculation(props.selectedRow);
-
         const toFixed0 = (value: number) => +value.toFixed(0);
 
         function submit() {
+            // validateAction<FormState>(formRef, formState).then((res) => {
+            const item = tableList.value[0];
             const param: TradeHoldTransferApplyReq = {
-                TradeID: 111,
-                BuyorSell: 1,
-                TransferPrice: 11,
+                TradeID: Long.fromString(item.tradeid),
+                BuyorSell: item.buyorsell,
+                TransferPrice: 100,
                 ApplySrc: 2,
                 ApplicantID: geLoginID_number()!,
                 Remark: '',
             };
-
-            if (!selected.value) {
-                message.warn('请选择合约');
-                return;
-            }
-            if (!selected.value.num) {
-                message.warn('请输入选择数量');
-                return;
-            }
-
-            if (deliveryGoods.value) {
-                loading.value = true;
-                console.log(deliveryGoods.value);
-                const param: DeliveryOrderReq = {
-                    ClientSerialNo: v4(), // 客户端流水号
-                    ClientOrderTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), // 客户端委托时间
-                    ClientType: 4, // 终端类型
-                    // goodsID: props.selectedRow.goodsid,
-                    // market
-                    AccountID: getSelectedAccountId(),
-                    XGoodsID: getGoodsByCode(selected.value.xgoodscode)!.goodsid,
-                    DeliveryGoodsID: deliveryGoods.value.deliverygoodsid,
-                    XQty: Long.fromNumber(XQty()),
-                    PQty: Long.fromNumber(PQty()),
-                    OperateType: 0,
-                    OrderSrc: 0,
-                    OperatorID: Number(geLoginID_number()),
-                    DeliveryQty: selected.value.num,
-                    DeliveryOrderDetail: {
-                        AccountID: selected.value.accountid,
-                        Qty: selected.value.num,
-                        LadingBillID: Long.fromString(selected.value.ladingbillid),
-                        WRFactorTypeID: Long.fromString(selected.value.wrfactortypeid),
-                        SubNum: selected.value.subnum,
-                    },
-                };
-                if (isBaseSpread()) {
-                    param.PGoodsID = deliveryGoods.value.pgoodsid;
-                } else {
-                    // param.PGoodsID = 0;
-                    param.PQty = 0;
-                }
-                console.log('param', param);
-                DeliveryOrder(param)
-                    .then((res) => {
-                        console.log('res', res);
-                        message.success('提交成功');
-                        cancel(true);
-                    })
-                    .catch((err) => {
-                        console.log('err', err);
-                        message.error(err);
-                    })
-                    .finally(() => {
-                        loading.value = false;
-                    });
-            } else {
-                message.warn('未找到对应的交割商品');
-            }
+            requestResultLoadingAndInfo(tradeHoldTransferApply, param, loading, ['协议平仓成功', '协议平仓失败:']).then(() => {
+                cancel(true);
+            });
+            // });
         }
         return {
             visible,
@@ -231,20 +174,6 @@ export default defineComponent({
             submit,
             tableList,
             loading,
-            checkGroupChange,
-            checkboxChange,
-            checked,
-            isChecked,
-            isBaseSpread,
-            getStepValue,
-            getCanSettlementNum,
-            getNeedContractNum,
-            getEstimatedPayment,
-            getDeliveryGoodsPrice,
-            increase,
-            decrease,
-            selctedNum,
-            selected,
             toFixed0,
         };
     },

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

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

+ 18 - 207
src/views/order/commodity_contract/components/commodity_contract_summary/components/commodity_contract_summary_deal_closed/setup.ts

@@ -1,209 +1,20 @@
-import { handleDeliveryRelation } from "@/common/setup/deliveryRelation";
-import { getSelectedAccountId } from "@/services/bus/account";
-import { getGoodsByCode, getQuoteDayInfoByCode } from "@/services/bus/goods";
-import { QueryDeliveryRelationRsp } from "@/services/go/delivery/interface";
-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";
-
-// 选中的交收合约
-const selected = ref<DBType>()
-const checked = ref<string>();
-// 交割商品
-const deliveryGoods = ref<QueryDeliveryRelationRsp | undefined>();
-
-// 查询合约交收可点选仓单
-export function getTableList(goodsid: number) {
-    // 交割商品
-    const { getItemDeliveryRelationByGoodsId } = handleDeliveryRelation()
-    const param: QueryWrDeliveryAvalidHoldLBReq = {
-        goodsid,
-        accountid: getSelectedAccountId(),
+import { validateCommon } from "@/common/setup/validate";
+import { RuleObject } from "ant-design-vue/lib/form/interface";
+import { reactive, ref, UnwrapRef } from "vue";
+import { FormState } from "./interface";
+
+export function handleForm() {
+    const formRef = ref();
+    const v_num = async (rule: RuleObject, value: number) => {
+        return validateCommon(value, '请输入协议价');
     };
-    const tableList = ref<DBType[]>([]);
-    queryWrDeliveryAvalidHoldLB(param).then((res) => {
-        tableList.value = res.map((e, i) => {
-            if (i) {
-                return { ...e, checked: false, num: 0 };
-            } else {
-                // 默认勾选第一个
-                checked.value = e.ladingbillid
-                const result = { ...e, checked: true, num: 0 };
-                selected.value = result
-                deliveryGoods.value = getItemDeliveryRelationByGoodsId(e.goodsid).value
-                return result
-            }
-        });
-    });
-    return { tableList }
-}
-
-
-
-export function handleCheck() {
-    // 交割商品
-    const { getItemDeliveryRelationByGoodsId } = handleDeliveryRelation()
-
-    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;
-        deliveryGoods.value = getItemDeliveryRelationByGoodsId(item.goodsid).value
-    }
-    // true 基差点价; false 挂牌点选
-    function isBaseSpread() {
-        if (deliveryGoods.value) {
-            // 1和3是订单交易 挂牌转让
-            // 2和4是基差点价
-            const arr = [2, 4]
-            return arr.includes(deliveryGoods.value.deliverytype)
-        } else {
-            return false
-        }
-    }
-    return { checked, selected, deliveryGoods, checkGroupChange, isChecked, checkboxChange, isBaseSpread }
-}
-
-export function handleCalculation(selectedRow: QueryTradePositionRsp) {
-    // 商品合约单位
-    const { enableqty } = selectedRow
-    function getDecimalplace() {
-        let result = 2;
-        const goods = selected.value?.pgoodscode
-        if (goods) {
-            const item = getGoodsByCode(goods)
-            item && (result = item.decimalplace)
-        }
-        return result
-    }
-    function getAgreeunit(goodscode: string) {
-        let result = 1
-        // const goodscode = selectedRow.goodscode
-        // if (goodscode) {
-        const item = getGoodsByCode(goodscode)
-        if (item) {
-            result = item.agreeunit
-        }
-        // }
-        return result
-    }
-
-
-    function selctedNum() {
-        return selected.value ? selected.value.num.toFixed(0) : '--'
-    }
-    // 选中数量的 最小变动值 = 合约单位 * 最小交割系数 * 仓单商品的单位r2
-    function getStepValue() {
-        const agreeunit = getAgreeunit(selectedRow.goodscode)
-        if (deliveryGoods.value) {
-            const { rratio2, mindeliveryqty } = deliveryGoods.value
-            return agreeunit * mindeliveryqty * rratio2
-        } else {
-            return agreeunit
-        }
-    }
-    // 可交收数量 = 合约可用手数 * 合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1)
-    function getCanSettlementNum() {
-        if (deliveryGoods.value) {
-            const agreeunit = getAgreeunit(selectedRow.goodscode)
-            const { rratio1, rratio2, mindeliveryqty } = deliveryGoods.value
-            const result = enableqty * agreeunit * mindeliveryqty * (rratio2 / rratio1)
-            return result.toFixed(0)
-        } else {
-            return '--'
-        }
-    }
-    // (选中的数量 / (合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1)))
-    function XQty() {
-        let result = 0
-        if (selected.value?.num) {
-            if (deliveryGoods.value) {
-                const agreeunit = getAgreeunit(selectedRow.goodscode)
-                const { rratio1, rratio2, mindeliveryqty, xdeliveryratio, pdeliveryratio } = deliveryGoods.value
-                result = selected.value.num / (agreeunit * mindeliveryqty * (rratio2 / rratio1))
-            }
-        }
-        return result
-    }
-    // 需要合约手数 = (选中的数量 / (合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1))) / (p1合约系数 / x合约系数)
-    function PQty() {
-        let result = XQty()
-        if (result) {
-            if (deliveryGoods.value) {
-                const { xdeliveryratio, pdeliveryratio } = deliveryGoods.value
-                result = result / pdeliveryratio / xdeliveryratio
-            }
-        }
-        return result
-    }
-    // 需要合约手数 = (选中的数量 / (合约单位 * 最小交割系数 * (仓单商品的单位r2/合约商品的单位r1))) / (p1合约系数 / x合约系数)
-    function getNeedContractNum() {
-        const result = PQty()
-        return result ? result.toFixed(0) : '--'
-    }
-    // 预估货款 = 需要合约手数  * 合约交割价 * 合约单位 + 升贴水
-    function getEstimatedPayment() {
-        const num = getNeedContractNum()
-        const price = getDeliveryGoodsPrice()
-        let result = 0
-        if (selected.value) {
-            if (num !== '--' && price !== '--') {
-                if (deliveryGoods.value) {
-                    const agreeunit = getAgreeunit(selected.value.pgoodscode)
-                    result = (Number(num) * Number(price) * agreeunit) + (selected.value.pricemove * selected.value.num)
-                }
-            }
-        }
-        return result ? result.toFixed(getDecimalplace()) : '--'
-    }
-    /**
-     * 合约交割价取价规则
-     * 1.优先实时结算价
-     * 2.其次卖一价
-     * 3.再次是买一价与成交价中的最高价
-     * 4.最后取昨日结算价
-     * 所有权(X): 不取交割价,默认设为0,不影响交割流程
-     */
-    function getDeliveryGoodsPrice() {
-        const goodscode = selected.value?.pgoodscode
-        if (!goodscode) return '--'
-        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(getDecimalplace()) : '--'
-    }
-
-    // 增加
-    function increase(value: DBType) {
-        if (value.num < value.avalidqty) {
-            value.num += getStepValue()
-            value.num = +value.num.toFixed(getDecimalplace())
-        }
-    }
-    // 减少
-    function decrease(value: DBType) {
-        if (value.num > 0) {
-            value.num -= getStepValue()
-            value.num = +value.num.toFixed(getDecimalplace())
-        }
-    }
-    return { getStepValue, getCanSettlementNum, getNeedContractNum, getEstimatedPayment, XQty, PQty, getDeliveryGoodsPrice, increase, decrease, selctedNum }
+    const formState: UnwrapRef<FormState> = reactive({
+        num: 0,
+    })
+    const rules = {
+        num: [
+            { require, message: '请输入协议价', trigger: 'blur', type: 'number', validator: v_num },
+        ],
+    }
+    return { rules, formState, formRef }
 }