Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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