Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

253 строки
9.8 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  13. import Loadable from 'components/Loadable';
  14. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  15. import MainCard from 'components/MainCard';
  16. const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
  17. const GazetteIssueTable = Loadable(React.lazy(() => import('./DataGrid')))
  18. const BackgroundHead = {
  19. backgroundImage: `url(${titleBackgroundImg})`,
  20. width: '100%',
  21. height: '100%',
  22. backgroundSize: 'contain',
  23. backgroundRepeat: 'no-repeat',
  24. backgroundColor: '#0C489E',
  25. backgroundPosition: 'right'
  26. }
  27. import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst";
  28. import {ThemeProvider} from "@emotion/react";
  29. import { dateStr_Year } from "utils/DateUtils";
  30. import { notifySaveSuccess } from 'utils/CommonFunction';
  31. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const Index = () => {
  33. const [record, setRecord] = React.useState([]);
  34. const [comboData, setComboData] = React.useState([]);
  35. const [onReady, setOnReady] = React.useState(false);
  36. const [onSearchReady, setOnSearchReady] = React.useState(false);
  37. // const navigate = useNavigate()
  38. const [searchCriteria, setSearchCriteria] = React.useState({
  39. year: dateStr_Year(new Date()),
  40. // dateFrom: DateUtils.dateStr(new Date().setDate(new Date().getDate()-14)),
  41. });
  42. const [attachments, setAttachments] = React.useState([]);
  43. const [waitImport, setWaitImport] = React.useState(false);
  44. const [waitDownload, setWaitDownload] = React.useState(false);
  45. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  46. const [warningText, setWarningText] = React.useState("");
  47. React.useEffect(() => {
  48. // console.log(searchCriteria)
  49. setOnSearchReady(false)
  50. loadForm();
  51. }, [searchCriteria]);
  52. function loadForm() {
  53. HttpUtils.get({
  54. url: UrlUtils.GET_ISSUE,
  55. params: searchCriteria,
  56. onSuccess: (responseData) => {
  57. // console.log(comboData)
  58. setRecord(responseData);
  59. if (comboData.length == 0) {
  60. loadCombo();
  61. }else{
  62. setOnSearchReady(true)
  63. }
  64. }
  65. });
  66. }
  67. function loadCombo() {
  68. HttpUtils.get({
  69. url: UrlUtils.GET_ISSUE_YEAR_COMBO,
  70. onSuccess: (responseData) => {
  71. let combo = responseData;
  72. setComboData(combo);
  73. setOnReady(true);
  74. setOnSearchReady(true)
  75. }
  76. });
  77. }
  78. function applySearch(input) {
  79. setSearchCriteria(input);
  80. }
  81. React.useEffect(() => {
  82. if (attachments.length > 0) {
  83. importHoliday();
  84. }
  85. }, [attachments]);
  86. const readFile = (event) => {
  87. let file = event.target.files[0];
  88. if (file) {
  89. if (!file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")) {
  90. setWarningText("Please upload a valid file (File format: .xlsx).");
  91. setIsWarningPopUp(true);
  92. document.getElementById("uploadFileBtn").value = "";
  93. return;
  94. }
  95. file['id'] = attachments.length;
  96. setAttachments([
  97. ...attachments,
  98. file
  99. ]);
  100. document.getElementById("uploadFileBtn").value = "";
  101. }
  102. }
  103. const doExport=()=>{
  104. setWaitDownload(true)
  105. HttpUtils.fileDownload({
  106. url: UrlUtils.GET_ISSUE_LIST,
  107. onResponse: () => {
  108. setTimeout(()=> setWaitDownload(false), 500)
  109. }
  110. });
  111. }
  112. const importHoliday = () => {
  113. setWaitImport(true);
  114. if (!attachments || attachments.length <= 0) {
  115. setWarningText("Please upload file.");
  116. setSaving(false);
  117. return;
  118. }
  119. HttpUtils.postWithFiles({
  120. url: UrlUtils.POST_ISSUE_FILE,
  121. files: attachments,
  122. onSuccess: () => {
  123. notifySaveSuccess()
  124. setWaitImport(false);
  125. setAttachments([]);
  126. loadForm();
  127. }
  128. });
  129. }
  130. return (
  131. !onReady ?
  132. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  133. <Grid item>
  134. <LoadingComponent />
  135. </Grid>
  136. </Grid>
  137. :
  138. (
  139. <Grid container sx={{minHeight: '87vh', backgroundColor: 'backgroundColor.default'}} direction="column" justifyContent="flex-start" alignItems="center" >
  140. <Grid item xs={12} width="100%">
  141. <div style={BackgroundHead} width="100%">
  142. <Stack direction="row" height='70px'>
  143. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>Gazette Issue</Typography>
  144. </Stack>
  145. </div>
  146. </Grid>
  147. <Grid item xs={12} md={12} lg={6} width="100%">
  148. <Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={2} sx={{ml:2,mt:1}} >
  149. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  150. <label htmlFor="downloadFileBtn">
  151. <Button
  152. component="span"
  153. variant="contained"
  154. size="large"
  155. disabled={waitDownload}
  156. onClick={doExport}
  157. >
  158. <Typography variant="h5">Export</Typography>
  159. </Button>
  160. </label>
  161. </ThemeProvider>
  162. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  163. <input
  164. id="uploadFileBtn"
  165. name="file"
  166. type="file"
  167. accept=".xlsx"
  168. style={{ display: 'none' }}
  169. disabled={waitImport}
  170. onChange={(event) => {
  171. readFile(event)
  172. }}
  173. />
  174. <label htmlFor="uploadFileBtn">
  175. <Button
  176. component="span"
  177. variant="contained"
  178. size="large"
  179. disabled={waitImport}
  180. >
  181. <Typography variant="h5">Upload Files</Typography>
  182. </Button>
  183. </label>
  184. </ThemeProvider>
  185. </Stack>
  186. </Grid>
  187. {/*row 1*/}
  188. <Grid item xs={12} md={12} lg={12} width="100%">
  189. <SearchForm
  190. applySearch={applySearch}
  191. // generateXML={generateXML}
  192. searchCriteria={searchCriteria}
  193. comboData={comboData}
  194. />
  195. </Grid>
  196. {/*row 2*/}
  197. {!onSearchReady?
  198. <LoadingComponent/>:
  199. <Grid item xs={12} md={12} lg={12} width="100%">
  200. <MainCard elevation={0}
  201. border={false}
  202. content={false}
  203. >
  204. <GazetteIssueTable
  205. recordList={record}
  206. />
  207. </MainCard>
  208. </Grid>
  209. }
  210. <div>
  211. <Dialog
  212. open={isWarningPopUp}
  213. onClose={() => setIsWarningPopUp(false)}
  214. PaperProps={{
  215. sx: {
  216. minWidth: '40vw',
  217. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  218. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  219. }
  220. }}
  221. >
  222. <DialogTitle><Typography variant="h3">Warning</Typography></DialogTitle>
  223. <DialogContent style={{ display: 'flex', }}>
  224. <Typography variant="h4" style={{ padding: '16px' }}>{warningText}</Typography>
  225. </DialogContent>
  226. <DialogActions>
  227. <Button onClick={() => setIsWarningPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  228. </DialogActions>
  229. </Dialog>
  230. </div>
  231. </Grid >
  232. )
  233. );
  234. };
  235. export default Index;