Commit 7769b84c authored by XieZhiXiong's avatar XieZhiXiong

chore: 抽离上传凭证弹窗

parent e565f06b
...@@ -19,11 +19,10 @@ import { PAY_CHANNEL_WECHAT } from '@/constants'; ...@@ -19,11 +19,10 @@ import { PAY_CHANNEL_WECHAT } from '@/constants';
import MellowCard from '@/components/MellowCard'; import MellowCard from '@/components/MellowCard';
import { Pie } from '@/components/Charts'; import { Pie } from '@/components/Charts';
import StatusTag from '@/components/StatusTag'; import StatusTag from '@/components/StatusTag';
import NiceForm from '@/components/NiceForm';
import { uploadVoucherModalSchema } from './schema';
import TradeRecord, { RecordParams, RecordRes } from '../TradeRecord'; import TradeRecord, { RecordParams, RecordRes } from '../TradeRecord';
import WxPayModal from '../WxPayModal'; import WxPayModal from '../WxPayModal';
import RefundModal from '../RefundModal'; import RefundModal from '../RefundModal';
import UploadVoucherModal from '../UploadVoucherModal';
import styles from './index.less'; import styles from './index.less';
const uploadVoucherFormActions = createFormActions(); const uploadVoucherFormActions = createFormActions();
...@@ -111,12 +110,6 @@ interface IntroduceRowProps { ...@@ -111,12 +110,6 @@ interface IntroduceRowProps {
interface IntroduceRowState { interface IntroduceRowState {
billId: number; billId: number;
billInfo: BillDetailData | null; billInfo: BillDetailData | null;
bankAccount: {
id: number,
name: string,
bankAccount: string,
bankDeposit: string,
},
visibleRecord: boolean; visibleRecord: boolean;
visibleRepayment: boolean; visibleRepayment: boolean;
visibleUploadVoucher: boolean; visibleUploadVoucher: boolean;
...@@ -141,12 +134,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -141,12 +134,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
this.state = { this.state = {
billId: 0, billId: 0,
billInfo: null, billInfo: null,
bankAccount: {
id: 0,
name: '',
bankAccount: '',
bankDeposit: '',
},
visibleRecord: false, visibleRecord: false,
visibleRepayment: false, visibleRepayment: false,
visibleUploadVoucher: false, visibleUploadVoucher: false,
...@@ -181,30 +168,12 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -181,30 +168,12 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
id: `${id}`, id: `${id}`,
}).then(res => { }).then(res => {
this.setState({ billInfo: res }); this.setState({ billInfo: res });
this.getSettleAccountsGetMemberAccountConfig(res.memberId, res.memberRoleId);
}).finally(() => { }).finally(() => {
this.setState({ billInfoLoading: false }); this.setState({ billInfoLoading: false });
}); });
} }
}; };
// 获取对公账户信息
getSettleAccountsGetMemberAccountConfig = (memberId: number, memberRoleId: number) => {
if (!memberId || !memberRoleId) {
return;
}
PublicApi.getSettleAccountsGetMemberAccountConfig({
memberId: `${memberId}`,
roleId: `${memberRoleId}`,
}).then(res => {
if (res.code === 1000) {
this.setState({
bankAccount: res.data,
});
}
});
};
// 根据下拉框数据改变设置默认选中第一项,并获取相应的账单详情 // 根据下拉框数据改变设置默认选中第一项,并获取相应的账单详情
initialize = (options) => { initialize = (options) => {
if (options && options.length) { if (options && options.length) {
...@@ -297,17 +266,7 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -297,17 +266,7 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
handleUploadVoucherSubmit = values => { handleUploadVoucherSubmit = values => {
const { payProveList = [] } = values; const { payProveList = [] } = values;
const { repaymentValues, billId, bankAccount } = this.state; const { repaymentValues, billId } = this.state;
if (
!bankAccount ||
!bankAccount.id ||
!bankAccount.bankAccount ||
!bankAccount.bankDeposit
) {
message.error('没有还款账户完整相关信息,无法还款');
return;
}
this.setState({ uploadVoucherSubmitLoading: true }); this.setState({ uploadVoucherSubmitLoading: true });
PublicApi.postPayCreditApplyCreditRepay({ PublicApi.postPayCreditApplyCreditRepay({
...@@ -328,13 +287,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -328,13 +287,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
}); });
}; };
beforeUploadVoucher = file => {
if (file.size / 1024 > 200) {
message.warning('图片大小超过200K');
return Promise.reject();
}
};
getRecordList = params => { getRecordList = params => {
const { billId } = this.state; const { billId } = this.state;
const { fetchBillRecordList } = this.props; const { fetchBillRecordList } = this.props;
...@@ -409,7 +361,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -409,7 +361,6 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
billInfoLoading, billInfoLoading,
visibleRecord, visibleRecord,
billInfo, billInfo,
bankAccount,
visibleRepayment, visibleRepayment,
visibleUploadVoucher, visibleUploadVoucher,
repaymentSubmitLoading, repaymentSubmitLoading,
...@@ -588,29 +539,14 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState> ...@@ -588,29 +539,14 @@ class IntroduceRow extends React.Component<IntroduceRowProps, IntroduceRowState>
confirmLoading={repaymentSubmitLoading} confirmLoading={repaymentSubmitLoading}
/> />
<Modal <UploadVoucherModal
title="上传支付凭证"
width={576}
visible={visibleUploadVoucher} visible={visibleUploadVoucher}
confirmLoading={uploadVoucherSubmitLoading} confirmLoading={uploadVoucherSubmitLoading}
onOk={() => uploadVoucherFormActions.submit()} memberId={billInfo?.memberId}
memberRoleId={billInfo?.memberRoleId}
onCancel={() => this.setState({ visibleUploadVoucher: false })} onCancel={() => this.setState({ visibleUploadVoucher: false })}
destroyOnClose
>
<NiceForm
previewPlaceholder=""
initialValues={bankAccount}
effects={($, { setFieldState }) => {
}}
expressionScope={{
beforeUpload: this.beforeUploadVoucher,
}}
actions={uploadVoucherFormActions}
schema={uploadVoucherModalSchema}
onSubmit={this.handleUploadVoucherSubmit} onSubmit={this.handleUploadVoucherSubmit}
/> />
</Modal>
<WxPayModal <WxPayModal
{...WxPayModalPros} {...WxPayModalPros}
......
/*
* @Author: XieZhiXiong
* @Date: 2021-01-13 13:46:08
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-01-13 13:46:22
* @Description: 上传凭证弹窗
*/
import React, { useState, useEffect } from 'react';
import { Modal, message } from 'antd';
import { createFormActions } from '@formily/antd';
import NiceForm from '@/components/NiceForm';
import { PublicApi } from '@/services/api';
import { uploadVoucherModalSchema } from './schema';
import styles from './index.less';
const uploadVoucherFormActions = createFormActions();
interface UploadVoucherModalProps {
/**
* 是否可见
*/
visible: boolean;
/**
* 确认按钮loading
*/
confirmLoading: boolean;
/**
* 会员id
*/
memberId: number;
/**
* 会员角色
*/
memberRoleId: number;
/**
* 提交事件
*/
onSubmit: (values: any) => void;
/**
* 隐藏事件
*/
onCancel: () => void,
}
interface BankAccountData {
id: number,
name: string,
bankAccount: string,
bankDeposit: string,
}
const UploadVoucherModal: React.FC<UploadVoucherModalProps> = (props: UploadVoucherModalProps) => {
const {
visible,
confirmLoading,
memberId,
memberRoleId,
onSubmit,
onCancel,
} = props;
const [bankAccount, setBankAccount] = useState<BankAccountData>({
id: 0,
name: '',
bankAccount: '',
bankDeposit: '',
});
const [loading, setLoading] = useState(false);
// 获取对公账户信息
const getSettleAccountsGetMemberAccountConfig = (memberId: number, memberRoleId: number) => {
if (!memberId || !memberRoleId || loading) {
return;
}
setLoading(true);
PublicApi.getSettleAccountsGetMemberAccountConfig({
memberId: `${memberId}`,
roleId: `${memberRoleId}`,
}).then(res => {
if (res.code === 1000) {
setBankAccount(res.data);
}
}).finally(() => {
setLoading(false);
});
};
useEffect(() => {
if (visible) {
getSettleAccountsGetMemberAccountConfig(memberId, memberRoleId);
}
}, [visible]);
const beforeUploadVoucher = file => {
if (file.size / 1024 > 200) {
message.warning('图片大小超过200K');
return Promise.reject();
}
};
const handleUploadVoucherSubmit = values => {
if (onSubmit) {
if (
!bankAccount ||
!bankAccount.id ||
!bankAccount.bankAccount ||
!bankAccount.bankDeposit
) {
message.error('没有还款账户完整相关信息,无法还款');
return;
}
onSubmit(values);
}
};
return (
<Modal
title="上传支付凭证"
width={576}
visible={visible}
confirmLoading={confirmLoading}
onOk={() => uploadVoucherFormActions.submit()}
onCancel={onCancel}
destroyOnClose
>
<NiceForm
previewPlaceholder=""
initialValues={bankAccount}
effects={($, { setFieldState }) => {
}}
expressionScope={{
beforeUpload: beforeUploadVoucher,
}}
actions={uploadVoucherFormActions}
schema={uploadVoucherModalSchema}
onSubmit={handleUploadVoucherSubmit}
/>
</Modal>
);
};
export default UploadVoucherModal;
/*
* @Author: XieZhiXiong
* @Date: 2021-01-13 14:01:40
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-01-13 14:01:41
* @Description:
*/
import { ISchema } from '@formily/antd'; import { ISchema } from '@formily/antd';
import { UPLOAD_TYPE } from '@/constants'; import { UPLOAD_TYPE } from '@/constants';
......
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