Commit bc901a26 authored by XieZhiXiong's avatar XieZhiXiong

feat: 对接售后支付信息相关

parent 813a0f37
......@@ -9,16 +9,12 @@ import React from 'react';
import { Drawer, Button, Pagination, message } from 'antd';
import { createFormActions } from '@formily/antd';
import moment from 'moment';
import BigNumber from 'bignumber.js';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import {
PAYWAY,
PAY_CHANNEL,
} from '@/constants/payment';
import {
PayOutWorkState,
} from '@/constants/order';
import NiceForm from '@/components/NiceForm';
import NestTable from '@/components/NestTable';
import { goodItem, OrderListRes } from './interface';
......
......@@ -2,13 +2,14 @@
* @Author: XieZhiXiong
* @Date: 2020-11-05 17:36:45
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-25 15:47:51
* @LastEditTime: 2021-08-26 15:34:25
* @Description: 查看退货数量与退款金额 抽屉
*/
import React, { useEffect, useState } from 'react';
import { Drawer, Button, Spin } from 'antd';
import NiceForm from '@/components/NiceForm';
import { createAsyncFormActions, FormEffectHooks } from '@formily/antd';
import BigNumber from 'bignumber.js';
import { PublicApi } from '@/services/api';
import {
ORDER_TYPE_INQUIRY_CONTRACT,
......@@ -20,118 +21,148 @@ import { createEffects } from './effects';
import Stamp from '../Stamp';
import SteamerTicket from './components/SteamerTicket';
import styles from './index.less';
import moment from 'moment';
const schemaAction = createAsyncFormActions();
const {
onFormMount$,
} = FormEffectHooks;
export interface PayListItem {
export type PayListItem = {
/**
* 支付id
*/
payId: number,
/**
* 支付次数
*/
payCount: number,
payCount: number,
/**
* 支付环节
*/
payNode: string,
payNode: string,
/**
* 支付比例
*/
payRatio: number,
payRatio: number,
/**
* 支付金额
*/
payAmount: number,
payAmount: number,
/**
* 支付方式
*/
payWay: string,
payWay: number,
/**
* 支付方式名称
*/
payWayName: string,
/**
* 支付渠道
*/
channel: string,
channel: number,
/**
* 支付时间
* 支付渠道名称
*/
payTime: string,
channelName: string,
/**
* 退款金额
*/
refundAmount: number,
};
refundAmount: number,
/**
* 支付时间
*/
payTime: string,
/**
* 支付配置:1.平台代收2.会员直接到账
*/
payRuleId: number,
/**
* 支付外部状态
* 这个字段现在没用了,支付信息返回的都是 确认到账 的数据,后台说写死
*/
externalState: number,
/**
* 第三方支付成功返回的code
*/
transactionPayId: string,
}
export interface OrderInfo {
export interface ReturnApplyInfo {
/**
* 列表索引
*/
index?: number;
/**
* 订单号
*/
orderNo: string;
/**
* 订单id
*/
orderId: number;
orderId: number,
/**
* 订单类型
* 订单
*/
orderType: number;
orderNo: string,
/**
* 商品名称
*/
productName: string;
productName: string,
/**
* 品类
*/
category: string;
category: string,
/**
* 品
* 品
*/
brand: string;
brand: string,
/**
* 单位
*/
unit: string;
unit: string,
/**
* 采购数量
*/
purchaseCount: string;
purchaseCount: number,
/**
* 采购单价
*/
purchasePrice: string;
purchasePrice: number,
/**
* 采购金额
*/
purchaseAmount: string;
purchaseAmount: number,
/**
* 退货数量
*/
returnCount: number,
/**
* 剩余可退数量
*/
remaining?: number,
/**
* 支付记录
* 订单类型
*/
payList: PayListItem[];
orderType?: number,
/**
* 剩余可退货数量
* 支付信息
*/
remaining?: number;
payList?: PayListItem[],
/**
* 退款数量
* 总的退款金额
*/
returnCount?: number | string;
refundAmount?: number,
/**
* 退款理由
*/
returnReason?: string;
};
returnReason?: string,
}
interface ReturnInfoDrawerProps {
/**
* 是否可见
*/
visible: boolean;
/**
* 订单信息
* 申请信息
*/
orderInfo: OrderInfo;
applyInfo: ReturnApplyInfo;
/**
* 关闭触发事件
*/
......@@ -147,66 +178,83 @@ interface ReturnInfoDrawerProps {
};
const ReturnInfoDrawer: React.FC<ReturnInfoDrawerProps> = ({
visible = false,
orderInfo,
onClose,
onSubmit,
isEdit = false,
visible = false,
applyInfo,
onClose,
onSubmit,
isEdit = false,
}) => {
const [innerApplyInfo, setInnerApplyInfo] = useState<ReturnApplyInfo | null>(null);
const [payInfoLoading, setPayInfoLoading] = useState(false);
console.log('orderInfo', orderInfo);
const { orderType } = (innerApplyInfo || {});
const isMateriel = (
orderType === ORDER_TYPE_INQUIRY_CONTRACT
|| orderType === ORDER_TYPE_BIDDING_CONTRACT
|| orderType === ORDER_TYPE_TENDER_CONTRACT
);
const getPayInfo = () => {
if (!orderInfo || !orderInfo.orderId) {
const getPayInfo = async () => {
if (!applyInfo || !applyInfo.orderId) {
return;
}
let payList = applyInfo.payList || [];
setPayInfoLoading(true);
PublicApi.getOrderCommonAfterSalePaymentFind({
orderId: `${orderInfo.orderId}`,
}).then((res) => {
console.log('res', res);
}).finally(() => {
setPayInfoLoading(false);
try {
// 编辑状态才请求支付信息,否则默认取申请信息里边的支付信息
if (isEdit) {
const res = await PublicApi.getOrderCommonAfterSalePaymentFind({
orderId: `${applyInfo.orderId}`,
});
if (res.code === 1000) {
payList = res.data.map((item) => ({
payId: item.paymentId,
payCount: item.batchNo,
payNode: item.payNode,
payRatio: item.payRate * 100,
payAmount: item.payAmount,
payWay: item.payType,
payWayName: item.payTypeName,
channel: item.payChannel,
channelName: item.payChannelName,
refundAmount: +(new BigNumber(+applyInfo.remaining).multipliedBy(applyInfo.purchasePrice).multipliedBy(new BigNumber(item.payRate * 100).dividedBy(100))).toFixed(2),
payTime: item.payTime,
payRuleId: item.fundMode,
externalState: 3,
transactionPayId: '123', // 微信 或 其他第三方支付返回的 code,原路退款需要
}));
}
}
} catch (error) {
console.warn(error);
}
setPayInfoLoading(false);
if (payList.length) {
schemaAction.setFieldState('REPOSIT_TABS', state => {
state.props['x-component-props'].hiddenKeys = [];
});
}
setInnerApplyInfo({
...applyInfo,
payList,
returnCount: applyInfo.returnCount || applyInfo.remaining, // 默认赋值
});
};
useEffect(() => {
getPayInfo();
}, [orderInfo]);
useEffect(() => {
const { setFieldState } = schemaAction;
const { orderType } = (orderInfo || {});
const isMateriel = (
orderType === ORDER_TYPE_INQUIRY_CONTRACT
|| orderType === ORDER_TYPE_BIDDING_CONTRACT
|| orderType === ORDER_TYPE_TENDER_CONTRACT
);
if (
(
orderInfo
&& (
!orderInfo.payList
|| !orderInfo.payList.length
)
)
|| isMateriel
) {
setFieldState('REPOSIT_TABS', state => {
state.props['x-component-props'].hiddenKeys = ['tab-2'];
});
if (!isMateriel) {
getPayInfo();
}
}, [orderInfo]);
}, [applyInfo]);
const handleClose = () => {
if (onClose) {
onClose();
}
};
const handleSubmit = values => {
const handleSubmit = (values: ReturnApplyInfo) => {
if (onSubmit) {
const { remaining, orderType, ...rest } = values;
onSubmit(rest);
......@@ -229,15 +277,15 @@ const ReturnInfoDrawer: React.FC<ReturnInfoDrawerProps> = ({
textAlign: 'right',
}}
>
<Button
onClick={handleClose}
<Button
onClick={handleClose}
style={{ marginRight: 8 }}
>
{onSubmit ? '取消' : '关闭'}
</Button>
{onSubmit && (
<Button
onClick={() => schemaAction.submit()}
<Button
onClick={() => schemaAction.submit()}
type="primary"
>
确定
......@@ -248,12 +296,12 @@ const ReturnInfoDrawer: React.FC<ReturnInfoDrawerProps> = ({
destroyOnClose
>
<Spin spinning={payInfoLoading}>
<NiceForm
initialValues={orderInfo}
<NiceForm
value={innerApplyInfo}
previewPlaceholder=" "
components={{
Stamp,
SteamerTicket,
Stamp,
SteamerTicket,
}}
editable={isEdit}
effects={($, actions) => {
......
......@@ -15,7 +15,8 @@ const schema: ISchema = {
type: 'object',
'x-component': 'tab',
'x-component-props': {
tabPosition: 'left',
tabPosition: 'left',
hiddenKeys: ['tab-2'],
},
properties: {
'tab-1': {
......
......@@ -34,7 +34,7 @@ import StatusTag from '@/components/StatusTag';
import { EditableColumns } from '@/components/PolymericTable/interface';
import DescProgress from '@/components/DescProgress';
import AuditProcess from '@/components/AuditProcess';
import ReturnInfoDrawer, { OrderInfo } from '../../../components/ReturnInfoDrawer';
import ReturnInfoDrawer, { ReturnApplyInfo } from '../../../components/ReturnInfoDrawer';
import { OuterHistoryData, InnerHistoryData } from '../../../components/FlowRecords';
import {
RETURN_OUTER_STATUS_TAG_MAP,
......@@ -98,10 +98,11 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
const [returnGoodsLoading, setReturnGoodsLoading] = useState(false);
const [infoLoading, setInfoloading] = useState(false);
const [visibleOrderDetial, setVisibleReturnInfo] = useState<boolean>(false);
const [orderInfo, setOrderInfo] = useState<OrderInfo>(null);
const [applyInfo, setApplyInfo] = useState<ReturnApplyInfo>(null);
const handleCheckOrderDetial = record => {
setOrderInfo({
setApplyInfo({
orderId: record.orderId,
orderNo: record.orderNo,
productName: record.productName,
category: record.category,
......@@ -663,7 +664,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
<ReturnInfoDrawer
visible={visibleOrderDetial}
orderInfo={orderInfo}
applyInfo={applyInfo}
onClose={() => setVisibleReturnInfo(false)}
/>
</AnchorPage>
......
......@@ -21,7 +21,7 @@ import NiceForm from '@/components/NiceForm';
import GoodsDrawer from '../../../../components/GoodsDrawer';
import { OrderListRes } from '../../../../components/GoodsDrawer/interface';
import AddressFormItem from '../../../../components/AddressFormItem';
import ReturnInfoDrawer, { OrderInfo } from '../../../../components/ReturnInfoDrawer';
import ReturnInfoDrawer, { ReturnApplyInfo } from '../../../../components/ReturnInfoDrawer';
import { addSchema } from './schema';
import { createEffects } from './effects';
import {
......@@ -190,7 +190,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
const [unsaved, setUnsaved] = useState(false);
const [infoLoading, setInfoLoading] = useState(false);
const [submitLoading, setSubmitLoading] = useState(false);
const [orderInfo, setOrderInfo] = useState<OrderInfo>(null);
const [applyInfo, setApplyInfo] = useState<ReturnApplyInfo>(null);
const [visibleGoodsDrawer, setVisibleGoodsDrawer] = useState(false);
const [visibleReturnInfoDrawer, setVisibleReturnInfoDrawer] = useState(false);
const [goodsValue, setGoodsValue] = useState([]);
......@@ -410,7 +410,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
remaining: item.purchaseCount || 0, // 可退货数量,这里取 采购数量判断即可
extraData: {
returnReason: item.returnReason,
payList: (item.payList || []).map(({ payId, ...rest }) => ({ ...rest, id: payId })),
payList: item.payList || [],
id: item.orderRecordId,
taskTypeKey,
orderId: item.orderId,
......@@ -599,13 +599,11 @@ const ReturnForm: React.FC<BillsFormProps> = ({
channelName,
payTime,
payWayName,
id,
...payItemRest
} = item;
return {
...payItemRest,
payTime: +new Date(payTime),
payId: id,
};
}),
})),
......@@ -672,8 +670,6 @@ const ReturnForm: React.FC<BillsFormProps> = ({
const preValues = addSchemaAction.getFieldValue('returnGoodsList');
const value = [];
console.log('values', values)
values.forEach(item => {
const atom = {
id: item.id,
......@@ -731,7 +727,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
const returnGoodsListValue = getFieldValue('returnGoodsList');
const item = returnGoodsListValue[index];
setOrderInfo({
setApplyInfo({
index,
...item,
payList: item.extraData.payList,
......@@ -744,7 +740,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
const handleReturnInfoSubmit = values => {
const { getFieldValue, setFieldValue, setFieldState } = addSchemaAction;
const { index } = orderInfo;
const { index } = applyInfo;
const newData = [...getFieldValue('returnGoodsList')];
newData.splice(index, 1, {
...newData[index],
......@@ -873,7 +869,7 @@ const ReturnForm: React.FC<BillsFormProps> = ({
<ReturnInfoDrawer
visible={visibleReturnInfoDrawer}
orderInfo={orderInfo}
applyInfo={applyInfo}
onClose={() => setVisibleReturnInfoDrawer(false)}
onSubmit={handleReturnInfoSubmit}
isEdit
......
......@@ -37,7 +37,7 @@ import AuditProcess from '@/components/AuditProcess';
import { EditableColumns } from '@/components/PolymericTable/interface';
import DescProgress from '@/components/DescProgress';
import { Values as ReturnAddressValues } from '../../../components/ReturnAddressInfo';
import ReturnInfoDrawer, { OrderInfo } from '../../../components/ReturnInfoDrawer';
import ReturnInfoDrawer, { ReturnApplyInfo } from '../../../components/ReturnInfoDrawer';
import { OuterHistoryData, InnerHistoryData } from '../../../components/FlowRecords';
import {
RETURN_OUTER_STATUS_TAG_MAP,
......@@ -103,10 +103,11 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
const [infoLoading, setInfoloading] = useState(false);
const [visibleOrderDetial, setVisibleReturnInfo] = useState<boolean>(false);
const [returnAddress, setReturnAddress] = useState<ReturnAddressValues>(null);
const [orderInfo, setOrderInfo] = useState<OrderInfo>(null);
const [applyInfo, setApplyInfo] = useState<ReturnApplyInfo>(null);
const handleCheckOrderDetial = record => {
setOrderInfo({
setApplyInfo({
orderId: record.orderId,
orderNo: record.orderNo,
productName: record.productName,
category: record.category,
......@@ -699,7 +700,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
<ReturnInfoDrawer
visible={visibleOrderDetial}
orderInfo={orderInfo}
applyInfo={applyInfo}
onClose={() => setVisibleReturnInfo(false)}
/>
</AnchorPage>
......
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