|  |  |  | 
|---|
|  |  |  | import { useEffect, useState } from 'react'; | 
|---|
|  |  |  | import { useEffect, useState, createContext, useContext } from 'react'; | 
|---|
|  |  |  | import { Box, CircularProgress, Stack, Typography } from '@mui/material'; | 
|---|
|  |  |  | import Alert from '@mui/material/Alert'; | 
|---|
|  |  |  | import Dialog from '@mui/material/Dialog'; | 
|---|
|  |  |  | 
|---|
|  |  |  | Form, | 
|---|
|  |  |  | Toolbar, | 
|---|
|  |  |  | useRefresh, | 
|---|
|  |  |  | useTranslate | 
|---|
|  |  |  | useTranslate, | 
|---|
|  |  |  | useNotify | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { Link } from 'react-router-dom'; | 
|---|
|  |  |  | import DialogCloseButton from './DialogCloseButton'; | 
|---|
|  |  |  | import { usePapaParse } from './usePapaParse'; | 
|---|
|  |  |  | import MatnrList from '../basicInfo/matnr/MatnrList'; | 
|---|
|  |  |  | import request from '@/utils/request' | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10 }) => { | 
|---|
|  |  |  | const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10, value, parmas = {} }) => { | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { processBatch } = useCodeImport(); | 
|---|
|  |  |  | // const { processBatch } = useCodeImport(); | 
|---|
|  |  |  | const { importer, parseCsv, reset } = usePapaParse({ | 
|---|
|  |  |  | batchSize: onceBatch, | 
|---|
|  |  |  | processBatch, | 
|---|
|  |  |  | // processBatch, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const [file, setFile] = useState(null); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | if (importer.state === 'complete') { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!file) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const form = new FormData(); | 
|---|
|  |  |  | for (const key in parmas) { | 
|---|
|  |  |  | if (parmas.hasOwnProperty(key)) { | 
|---|
|  |  |  | form.append(key, parmas[key]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | form.append('file', file); | 
|---|
|  |  |  | const { data: { code, data, msg } } = await request.post(`/${value}/import`, form) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | parseCsv(file); | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | handleClose() | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleClose = () => { | 
|---|
|  |  |  | reset(); | 
|---|
|  |  |  | 
|---|
|  |  |  | <Alert | 
|---|
|  |  |  | severity="info" | 
|---|
|  |  |  | action={ | 
|---|
|  |  |  | <Button | 
|---|
|  |  |  | component={Link} | 
|---|
|  |  |  | label="common.action.import.download" | 
|---|
|  |  |  | color="info" | 
|---|
|  |  |  | to={importTemp} | 
|---|
|  |  |  | download={'import_template.csv'} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | <MatnrList.Context.Consumer> | 
|---|
|  |  |  | {context => ( | 
|---|
|  |  |  | <Button | 
|---|
|  |  |  | component={Link} | 
|---|
|  |  |  | onClick={() => { | 
|---|
|  |  |  | downloadTemplate(context) | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | label="common.action.import.download" | 
|---|
|  |  |  | color="info" | 
|---|
|  |  |  | to={importTemp} | 
|---|
|  |  |  | download={'import_template.csv'} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </MatnrList.Context.Consumer> | 
|---|
|  |  |  | } | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {translate('common.action.import.msg')} | 
|---|
|  |  |  | </Alert> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <FileInput | 
|---|
|  |  |  | source="csv" | 
|---|
|  |  |  | label="CSV File" | 
|---|
|  |  |  | accept={{ 'text/csv': ['.csv'] }} | 
|---|
|  |  |  | source="xlsx" | 
|---|
|  |  |  | label="Xlsx File" | 
|---|
|  |  |  | accept={{ 'text/xlsx': ['.xls', '.xlsx'] }} | 
|---|
|  |  |  | onChange={handleFileChange} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <FileField source="src" title="title" /> | 
|---|
|  |  |  | 
|---|
|  |  |  | </Dialog> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | {/**下载打印模板,传入type类型,调用下载模板接口 */ } | 
|---|
|  |  |  | const downloadTemplate = (type) => { | 
|---|
|  |  |  | // 下载物料模板 | 
|---|
|  |  |  | if (type != undefined && type == 'matnr') { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | console.log('======>'); | 
|---|
|  |  |  | console.log(type); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function millisecondsToTime(ms) { | 
|---|
|  |  |  | var seconds = Math.floor((ms / 1000) % 60); | 
|---|