您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

282 行
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. renderInput={(params) => (
  156. <TextField {...params}
  157. label="Gazette Issue"
  158. InputLabelProps={{
  159. shrink: true
  160. }}
  161. />
  162. )}
  163. />
  164. </Grid>
  165. <Grid item >
  166. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  167. <Button
  168. variant="contained"
  169. onClick={onSubmit}
  170. color="success"
  171. disabled={waitDownload}
  172. minWidth={150}
  173. >
  174. Export
  175. </Button>
  176. </ThemeProvider>
  177. </Grid>
  178. {/* <Grid item >
  179. <Grid container display="flex" alignItems={"center"} spacing={3}>
  180. <Grid item >
  181. <Typography variant="h5">Pending Payment: {paymentCount}</Typography>
  182. </Grid>
  183. <Grid item >
  184. <Typography variant="h5">Pending Publish: {publishCount}</Typography>
  185. </Grid>
  186. </Grid>
  187. </Grid> */}
  188. </Grid>
  189. </form>
  190. <div>
  191. <Dialog
  192. open={isFailPopUp}
  193. onClose={() => setIsFailPopUp(false)}
  194. PaperProps={{
  195. sx: {
  196. minWidth: '40vw',
  197. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  198. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  199. }
  200. }}
  201. >
  202. <DialogTitle><Typography variant="h3">Action Fail</Typography></DialogTitle>
  203. <DialogContent style={{ display: 'flex', }}>
  204. <Typography variant="h4" style={{ padding: '16px' }}>{failText}</Typography>
  205. </DialogContent>
  206. <DialogActions>
  207. <Button onClick={() => setIsFailPopUp(false)}><Typography variant="h5">OK</Typography></Button>
  208. </DialogActions>
  209. </Dialog>
  210. </div>
  211. <div>
  212. <Dialog
  213. open={confirmPopUp}
  214. onClose={() => setConfirmPopUp(false)}
  215. PaperProps={{
  216. sx: {
  217. minWidth: '40vw',
  218. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  219. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  220. }
  221. }}
  222. >
  223. <DialogTitle><Typography variant="h3">Create Confirm</Typography></DialogTitle>
  224. <DialogContent style={{ display: 'flex', }}>
  225. <Grid container alignItems={"center"}>
  226. <Grid item md={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  227. <Typography variant="h4" style={{ padding: '16px' }}>Due Date: </Typography>
  228. </Grid>
  229. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  230. <TextField
  231. fullWidth
  232. type="date"
  233. defaultValue={dueDate}
  234. InputProps={{ inputProps: { min: DateUtils.dateValue(new Date()) } }}
  235. onChange={(newValue) => {
  236. setDueDate(newValue.currentTarget.value)
  237. }}
  238. InputLabelProps={{
  239. shrink: true
  240. }}
  241. />
  242. </Grid>
  243. </Grid>
  244. </DialogContent>
  245. <DialogActions>
  246. <Button onClick={() => setConfirmPopUp(false)}><Typography variant="h5">Cancel</Typography></Button>
  247. <Button onClick={() => doDnCreate()}><Typography variant="h5">Confirm</Typography></Button>
  248. </DialogActions>
  249. </Dialog>
  250. </div>
  251. </MainCard>
  252. );
  253. };
  254. export default SearchPublicNoticeForm;