Commit 1b7cd0b6 authored by XieZhiXiong's avatar XieZhiXiong

fix: 修复 合同订单 退款金额为0的问题

parent 1f578402
......@@ -6,11 +6,7 @@
* @Description:
*/
import { useBusinessEffects } from './useBusinessEffects';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { PublicApi } from '@/services/api';
export const createEffects = (context, actions) => {
const { setFieldState } = actions;
useBusinessEffects(context, actions);
};
\ No newline at end of file
......@@ -2,12 +2,16 @@
* @Author: XieZhiXiong
* @Date: 2020-11-03 18:30:47
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-02-24 17:25:15
* @LastEditTime: 2021-05-13 11:43:00
* @Description: 联动逻辑相关
*/
import BigNumber from 'bignumber.js';
import { FormEffectHooks, FormPath } from '@formily/antd';
import { useLinkageUtils } from '@/utils/formEffectUtils';
import { FormEffectHooks } from '@formily/antd';
import {
ORDER_TYPE_INQUIRY_CONTRACT,
ORDER_TYPE_BIDDING_CONTRACT,
ORDER_TYPE_TENDER_CONTRACT,
} from '@/constants/order';
const {
onFieldInputChange$,
......@@ -18,36 +22,49 @@ export const useBusinessEffects = (context, actions) => {
const {
getFieldValue,
setFieldValue,
getFieldState,
setFieldState,
} = actions;
const linkage = useLinkageUtils();
// 联动退款金额
onFieldValueChange$('payList.*.refundAmount').subscribe(fieldState => {
const payListValue = getFieldValue('payList');
onFieldValueChange$('payList.*.refundAmount').subscribe(async () => {
const payListValue = await getFieldValue('payList');
const amount = payListValue.reduce((pre, now) => new BigNumber(+now.refundAmount).plus(pre).toNumber(), 0);
setFieldValue('refundAmount', amount);
});
// 退款数量 联动,支付信息里边的 退款金额
onFieldInputChange$('returnCount').subscribe(fieldState => {
onFieldInputChange$('returnCount').subscribe(async (fieldState) => {
const { value } = fieldState;
const purchasePriceValue = getFieldValue('purchasePrice');
const newData = [...getFieldValue('payList')].map(item => {
const purchasePriceValue = await getFieldValue('purchasePrice');
const orderTypeValue = await getFieldValue('orderType');
const payListValue = await getFieldValue('payList');
const isMateriel = (
orderTypeValue === ORDER_TYPE_INQUIRY_CONTRACT
|| orderTypeValue === ORDER_TYPE_BIDDING_CONTRACT
|| orderTypeValue === ORDER_TYPE_TENDER_CONTRACT
);
const newData = [...payListValue].map(item => {
const refundAmount = item.payTime ? +(new BigNumber(+value).multipliedBy(purchasePriceValue).multipliedBy(new BigNumber(item.payRatio).dividedBy(100))).toFixed(2) : 0;
return {
...item,
refundAmount: item.payTime ? +(new BigNumber(+value).multipliedBy(purchasePriceValue).multipliedBy(new BigNumber(item.payRatio).dividedBy(100))).toFixed(2) : 0,
refundAmount,
};
});
setFieldValue('payList', newData);
if (isMateriel) {
const refundAmount = +(new BigNumber(+value).multipliedBy(purchasePriceValue).toFixed(2));
setFieldValue('refundAmount', refundAmount);
}
});
// 校验退货数量
onFieldInputChange$('returnCount').subscribe(fieldState => {
onFieldInputChange$('returnCount').subscribe(async (fieldState) => {
const { name, value } = fieldState;
// 采购数量
const remainingValue = getFieldValue('remaining');
// 剩余数量
const remainingValue = await getFieldValue('remaining');
setFieldState(
'returnCount',
......
.paneTitle {
padding-left: 6px;
margin-bottom: 24px;
line-height: 14px;
font-size: 14px;
font-weight: 400;
color: #606266;
border-left: 2px solid #00B37A;
}
.payInfo {
&-item {
margin-bottom: 16px;
}
}
\ No newline at end of file
......@@ -2,20 +2,25 @@
* @Author: XieZhiXiong
* @Date: 2020-11-05 17:36:45
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-01-22 11:07:42
* @LastEditTime: 2021-05-13 11:46:56
* @Description: 查看退货数量与退款金额 抽屉
*/
import React from 'react';
import { Drawer, Button } from 'antd';
import NiceForm from '@/components/NiceForm';
import { createFormActions } from '@formily/antd';
import { createAsyncFormActions } from '@formily/antd';
import {
ORDER_TYPE_INQUIRY_CONTRACT,
ORDER_TYPE_BIDDING_CONTRACT,
ORDER_TYPE_TENDER_CONTRACT,
} from '@/constants/order';
import schema from './schema';
import { createEffects } from './effects';
import Stamp from '../Stamp';
import SteamerTicket from './components/SteamerTicket';
import styles from './index.less';
const schemaAction = createFormActions();
const schemaAction = createAsyncFormActions();
export interface PayListItem {
/**
......@@ -62,6 +67,10 @@ export interface OrderInfo {
*/
orderNo: string;
/**
* 订单类型
*/
orderType: number;
/**
* 商品名称
*/
productName: string;
......@@ -108,9 +117,21 @@ export interface OrderInfo {
};
interface ReturnInfoDrawerProps {
/**
* 是否可见
*/
visible: boolean;
/**
* 订单信息
*/
orderInfo: OrderInfo;
/**
* 关闭触发事件
*/
onClose: () => void;
/**
* form 提交触发事件
*/
onSubmit?: (values: { [key: string]: any }) => void;
/**
* 是否是编辑的
......@@ -134,7 +155,7 @@ const ReturnInfoDrawer: React.FC<ReturnInfoDrawerProps> = ({
const handleSubmit = values => {
if (onSubmit) {
const { remaining, ...rest } = values;
const { remaining, orderType, ...rest } = values;
onSubmit(rest);
} else {
onClose();
......@@ -182,7 +203,20 @@ const ReturnInfoDrawer: React.FC<ReturnInfoDrawerProps> = ({
}}
editable={isEdit}
effects={($, actions) => {
const { setFieldState } = actions;
const { orderType } = orderInfo;
const isMateriel = (
orderType === ORDER_TYPE_INQUIRY_CONTRACT
|| orderType === ORDER_TYPE_BIDDING_CONTRACT
|| orderType === ORDER_TYPE_TENDER_CONTRACT
);
createEffects($, actions);
if (isMateriel) {
setFieldState('REPOSIT_TABS', state => {
state.props['x-component-props'].hiddenKeys = ['tab-2']
});
}
}}
onSubmit={handleSubmit}
actions={schemaAction}
......
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2020-11-06 14:20:17
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-05-07 16:44:47
* @LastEditTime: 2021-05-13 11:23:45
* @Description:
*/
import { ISchema } from '@formily/antd';
......@@ -79,10 +79,6 @@ const schema: ISchema = {
addonBefore: '¥ '
},
},
remaining: {
type: 'string',
display: false,
},
returnCount: {
type: 'string',
title: '退货数量',
......@@ -103,6 +99,14 @@ const schema: ISchema = {
},
],
},
remaining: {
type: 'string',
display: false,
},
orderType: {
type: 'string',
display: false,
},
},
},
},
......
......@@ -269,6 +269,7 @@ const ExchangeForm: React.FC<BillsFormProps> = ({
}
);
setOrderTypeValue(rest.orderType);
setDetailInfo({
proofFileList: faultFileList.map(item => normalizeFiledata(item.filePath)),
deliveryAddress: {
......@@ -315,7 +316,6 @@ const ExchangeForm: React.FC<BillsFormProps> = ({
})),
...rest,
});
setOrderTypeValue(rest.orderType);
setGoodsValue(goodsDetailList.map(item => item.orderRecordId));
}
}).finally(() => {
......
......@@ -254,6 +254,7 @@ const RepairForm: React.FC<BillsFormProps> = ({
}
);
setOrderTypeValue(rest.orderType);
setDetailInfo({
...detailInfo,
faultFileList: faultFileList.map(item => normalizeFiledata(item.filePath)),
......@@ -271,7 +272,6 @@ const RepairForm: React.FC<BillsFormProps> = ({
,
...rest,
});
setOrderTypeValue(rest.orderType);
}
}).finally(() => {
setInfoLoading(false);
......
......@@ -118,6 +118,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
payWayTxt: item.payWayName,
channelTxt: item.channelName,
})),
orderType: detailInfo?.orderType,
});
setVisibleReturnInfo(true);
};
......
......@@ -262,6 +262,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
returnBatch,
returnId,
roleId,
refundList,
...rest
} = res.data;
......@@ -303,6 +304,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
...rest,
});
setOrderTypeValue(rest.orderType);
setReturnGoodsList(goodsDetailList.map(item => ({
...item,
remaining: item.purchaseCount || 0, // 可退货数量,这里取 采购数量判断即可
......@@ -315,7 +317,6 @@ const ReturnForm: React.FC<BillsFormProps> = ({
associated: !item.materielId ? '' : `${item.productId}/${item.productName}/${item.category}/${item.brand}`,
materielNameAndType: `${item.materielName || ''}${item.materielType ? '/' + item.materielType : ''}`,
})));
setOrderTypeValue(rest.orderType);
setGoodsValue(goodsDetailList.map(item => item.orderRecordId));
}
}).finally(() => {
......@@ -473,7 +474,6 @@ const ReturnForm: React.FC<BillsFormProps> = ({
extraData,
needReturnName,
isNeedReturn,
refundAmount,
associated,
materielNameAndType,
...rest
......@@ -623,6 +623,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
payList: item.extraData.payList,
remaining: item.extraData.remaining,
returnReason: item.extraData.returnReason,
orderType: orderTypeValue,
});
setVisibleReturnInfoDrawer(true)
};
......
......@@ -123,6 +123,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
payWayTxt: item.payWayName,
channelTxt: item.channelName,
})),
orderType: detailInfo?.orderType,
});
setVisibleReturnInfo(true);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment