Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

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