25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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