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

330 行
15 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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  17. const SearchPublicNoticeForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
  18. }) => {
  19. const [type, setType] = React.useState([]);
  20. // const [status, setStatus] = React.useState({ key: 0, label: 'All', type: 'all' });
  21. const [orgSelected, setOrgSelected] = React.useState({});
  22. const [orgCombo, setOrgCombo] = React.useState();
  23. const [issueSelected, setIssueSelected] = React.useState({});
  24. const [issueCombo, setIssueCombo] = React.useState([]);
  25. const [selectedStatus, setSelectedStatus] = React.useState([]);
  26. const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
  27. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  28. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  29. const marginBottom = 2.5;
  30. const { reset, register, handleSubmit } = useForm()
  31. const onSubmit = (data) => {
  32. data.status = selectedLabelsString
  33. let typeArray = [];
  34. for (let i = 0; i < type.length; i++) {
  35. typeArray.push(type[i].label);
  36. }
  37. const temp = {
  38. appNo: data.appNo,
  39. dateFrom: data.dateFrom,
  40. dateTo: data.dateTo,
  41. contact: data.contact,
  42. status: (data.status === '' || data.status.includes("all")) ? "" : data.status,
  43. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  44. issueId: issueSelected?.id,
  45. groupNo: data.groupNo,
  46. };
  47. applySearch(temp);
  48. };
  49. React.useEffect(() => {
  50. if (orgComboData && orgComboData.length > 0) {
  51. setOrgCombo(orgComboData);
  52. }
  53. }, [orgComboData]);
  54. React.useEffect(() => {
  55. if (issueComboData && issueComboData.length > 0) {
  56. setIssueCombo(issueComboData);
  57. }
  58. }, [issueComboData]);
  59. function resetForm() {
  60. setType([]);
  61. // setStatus({ key: 0, label: 'All', type: 'all' });
  62. setOrgSelected({});
  63. setIssueSelected({});
  64. setSelectedStatus([]);
  65. reset();
  66. }
  67. function getIssueLabel(data) {
  68. if (data == {}) return "";
  69. return data.year
  70. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  71. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  72. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  73. }
  74. return (
  75. <MainCard xs={12} md={12} lg={12}
  76. border={false}
  77. content={false}
  78. sx={{ backgroundColor: '#fff' }}
  79. >
  80. <form onSubmit={handleSubmit(onSubmit)}>
  81. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  82. {/*row 1*/}
  83. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  84. <Typography variant="pnspsFormHeader" >
  85. Search Form
  86. </Typography>
  87. </Grid>
  88. {/*row 2*/}
  89. <Grid container display="flex" alignItems={"center"}>
  90. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  91. <TextField
  92. fullWidth
  93. {...register("appNo")}
  94. id='appNo'
  95. label={"App No."}
  96. defaultValue={searchCriteria.appNo}
  97. InputLabelProps={{
  98. shrink: true
  99. }}
  100. />
  101. </Grid>
  102. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  103. <Grid container>
  104. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  105. <TextField
  106. fullWidth
  107. {...register("dateFrom")}
  108. id="dateFrom"
  109. type="date"
  110. label={"Submit Date(From)"}
  111. defaultValue={searchCriteria.dateFrom}
  112. InputProps={{ inputProps: { max: maxDate } }}
  113. onChange={(newValue) => {
  114. setMinDate(DateUtils.dateStr(newValue));
  115. }}
  116. InputLabelProps={{
  117. shrink: true
  118. }}
  119. />
  120. </Grid>
  121. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:0.8, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  122. To
  123. </Grid>
  124. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  125. <TextField
  126. fullWidth
  127. InputLabelProps={{
  128. shrink: true
  129. }}
  130. {...register("dateTo")}
  131. InputProps={{ inputProps: { min: minDate } }}
  132. onChange={(newValue) => {
  133. setMaxDate(DateUtils.dateStr(newValue));
  134. }}
  135. id="dateTo"
  136. type="date"
  137. //label={"Submit Date(To)"}
  138. defaultValue={searchCriteria.dateTo}
  139. />
  140. </Grid>
  141. </Grid>
  142. </Grid>
  143. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  144. <TextField
  145. fullWidth
  146. {...register("contact")}
  147. id="contact"
  148. label={"Client"}
  149. defaultValue={searchCriteria.contact}
  150. InputLabelProps={{
  151. shrink: true
  152. }}
  153. />
  154. </Grid>
  155. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  156. {/* <Autocomplete
  157. {...register("status")}
  158. disablePortal
  159. id="status"
  160. filterOptions={(options) => options}
  161. options={ComboData.publicNoticeStatic_GLD}
  162. value={status}
  163. inputValue={status?.label}
  164. onChange={(event, newValue) => {
  165. if (newValue !== null) {
  166. setStatus(newValue);
  167. }
  168. }}
  169. renderInput={(params) => (
  170. <TextField {...params}
  171. label="Status"
  172. />
  173. )}
  174. InputLabelProps={{
  175. shrink: true
  176. }}
  177. /> */}
  178. <Autocomplete
  179. multiple
  180. {...register("status")}
  181. id="status"
  182. size="small"
  183. options={ComboData.publicNoticeStatic_GLD}
  184. value={selectedStatus}
  185. onChange={(event, newValue) => {
  186. const findAllIndex = newValue.findIndex((ele) => {
  187. return ele.type === "all"
  188. })
  189. if (findAllIndex > -1) {
  190. setSelectedStatus([newValue[findAllIndex]]);
  191. setSelectedLabelsString('all')
  192. } else {
  193. const selectedLabels = newValue.map(option => option.type);
  194. const selectedLabelsString = `${selectedLabels.join(',')}`;
  195. setSelectedStatus(newValue);
  196. setSelectedLabelsString(selectedLabelsString);
  197. }
  198. }}
  199. getOptionLabel={(option) => option.label}
  200. renderInput={(params) => (
  201. <TextField
  202. {...params}
  203. label="Status"
  204. InputLabelProps={{
  205. shrink: true
  206. }}
  207. />
  208. )}
  209. />
  210. </Grid>
  211. {
  212. orgCombo ?
  213. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  214. <Autocomplete
  215. {...register("orgId")}
  216. disablePortal
  217. id="orgId"
  218. options={orgCombo}
  219. size="small"
  220. value={orgSelected}
  221. inputValue={(orgSelected?.label) ? orgSelected?.label : ""}
  222. onChange={(event, newValue) => {
  223. if (newValue !== null) {
  224. setOrgSelected(newValue);
  225. }
  226. }}
  227. renderInput={(params) => (
  228. <TextField {...params}
  229. label="Organisation"
  230. InputLabelProps={{
  231. shrink: true
  232. }}
  233. />
  234. )}
  235. />
  236. </Grid>
  237. : <></>
  238. }
  239. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  240. <Autocomplete
  241. {...register("issueId")}
  242. disablePortal
  243. size="small"
  244. id="issueId"
  245. options={issueCombo}
  246. value={issueSelected}
  247. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  248. getOptionLabel={(option) => getIssueLabel(option)}
  249. onChange={(event, newValue) => {
  250. if (newValue !== null) {
  251. setIssueSelected(newValue);
  252. }
  253. }}
  254. renderInput={(params) => (
  255. <TextField {...params}
  256. label="Gazette Issue"
  257. InputLabelProps={{
  258. shrink: true
  259. }}
  260. />
  261. )}
  262. />
  263. </Grid>
  264. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  265. <TextField
  266. fullWidth
  267. {...register("groupNo")}
  268. id='groupNo'
  269. label="Gazette Code."
  270. defaultValue={searchCriteria.groupNo}
  271. InputLabelProps={{
  272. shrink: true
  273. }}
  274. />
  275. </Grid>
  276. </Grid>
  277. {/*last row*/}
  278. <Grid container maxWidth justifyContent="flex-end">
  279. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  280. <Grid item sx={{ ml: 3 }}>
  281. <Button
  282. variant="contained"
  283. onClick={resetForm}
  284. >
  285. Clear
  286. </Button>
  287. </Grid>
  288. <Grid item sx={{ ml: 3 }}>
  289. <Button
  290. variant="contained"
  291. type="submit"
  292. >
  293. Submit
  294. </Button>
  295. </Grid>
  296. </ThemeProvider>
  297. </Grid>
  298. </Grid>
  299. </form>
  300. </MainCard>
  301. );
  302. };
  303. export default SearchPublicNoticeForm;