Commit 524995ac authored by FE-安焕焕's avatar FE-安焕焕 👣

附件上传逻辑修改

parent f3126363
...@@ -14,20 +14,17 @@ export default props => { ...@@ -14,20 +14,17 @@ export default props => {
const picUpload = useRef(); const picUpload = useRef();
const uploadProps = { const uploadProps = {
name: 'file', name: 'file',
async customRequest({ file, onSuccess }) { beforeUpload(file) {
const result = await uploadFile(file, settlementNo); setFileList([file]);
if (result.businessCode === '0000') { return false;
notification.success({ message: '导入成功' });
onSuccess(file);
setFileList([...fileList, file]);
}
},
accept: '.xlsx',
showUploadList: {
showRemoveIcon: false,
}, },
accept: '.xlsx,.xls,.csv',
showUploadList: true,
maxCount: 1, maxCount: 1,
fileList, fileList,
onRemove() {
setFileList([]);
},
}; };
const initPicUpload = () => { const initPicUpload = () => {
if (picUpload?.current?.clearFileList) { if (picUpload?.current?.clearFileList) {
...@@ -38,9 +35,13 @@ export default props => { ...@@ -38,9 +35,13 @@ export default props => {
initPicUpload(); initPicUpload();
setFileList([]); setFileList([]);
}, [visible]); }, [visible]);
const uploadFn = async () => { const uploadPicFn = async () => {
// 上传图片的接口 // 上传图片的接口
const upLoadFileList = picUpload?.current?.getFileList?.(); const upLoadFileList = picUpload?.current?.getFileList?.();
if (!upLoadFileList.length) {
notification.warning({ message: '请先上传图片' });
return;
}
const data = await uploadPic({ const data = await uploadPic({
imgUrl: upLoadFileList.join(','), imgUrl: upLoadFileList.join(','),
settlementNo, settlementNo,
...@@ -50,6 +51,24 @@ export default props => { ...@@ -50,6 +51,24 @@ export default props => {
initPicUpload(); initPicUpload();
} }
}; };
const uploadFileFn = async () => {
if (!fileList.length) {
notification.warning({ message: '请先上传附件' });
return;
}
const result = await uploadFile(fileList[0], settlementNo);
if (result.businessCode === '0000') {
notification.success({ message: '导入成功' });
setFileList([]);
}
};
const uploadFn = () => {
if (tabValue === '1') {
uploadPicFn();
} else {
uploadFileFn();
}
};
const changeTab = tabV => { const changeTab = tabV => {
setTabValue(tabV); setTabValue(tabV);
}; };
...@@ -57,7 +76,7 @@ export default props => { ...@@ -57,7 +76,7 @@ export default props => {
<Modal title="上传发票" visible={visible} footer={null} onCancel={props.onCancel} width="700px"> <Modal title="上传发票" visible={visible} footer={null} onCancel={props.onCancel} width="700px">
<Tabs defaultActiveKey="1" className={styles.tab} onChange={changeTab} activeKey={tabValue}> <Tabs defaultActiveKey="1" className={styles.tab} onChange={changeTab} activeKey={tabValue}>
<TabPane tab="上传凭证" key="1"> <TabPane tab="上传凭证" key="1">
<UploadC ref={picUpload} accept=".png,.jpg" /> <UploadC ref={picUpload} accept=".png,.jpg,.jpeg,.pdf" />
</TabPane> </TabPane>
<TabPane tab="上传附件" key="2"> <TabPane tab="上传附件" key="2">
<a <a
...@@ -74,11 +93,9 @@ export default props => { ...@@ -74,11 +93,9 @@ export default props => {
</Dragger> </Dragger>
</TabPane> </TabPane>
</Tabs> </Tabs>
{tabValue === '1' && ( <Button type="primary" onClick={uploadFn} className={styles.logBtn}>
<Button type="primary" onClick={uploadFn} className={styles.logBtn}> {tabValue === '1' ? '确定上传图片' : '确定上传附件'}
确定上传 </Button>
</Button>
)}
</Modal> </Modal>
); );
}; };
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