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

440 行
19 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as ComboData from "utils/ComboData";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as FormatUtils from "utils/FormatUtils";
  14. import { ThemeProvider } from "@emotion/react";
  15. import { PNSPS_BUTTON_THEME } from "../../../themes/buttonConst";
  16. import { useIntl } from "react-intl";
  17. import { makeStyles } from '@mui/styles';
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const useStyles = makeStyles(() => ({
  20. root: {
  21. position: "relative"
  22. },
  23. display: {
  24. position: "absolute",
  25. top: 2,
  26. left: 12,
  27. bottom: 2,
  28. background: "white",
  29. pointerEvents: "none",
  30. right: 50,
  31. display: "flex",
  32. alignItems: "center",
  33. width:"70%"
  34. },
  35. }));
  36. const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
  37. }) => {
  38. const [type, setType] = React.useState([]);
  39. // const [status, setStatus] = React.useState({ key: 0, label: 'All', type: 'all' });
  40. const [orgSelected, setOrgSelected] = React.useState({});
  41. const [orgCombo, setOrgCombo] = React.useState();
  42. const [issueSelected, setIssueSelected] = React.useState({});
  43. const [issueCombo, setIssueCombo] = React.useState([]);
  44. const [selectedStatus, setSelectedStatus] = React.useState({key: 0, label: 'All', type: 'all'});
  45. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  46. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  47. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  48. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  49. React.useEffect(() => {
  50. setFromDateValue(minDate);
  51. }, [minDate]);
  52. React.useEffect(() => {
  53. setToDateValue(maxDate);
  54. }, [maxDate]);
  55. function FormDateInputComponent({ inputRef, ...props }) {
  56. const classes = useStyles();
  57. return (
  58. <>
  59. <div className={classes.display}>
  60. {DateUtils.dateStr(fromDateValue) == "Invalid Date" ?
  61. fromDateValue
  62. :
  63. DateUtils.dateStr(fromDateValue)}
  64. </div>
  65. <input
  66. className={classes.input}
  67. ref={inputRef}
  68. {...props}
  69. // onChange={handleChange}
  70. value={fromDateValue}
  71. max={maxDate}
  72. />
  73. </>
  74. );
  75. }
  76. function ToDateInputComponent({ inputRef, ...props }) {
  77. const classes = useStyles();
  78. return (
  79. <>
  80. <div className={classes.display}>
  81. {DateUtils.dateStr(toDateValue) == "Invalid Date" ?
  82. toDateValue
  83. :
  84. DateUtils.dateStr(toDateValue)}
  85. </div>
  86. <input
  87. // className={classes.input}
  88. ref={inputRef}
  89. {...props}
  90. // onChange={handleChange}
  91. value={toDateValue}
  92. min={minDate}
  93. />
  94. </>
  95. );
  96. }
  97. const intl = useIntl();
  98. const { locale } = intl;
  99. const marginBottom = 2.5;
  100. const { reset, register, handleSubmit } = useForm()
  101. const onSubmit = (data) => {
  102. data.status = selectedStatus?.type
  103. let typeArray = [];
  104. let sentDateFrom = "";
  105. let sentDateTo = "";
  106. for (let i = 0; i < type.length; i++) {
  107. typeArray.push(type[i].label);
  108. }
  109. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  110. sentDateFrom = DateUtils.dateValue(fromDateValue)
  111. sentDateTo = DateUtils.dateValue(toDateValue)
  112. }
  113. const temp = {
  114. appNo: data.appNo,
  115. dateFrom: sentDateFrom,
  116. dateTo: sentDateTo,
  117. contact: data.contact,
  118. status: (data.status === '' || data.status?.includes("all")) ? "" : data.status,
  119. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  120. issueId: issueSelected?.id,
  121. groupNo: data.groupNo,
  122. };
  123. applySearch(temp);
  124. };
  125. React.useEffect(() => {
  126. if (orgComboData && orgComboData.length > 0) {
  127. setOrgCombo(orgComboData);
  128. }
  129. }, [orgComboData]);
  130. React.useEffect(() => {
  131. if (issueComboData && issueComboData.length > 0) {
  132. setIssueCombo(issueComboData);
  133. }
  134. }, [issueComboData]);
  135. function resetForm() {
  136. setType([]);
  137. // setStatus({ key: 0, label: 'All', type: 'all' });
  138. setOrgSelected({});
  139. setIssueSelected({});
  140. setSelectedStatus({key: 0, label: 'All', type: 'all'});
  141. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  142. setMaxDate(DateUtils.dateValue(new Date()))
  143. reset();
  144. }
  145. const getIssueLabel=(data)=> {
  146. let issueYear = data.issueYear
  147. let volume = data.volume;
  148. let issueNo = data.issueNo;
  149. let issueDate = data.issueDate;
  150. if (locale === 'zh-HK') {
  151. return issueYear
  152. + " 第" + volume + "卷,"
  153. + " 第" + issueNo + "期,"
  154. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  155. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  156. } else if (locale === 'zh-CN') {
  157. return issueYear
  158. + " 第" + volume + "卷,"
  159. + " 第" + issueNo + "期,"
  160. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  161. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  162. }
  163. return issueYear
  164. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  165. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  166. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  167. }
  168. return (
  169. <MainCard xs={12} md={12} lg={12}
  170. border={false}
  171. content={false}
  172. sx={{ backgroundColor: '#fff' }}
  173. >
  174. <form onSubmit={handleSubmit(onSubmit)}>
  175. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom }} width="98%">
  176. {/*row 1*/}
  177. <Grid item justifyContent="space-between" alignItems="center" sx={{ mt: 1, ml: 3, mb: marginBottom }}>
  178. <Typography variant="pnspsFormHeader" >
  179. Search
  180. </Typography>
  181. </Grid>
  182. {/*row 2*/}
  183. <Grid container display="flex" alignItems={"center"}>
  184. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  185. <TextField
  186. fullWidth
  187. {...register("appNo")}
  188. id='appNo'
  189. label={"Application No."}
  190. defaultValue={searchCriteria.appNo}
  191. InputLabelProps={{
  192. shrink: true
  193. }}
  194. />
  195. </Grid>
  196. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  197. <Grid container spacing={1}>
  198. <Grid item xs={6}>
  199. <TextField
  200. fullWidth
  201. {...register("dateFrom")}
  202. id="dateFrom"
  203. type="date"
  204. label={"Submit Date (From)"}
  205. defaultValue={searchCriteria.dateFrom}
  206. InputProps={{
  207. inputComponent: FormDateInputComponent,
  208. }}
  209. onChange={(newValue) => {
  210. if(newValue.target.value!=""){
  211. setMinDate(newValue.target.value);
  212. }
  213. }}
  214. InputLabelProps={{
  215. shrink: true
  216. }}
  217. sx={{ "& .MuiInputBase-input": {display:"block", textIndent: "-9999px"} }}
  218. />
  219. </Grid>
  220. <Grid item xs={6}>
  221. <TextField
  222. fullWidth
  223. InputLabelProps={{
  224. shrink: true
  225. }}
  226. {...register("dateTo")}
  227. InputProps={{
  228. inputComponent: ToDateInputComponent,
  229. }}
  230. onChange={(newValue) => {
  231. if(newValue.target.value!=""){
  232. setMaxDate(newValue.target.value);
  233. }
  234. }}
  235. id="dateTo"
  236. type="date"
  237. label={"Submit Date (To)"}
  238. defaultValue={searchCriteria.dateTo}
  239. sx={{ "& .MuiInputBase-input": {display:"block", textIndent: "-9999px"} }}
  240. />
  241. </Grid>
  242. </Grid>
  243. </Grid>
  244. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  245. <TextField
  246. fullWidth
  247. {...register("contact")}
  248. id="contact"
  249. label={"Client"}
  250. defaultValue={searchCriteria.contact}
  251. InputLabelProps={{
  252. shrink: true
  253. }}
  254. />
  255. </Grid>
  256. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  257. <Autocomplete
  258. {...register("status")}
  259. id="status"
  260. size="small"
  261. options={ComboData.publicNoticeStatic_GLD}
  262. value={selectedStatus}
  263. onChange={(event, newValue) => {
  264. if(newValue==null){
  265. setSelectedStatus(ComboData.publicNoticeStatic_GLD[0]);
  266. }else{
  267. setSelectedStatus(newValue);
  268. }
  269. }}
  270. getOptionLabel={(option) => option.label}
  271. renderInput={(params) => (
  272. <TextField
  273. {...params}
  274. label="Status"
  275. InputLabelProps={{
  276. shrink: true
  277. }}
  278. />
  279. )}
  280. />
  281. {/* <Autocomplete
  282. multiple
  283. {...register("status")}
  284. id="status"
  285. size="small"
  286. options={ComboData.publicNoticeStatic_GLD}
  287. value={selectedStatus}
  288. onChange={(event, newValue) => {
  289. const findAllIndex = newValue.findIndex((ele) => {
  290. return ele.type === "all"
  291. })
  292. if (findAllIndex > -1) {
  293. setSelectedStatus([newValue[findAllIndex]]);
  294. setSelectedLabelsString('all')
  295. } else {
  296. const selectedLabels = newValue.map(option => option.type);
  297. const selectedLabelsString = `${selectedLabels.join(',')}`;
  298. setSelectedStatus(newValue);
  299. setSelectedLabelsString(selectedLabelsString);
  300. }
  301. }}
  302. getOptionLabel={(option) => option.label}
  303. renderInput={(params) => (
  304. <TextField
  305. {...params}
  306. label="Status"
  307. InputLabelProps={{
  308. shrink: true
  309. }}
  310. />
  311. )}
  312. /> */}
  313. </Grid>
  314. {
  315. orgCombo ?
  316. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  317. <Autocomplete
  318. {...register("orgId")}
  319. disablePortal
  320. id="orgId"
  321. options={orgCombo}
  322. size="small"
  323. value={orgSelected}
  324. getOptionLabel={(option) => option.name? option.name : ""}
  325. inputValue={orgSelected ? orgSelected.name : ""}
  326. onChange={(event, newValue) => {
  327. if (newValue !== null) {
  328. setOrgSelected(newValue);
  329. }else{
  330. setOrgSelected({});
  331. }
  332. }}
  333. renderInput={(params) => (
  334. <TextField {...params}
  335. label="Organisation"
  336. InputLabelProps={{
  337. shrink: true
  338. }}
  339. />
  340. )}
  341. />
  342. </Grid>
  343. : <></>
  344. }
  345. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  346. <Autocomplete
  347. {...register("issueId")}
  348. disablePortal
  349. size="small"
  350. id="issueId"
  351. options={issueCombo}
  352. value={issueSelected}
  353. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  354. getOptionLabel={(option) => getIssueLabel(option)}
  355. onChange={(event, newValue) => {
  356. setIssueSelected(newValue);
  357. }}
  358. renderInput={(params) => (
  359. <TextField {...params}
  360. label="Gazette Issue No."
  361. InputLabelProps={{
  362. shrink: true
  363. }}
  364. />
  365. )}
  366. />
  367. </Grid>
  368. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  369. <TextField
  370. fullWidth
  371. {...register("groupNo")}
  372. id='groupNo'
  373. label="Gazette Code"
  374. defaultValue={searchCriteria.groupNo}
  375. InputLabelProps={{
  376. shrink: true
  377. }}
  378. />
  379. </Grid>
  380. </Grid>
  381. {/*last row*/}
  382. <Grid container maxWidth justifyContent="flex-end">
  383. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  384. <Grid item sx={{ ml: 3 }}>
  385. <Button
  386. variant="contained"
  387. color="cancel"
  388. onClick={resetForm}
  389. >
  390. Reset
  391. </Button>
  392. </Grid>
  393. <Grid item sx={{ ml: 3 }}>
  394. <Button
  395. variant="contained"
  396. type="submit"
  397. >
  398. Submit
  399. </Button>
  400. </Grid>
  401. </ThemeProvider>
  402. </Grid>
  403. </Grid>
  404. </form>
  405. </MainCard>
  406. );
  407. };
  408. export default SearchPublicNoticeForm;