You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

287 lines
11 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import * as React from "react";
  11. import * as FormatUtils from "utils/FormatUtils";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as UrlUtils from "utils/ApiPathConst";
  14. import * as HttpUtils from "utils/HttpUtils";
  15. // import { useNavigate } from "react-router-dom";
  16. // import { notifyDownloadSuccess } from 'utils/CommonFunction';
  17. import { PNSPS_BUTTON_THEME } from "../../../themes/buttonConst";
  18. import { ThemeProvider } from "@emotion/react";
  19. import { useIntl } from "react-intl";
  20. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  21. const SearchPublicNoticeForm = ({ applySearch, issueComboData }) => {
  22. const [isFailPopUp, setIsFailPopUp] = React.useState(false);
  23. const [failText, setFailText] = React.useState("");
  24. const [confirmPopUp, setConfirmPopUp] = React.useState(false);
  25. const [dueDate, setDueDate] = React.useState(DateUtils.dateValue(DateUtils.dateValue((new Date().setDate(new Date().getDate() + 1)))));
  26. // const [isSuccessPopUp, setIsSuccessPopUp] = React.useState(false);
  27. // const [resultCount, setResultCount] = React.useState(0);
  28. // const [dnIdList, setDnIdList] = React.useState([]);
  29. const [issueSelected, setIssueSelected] = React.useState({});
  30. // const [paymentCount, setPaymentCount] = React.useState(0);
  31. // const [publishCount, setPublishCount] = React.useState(0);
  32. const [issueCombo, setIssueCombo] = React.useState([]);
  33. const [waitDownload, setWaitDownload] = React.useState(false);
  34. // const navigate = useNavigate()
  35. const intl = useIntl();
  36. const { locale } = intl;
  37. React.useEffect(() => {
  38. if (issueComboData && issueComboData.length > 0) {
  39. setIssueCombo(issueComboData);
  40. }
  41. }, [issueComboData]);
  42. // React.useEffect(() => {
  43. // setPaymentCount(_paymentCount);
  44. // }, [_paymentCount]);
  45. // React.useEffect(() => {
  46. // setPublishCount(_publishCount);
  47. // }, [_publishCount]);
  48. React.useEffect(() => {
  49. onPreView();
  50. }, [issueSelected]);
  51. function getIssueLabel(data) {
  52. let issueYear = data.issueYear
  53. let volume = data.volume;
  54. let issueNo = data.issueNo;
  55. let issueDate = data.issueDate;
  56. if (locale === 'zh-HK') {
  57. return issueYear
  58. + " 第" + volume + "卷,"
  59. + " 第" + issueNo + "期,"
  60. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  61. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  62. } else if (locale === 'zh-CN') {
  63. return issueYear
  64. + " 第" + volume + "卷,"
  65. + " 第" + issueNo + "期,"
  66. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  67. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  68. }
  69. return issueYear
  70. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  71. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  72. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  73. }
  74. const onSubmit = () => {
  75. if (!issueSelected?.id) {
  76. setFailText("Fail Create: Please select Gazette Issue.");
  77. setIsFailPopUp(true);
  78. return;
  79. } else {
  80. setDueDate(DateUtils.dateValue((new Date().setDate(new Date().getDate() + 1))));
  81. doDnExport();
  82. }
  83. };
  84. const doDnExport= () => {
  85. // setConfirmPopUp(false);
  86. setWaitDownload(true)
  87. HttpUtils.fileDownload({
  88. url: UrlUtils.GDN_EXPORT,
  89. params: {
  90. issueId: issueSelected.id
  91. },
  92. onResponse: () => {
  93. setTimeout(()=> setWaitDownload(false), 500)
  94. // location.reload();
  95. }
  96. });
  97. }
  98. // const fileDownload = () => {
  99. // HttpUtils.fileDownload({
  100. // method: 'post',
  101. // url: UrlUtils.DEMAND_NOTE_EXPORT,
  102. // params: {
  103. // "dnIdList": dnIdList
  104. // },
  105. // onSuccess: function () {
  106. // notifyDownloadSuccess();
  107. // }
  108. // });
  109. // }
  110. // const onNavigate = () => {
  111. // setIsSuccessPopUp(false);
  112. // if (resultCount > 0)
  113. // navigate('/paymentPage/demandNote');
  114. // };
  115. const onPreView = () => {
  116. if (!issueSelected?.id) {
  117. return;
  118. }
  119. const temp = {
  120. issueId: issueSelected.id,
  121. start:0,
  122. limit:10
  123. };
  124. applySearch(temp);
  125. };
  126. return (
  127. <MainCard xs={12} md={12} lg={12}
  128. border={false}
  129. content={false}
  130. >
  131. <form>
  132. {/*row 1*/}
  133. <Grid container sx={{ backgroundColor: '#ffffff', pt:4, pl:4, pb:4 }} width="98%" spacing={3} >
  134. {/*row 1*/}
  135. <Grid item justifyContent="space-between" alignItems="center" >
  136. <Typography variant="h5" >
  137. Please Select Gazette Issue :
  138. </Typography>
  139. </Grid>
  140. {/*row 2*/}
  141. <Grid item xs={9} s={6} md={5} lg={3}>
  142. <Autocomplete
  143. disablePortal
  144. size="small"
  145. id="issueId"
  146. options={issueCombo}
  147. value={issueSelected}
  148. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  149. getOptionLabel={(option) => getIssueLabel(option)}
  150. onChange={(event, newValue) => {
  151. if (newValue !== null) {
  152. setIssueSelected(newValue);
  153. }
  154. }}
  155. sx={{
  156. '& .MuiInputBase-root': { alignItems: 'center' },
  157. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  158. '& .MuiOutlinedInput-root': { height: 40 }
  159. }}
  160. renderInput={(params) => (
  161. <TextField {...params}
  162. label="Gazette Issue"
  163. InputLabelProps={{
  164. shrink: true
  165. }}
  166. />
  167. )}
  168. />
  169. </Grid>
  170. <Grid item >
  171. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  172. <Button
  173. variant="contained"
  174. onClick={onSubmit}
  175. color="success"
  176. disabled={waitDownload}
  177. minWidth={150}
  178. >
  179. Export
  180. </Button>
  181. </ThemeProvider>
  182. </Grid>
  183. {/* <Grid item >
  184. <Grid container display="flex" alignItems={"center"} spacing={3}>
  185. <Grid item >
  186. <Typography variant="h5">Pending Payment: {paymentCount}</Typography>
  187. </Grid>
  188. <Grid item >
  189. <Typography variant="h5">Pending Publish: {publishCount}</Typography>
  190. </Grid>
  191. </Grid>
  192. </Grid> */}
  193. </Grid>
  194. </form>
  195. <div>
  196. <Dialog
  197. open={isFailPopUp}
  198. onClose={() => setIsFailPopUp(false)}
  199. PaperProps={{
  200. sx: {
  201. minWidth: '40vw',
  202. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  203. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  204. }
  205. }}
  206. >
  207. <DialogTitle><Typography variant="h3">Action Fail</Typography></DialogTitle>
  208. <DialogContent style={{ display: 'flex', }}>
  209. <Typography variant="h4" style={{ padding: '16px' }}>{failText}</Typography>
  210. </DialogContent>
  211. <DialogActions>
  212. <Button onClick={() => setIsFailPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  213. </DialogActions>
  214. </Dialog>
  215. </div>
  216. <div>
  217. <Dialog
  218. open={confirmPopUp}
  219. onClose={() => setConfirmPopUp(false)}
  220. PaperProps={{
  221. sx: {
  222. minWidth: '40vw',
  223. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  224. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  225. }
  226. }}
  227. >
  228. <DialogTitle><Typography variant="h3">Create Confirm</Typography></DialogTitle>
  229. <DialogContent style={{ display: 'flex', }}>
  230. <Grid container alignItems={"center"}>
  231. <Grid item md={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  232. <Typography variant="h4" style={{ padding: '16px' }}>Due Date: </Typography>
  233. </Grid>
  234. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  235. <TextField
  236. fullWidth
  237. type="date"
  238. defaultValue={dueDate}
  239. InputProps={{ inputProps: { min: DateUtils.dateValue(new Date()) } }}
  240. onChange={(newValue) => {
  241. setDueDate(newValue.currentTarget.value)
  242. }}
  243. InputLabelProps={{
  244. shrink: true
  245. }}
  246. />
  247. </Grid>
  248. </Grid>
  249. </DialogContent>
  250. <DialogActions>
  251. <Button onClick={() => setConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  252. <Button onClick={() => doDnCreate()}><Typography variant="h5">Confirm</Typography></Button>
  253. </DialogActions>
  254. </Dialog>
  255. </div>
  256. </MainCard>
  257. );
  258. };
  259. export default SearchPublicNoticeForm;