Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

375 linhas
16 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. CardContent,
  5. Grid, TextField,
  6. Autocomplete,
  7. Typography
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import { useForm } from "react-hook-form";
  11. import * as React from "react";
  12. import * as ComboData from "utils/ComboData";
  13. import * as DateUtils from "utils/DateUtils";
  14. import * as FormatUtils from "utils/FormatUtils";
  15. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  16. import {ThemeProvider} from "@emotion/react";
  17. import {FormattedMessage, useIntl} from "react-intl";
  18. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  19. import dayjs from "dayjs";
  20. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  21. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  22. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  23. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  24. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData
  25. }) => {
  26. const intl = useIntl();
  27. const { locale } = intl;
  28. const [type, setType] = React.useState([]);
  29. const [status, setStatus] = React.useState(ComboData.proofStatus[0]);
  30. const [issueSelected, setIssueSelected] = React.useState({});
  31. const [issueCombo, setIssueCombo] = React.useState([]);
  32. const [groupSelected, setGroupSelected] = React.useState({});
  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. setFromDateValue(minDate);
  39. }, [minDate]);
  40. React.useEffect(() => {
  41. setToDateValue(maxDate);
  42. }, [maxDate]);
  43. const _sx = {
  44. padding: "4 2 4 2",
  45. boxShadow: 1,
  46. border: 1,
  47. borderColor: '#DDD',
  48. '& .MuiDataGrid-cell': {
  49. borderTop: 1,
  50. borderBottom: 1,
  51. borderColor: "#EEE"
  52. },
  53. '& .MuiDataGrid-footerContainer': {
  54. border: 1,
  55. borderColor: "#EEE"
  56. }
  57. }
  58. const { reset, register, handleSubmit } = useForm()
  59. const onSubmit = (data) => {
  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. refNo: data.refNo,
  72. code: data.code,
  73. issueId: issueSelected?.id,
  74. gazettGroup: groupSelected?.type,
  75. dateFrom: sentDateFrom,
  76. dateTo: sentDateTo,
  77. };
  78. if(status?.type && status?.type != 'all'){
  79. if (status?.type == "Confirmed"){
  80. temp["replyed"] = "T";
  81. temp["action"] = true;
  82. }else if(status?.type == "Re-proofing"){
  83. temp["replyed"] = "T";
  84. temp["action"] = false;
  85. }else if(status?.type == "No Reply"){
  86. temp["replyed"] = "F";
  87. temp["timeOut"] = "T";
  88. }else{
  89. temp["replyed"] = "F";
  90. temp["timeOut"] = "F";
  91. }
  92. }
  93. applySearch(temp);
  94. };
  95. React.useEffect(() => {
  96. if (issueComboData && issueComboData.length > 0) {
  97. setIssueCombo(issueComboData);
  98. }
  99. }, [issueComboData]);
  100. function resetForm() {
  101. setType([]);
  102. setStatus(ComboData.proofStatusFull[0]);
  103. setIssueSelected({});
  104. setGroupSelected({});
  105. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  106. setMaxDate(DateUtils.dateValue(new Date()))
  107. reset();
  108. }
  109. function getIssueLabel(data) {
  110. let issueYear = data.issueYear
  111. let volume = data.volume;
  112. let issueNo = data.issueNo;
  113. let issueDate = data.issueDate;
  114. if (locale === 'zh-HK') {
  115. return issueYear
  116. + " 第" + volume + "卷,"
  117. + " 第" + issueNo + "期,"
  118. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  119. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  120. } else if (locale === 'zh-CN') {
  121. return issueYear
  122. + " 第" + volume + "卷,"
  123. + " 第" + issueNo + "期,"
  124. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  125. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  126. }
  127. return issueYear
  128. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  129. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  130. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  131. }
  132. return (
  133. <MainCard xs={12} md={12} lg={12}
  134. border={false}
  135. content={false}
  136. sx={_sx}
  137. >
  138. <form onSubmit={handleSubmit(onSubmit)}>
  139. {/*row 1*/}
  140. <CardContent sx={{ px: 2.5, pt: 3 }}>
  141. <Grid item justifyContent="space-between" alignItems="center">
  142. <Typography variant="pnspsFormHeader">
  143. <FormattedMessage id="searchForm"/>
  144. </Typography>
  145. </Grid>
  146. </CardContent>
  147. {/*row 2*/}
  148. <Grid container alignItems={"center"}>
  149. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  150. <TextField
  151. fullWidth
  152. {...register("refNo")}
  153. id='refNo'
  154. label={intl.formatMessage({id: 'proofId'}) }
  155. defaultValue={searchCriteria.refNo}
  156. InputLabelProps={{
  157. shrink: true
  158. }}
  159. />
  160. </Grid>
  161. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  162. <TextField
  163. fullWidth
  164. {...register("code")}
  165. id='code'
  166. label={intl.formatMessage({id: 'applicationId'})}
  167. defaultValue={searchCriteria.code}
  168. InputLabelProps={{
  169. shrink: true
  170. }}
  171. />
  172. </Grid>
  173. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  174. <Autocomplete
  175. {...register("issueId")}
  176. disablePortal
  177. id="issueId"
  178. options={issueCombo}
  179. value={issueSelected}
  180. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  181. getOptionLabel={(option) => getIssueLabel(option)}
  182. onChange={(event, newValue) => {
  183. setIssueSelected(newValue);
  184. }}
  185. renderInput={(params) => (
  186. <TextField {...params}
  187. label={intl.formatMessage({id: 'gazetteCount'})}
  188. InputLabelProps={{
  189. shrink: true
  190. }}
  191. />
  192. )}
  193. />
  194. </Grid>
  195. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  196. <Autocomplete
  197. {...register("gazettGroup")}
  198. disablePortal
  199. id="gazettGroup"
  200. options={ComboData.groupTitle}
  201. value={groupSelected}
  202. inputValue={(groupSelected?.labelCht) ? groupSelected?.labelCht : ""}
  203. getOptionLabel={(option) => option.labelCht}
  204. onChange={(event, newValue) => {
  205. setGroupSelected(newValue);
  206. }}
  207. renderInput={(params) => (
  208. <TextField {...params}
  209. label="憲報類型"
  210. InputLabelProps={{
  211. shrink: true
  212. }}
  213. />
  214. )}
  215. />
  216. </Grid> */}
  217. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  218. <Grid container spacing={1}>
  219. <Grid item xs={6}>
  220. <LocalizationProvider dateAdapter={AdapterDayjs}>
  221. <DemoItem components={['DatePicker']}>
  222. <DatePicker
  223. id="dateFrom"
  224. // onError={(newError) => setReceiptFromError(newError)}
  225. slotProps={{
  226. field: { readOnly: true, },
  227. // textField: {
  228. // helperText: receiptFromErrorMessage,
  229. // },
  230. }}
  231. format="DD/MM/YYYY"
  232. label={intl.formatMessage({id: 'proofDateFrom'})}
  233. value={minDate === null ? null : dayjs(minDate)}
  234. maxDate={maxDate === null ? null : dayjs(maxDate)}
  235. onChange={(newValue) => {
  236. // console.log(newValue)
  237. if(newValue!=null){
  238. setMinDate(newValue);
  239. }
  240. }}
  241. />
  242. </DemoItem >
  243. </LocalizationProvider>
  244. </Grid>
  245. <Grid item xs={6}>
  246. <LocalizationProvider dateAdapter={AdapterDayjs}>
  247. <DemoItem components={['DatePicker']}>
  248. <DatePicker
  249. id="dateTo"
  250. // onError={(newError) => setReceiptFromError(newError)}
  251. slotProps={{
  252. field: { readOnly: true, },
  253. // textField: {
  254. // helperText: receiptFromErrorMessage,
  255. // },
  256. }}
  257. format="DD/MM/YYYY"
  258. label={intl.formatMessage({id: 'proofDateTo'})}
  259. value={maxDate === null ? null : dayjs(maxDate)}
  260. minDate={minDate === null ? null : dayjs(minDate)}
  261. onChange={(newValue) => {
  262. // console.log(newValue)
  263. if(newValue!=null){
  264. setMaxDate(newValue);
  265. }
  266. }}
  267. />
  268. </DemoItem >
  269. </LocalizationProvider>
  270. </Grid>
  271. </Grid>
  272. </Grid>
  273. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  274. <TextField
  275. fullWidth
  276. {...register("contact")}
  277. id="contact"
  278. label="聯絡人"
  279. defaultValue={searchCriteria.contact}
  280. InputLabelProps={{
  281. shrink: true
  282. }}
  283. />
  284. </Grid> */}
  285. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  286. <Autocomplete
  287. {...register("status")}
  288. disablePortal={false}
  289. size="small"
  290. id="status"
  291. disableClearable
  292. filterOptions={(options) => options}
  293. options={ComboData.proofStatusFull}
  294. value={status}
  295. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  296. inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""}
  297. onChange={(event, newValue) => {
  298. if (newValue !== null) {
  299. setStatus(newValue);
  300. }else{
  301. setStatus(ComboData.proofStatus[0]);
  302. }
  303. }}
  304. renderInput={(params) => (
  305. <TextField {...params}
  306. label={intl.formatMessage({id: 'status'})}
  307. />
  308. )}
  309. InputLabelProps={{
  310. shrink: true
  311. }}
  312. />
  313. </Grid>
  314. </Grid>
  315. {/*last row*/}
  316. <Grid container maxWidth justifyContent="flex-end">
  317. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  318. <Grid item sx={{ mr: 3, mb: 3 }}>
  319. <Button
  320. variant="contained"
  321. color="cancel"
  322. onClick={resetForm}
  323. aria-label={intl.formatMessage({id: 'reset'})}
  324. >
  325. <FormattedMessage id="reset"/>
  326. </Button>
  327. </Grid>
  328. <Grid item sx={{mr: 3, mb: 3 }}>
  329. <Button
  330. variant="contained"
  331. type="submit"
  332. aria-label={intl.formatMessage({id: 'submit'})}
  333. >
  334. <FormattedMessage id="submit"/>
  335. </Button>
  336. </Grid>
  337. </ThemeProvider>
  338. </Grid>
  339. </form>
  340. </MainCard>
  341. );
  342. };
  343. export default SearchPublicNoticeForm;