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

附件上传逻辑修改

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