Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

136 rader
4.4 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack
  6. } from '@mui/material';
  7. import MainCard from "components/MainCard";
  8. import * as UrlUtils from "utils/ApiPathConst";
  9. import * as React from "react";
  10. import * as HttpUtils from "utils/HttpUtils";
  11. import * as DateUtils from "utils/DateUtils";
  12. import Loadable from 'components/Loadable';
  13. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  14. const SearchForm = Loadable(React.lazy(() => import('./SearchForm')));
  15. const EventTable = Loadable(React.lazy(() => import('./DataGrid')));
  16. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  17. const BackgroundHead = {
  18. backgroundImage: `url(${titleBackgroundImg})`,
  19. width: '100%',
  20. height: '100%',
  21. backgroundSize:'contain',
  22. backgroundRepeat: 'no-repeat',
  23. backgroundColor: '#0C489E',
  24. backgroundPosition: 'right'
  25. }
  26. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  27. const Index = () => {
  28. const [record,setRecord] = React.useState([]);
  29. const [searchCriteria, setSearchCriteria] = React.useState({
  30. dateTo: DateUtils.dateStr(new Date()),
  31. dateFrom: DateUtils.dateStr(new Date().setDate(new Date().getDate()-14)),
  32. });
  33. const [onReady, setOnReady] = React.useState(false);
  34. React.useEffect(() => {
  35. setOnReady(true);
  36. }, [record]);
  37. React.useEffect(() => {
  38. console.log(searchCriteria)
  39. loadGrid();
  40. }, [searchCriteria]);
  41. function loadGrid(){
  42. HttpUtils.get({
  43. url: UrlUtils.GFIMIS_LIST,
  44. params: searchCriteria,
  45. onSuccess: function(responseData){
  46. setRecord(responseData);
  47. }
  48. });
  49. }
  50. function downloadXML(input) {
  51. console.log(input)
  52. HttpUtils.get({
  53. url: UrlUtils.GEN_GFMIS_XML + "/today",
  54. params:{dateTo: input.dateTo,
  55. dateFrom: input.dateFrom,
  56. },
  57. onSuccess: (responseData) => {
  58. console.log(responseData)
  59. const parser = new DOMParser();
  60. const xmlDoc = parser.parseFromString(responseData, 'application/xml');
  61. const filename = xmlDoc.querySelector('FileHeader').getAttribute('H_Filename');
  62. const blob = new Blob([responseData], { type: 'application/xml' });
  63. // Create a download link
  64. const link = document.createElement('a');
  65. link.href = URL.createObjectURL(blob);
  66. link.download = filename+'.xml';
  67. // Append the link to the document body
  68. document.body.appendChild(link);
  69. // Programmatically click the link to trigger the download
  70. link.click();
  71. // Clean up the link
  72. document.body.removeChild(link);
  73. }
  74. });
  75. // open(UrlUtils.GEN_GFMIS_XML + "/today?online=true")
  76. }
  77. function applySearch(input) {
  78. setSearchCriteria(input);
  79. }
  80. function generateXML(input) {
  81. downloadXML(input);
  82. }
  83. return (
  84. !onReady ?
  85. <LoadingComponent/>
  86. :
  87. <Grid container sx={{ backgroundColor: 'backgroundColor.default'}} direction="column">
  88. <Grid item xs={12}>
  89. <div style={BackgroundHead}>
  90. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  91. <Typography ml={15} color='#FFF' variant="h4">GFMIS</Typography>
  92. </Stack>
  93. </div>
  94. </Grid>
  95. {/*row 1*/}
  96. <Grid item xs={12} md={12} lg={12} sx={{mb:-1}}>
  97. <SearchForm
  98. applySearch={applySearch}
  99. generateXML={generateXML}
  100. searchCriteria={searchCriteria}
  101. />
  102. </Grid>
  103. {/*row 2*/}
  104. <Grid item xs={12} md={12} lg={12}>
  105. <MainCard elevation={0}
  106. border={false}
  107. content={false}
  108. sx={{width: "-webkit-fill-available"}}
  109. >
  110. <EventTable
  111. recordList={record}
  112. />
  113. </MainCard>
  114. </Grid>
  115. </Grid>
  116. );
  117. };
  118. export default Index;