You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

301 rivejä
12 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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, issueComboData
  20. }) => {
  21. const intl = useIntl();
  22. const [type, setType] = React.useState([]);
  23. const [status, setStatus] = React.useState(ComboData.proofStatus[0]);
  24. const [issueSelected, setIssueSelected] = React.useState({});
  25. const [issueCombo, setIssueCombo] = React.useState([]);
  26. const [groupSelected, setGroupSelected] = React.useState({});
  27. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  28. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  29. const _sx = {
  30. padding: "4 2 4 2",
  31. boxShadow: 1,
  32. border: 1,
  33. borderColor: '#DDD',
  34. '& .MuiDataGrid-cell': {
  35. borderTop: 1,
  36. borderBottom: 1,
  37. borderColor: "#EEE"
  38. },
  39. '& .MuiDataGrid-footerContainer': {
  40. border: 1,
  41. borderColor: "#EEE"
  42. }
  43. }
  44. const { reset, register, handleSubmit } = useForm()
  45. const onSubmit = (data) => {
  46. let typeArray = [];
  47. for (let i = 0; i < type.length; i++) {
  48. typeArray.push(type[i].label);
  49. }
  50. const temp = {
  51. refNo: data.refNo,
  52. code: data.code,
  53. issueId: issueSelected?.id,
  54. gazettGroup: groupSelected?.type,
  55. dateFrom: data.dateFrom,
  56. dateTo: data.dateTo,
  57. //contact: data.contact,
  58. replyed: (status?.type && status?.type != 'all') ? status?.type : "",
  59. };
  60. applySearch(temp);
  61. };
  62. React.useEffect(() => {
  63. if (issueComboData && issueComboData.length > 0) {
  64. setIssueCombo(issueComboData);
  65. }
  66. }, [issueComboData]);
  67. function resetForm() {
  68. setType([]);
  69. setStatus(ComboData.proofStatus[0]);
  70. setIssueSelected({});
  71. setGroupSelected({});
  72. reset();
  73. }
  74. function getIssueLabel(data) {
  75. if (data == {}) return "";
  76. return data.year
  77. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  78. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  79. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  80. }
  81. return (
  82. <MainCard xs={12} md={12} lg={12}
  83. border={false}
  84. content={false}
  85. sx={_sx}
  86. >
  87. <form onSubmit={handleSubmit(onSubmit)}>
  88. {/*row 1*/}
  89. <CardContent sx={{ px: 2.5, pt: 3 }}>
  90. <Grid item justifyContent="space-between" alignItems="center">
  91. <Typography variant="h4">
  92. <FormattedMessage id="search"/>
  93. </Typography>
  94. </Grid>
  95. </CardContent>
  96. {/*row 2*/}
  97. <Grid container alignItems={"center"}>
  98. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  99. <TextField
  100. fullWidth
  101. {...register("refNo")}
  102. id='refNo'
  103. label={intl.formatMessage({id: 'proofId'}) + ":"}
  104. defaultValue={searchCriteria.refNo}
  105. InputLabelProps={{
  106. shrink: true
  107. }}
  108. />
  109. </Grid>
  110. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  111. <TextField
  112. fullWidth
  113. {...register("code")}
  114. id='code'
  115. label={intl.formatMessage({id: 'applicationId'}) + ":"}
  116. defaultValue={searchCriteria.code}
  117. InputLabelProps={{
  118. shrink: true
  119. }}
  120. />
  121. </Grid>
  122. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  123. <Autocomplete
  124. {...register("issueId")}
  125. disablePortal
  126. id="issueId"
  127. options={issueCombo}
  128. value={issueSelected}
  129. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  130. getOptionLabel={(option) => getIssueLabel(option)}
  131. onChange={(event, newValue) => {
  132. setIssueSelected(newValue);
  133. }}
  134. renderInput={(params) => (
  135. <TextField {...params}
  136. label={intl.formatMessage({id: 'gazetteCount'})}
  137. InputLabelProps={{
  138. shrink: true
  139. }}
  140. />
  141. )}
  142. />
  143. </Grid>
  144. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  145. <Autocomplete
  146. {...register("gazettGroup")}
  147. disablePortal
  148. id="gazettGroup"
  149. options={ComboData.groupTitle}
  150. value={groupSelected}
  151. inputValue={(groupSelected?.labelCht) ? groupSelected?.labelCht : ""}
  152. getOptionLabel={(option) => option.labelCht}
  153. onChange={(event, newValue) => {
  154. setGroupSelected(newValue);
  155. }}
  156. renderInput={(params) => (
  157. <TextField {...params}
  158. label="憲報類型"
  159. InputLabelProps={{
  160. shrink: true
  161. }}
  162. />
  163. )}
  164. />
  165. </Grid> */}
  166. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  167. <Grid container>
  168. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  169. <TextField
  170. fullWidth
  171. {...register("dateFrom")}
  172. id="dateFrom"
  173. type="date"
  174. label={intl.formatMessage({id: 'proofDateFrom'})}
  175. defaultValue={searchCriteria.dateFrom}
  176. InputProps={{ inputProps: { max: maxDate } }}
  177. onChange={(newValue) => {
  178. setMinDate(DateUtils.dateStr(newValue));
  179. }}
  180. InputLabelProps={{
  181. shrink: true
  182. }}
  183. />
  184. </Grid>
  185. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:1.3, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  186. </Grid>
  187. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  188. <TextField
  189. fullWidth
  190. InputLabelProps={{
  191. shrink: true
  192. }}
  193. {...register("dateTo")}
  194. InputProps={{ inputProps: { min: minDate } }}
  195. onChange={(newValue) => {
  196. setMaxDate(DateUtils.dateStr(newValue));
  197. }}
  198. id="dateTo"
  199. type="date"
  200. //label="校對日期(到)"
  201. defaultValue={searchCriteria.dateTo}
  202. />
  203. </Grid>
  204. </Grid>
  205. </Grid>
  206. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  207. <TextField
  208. fullWidth
  209. {...register("contact")}
  210. id="contact"
  211. label="聯絡人"
  212. defaultValue={searchCriteria.contact}
  213. InputLabelProps={{
  214. shrink: true
  215. }}
  216. />
  217. </Grid> */}
  218. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  219. <Autocomplete
  220. {...register("status")}
  221. disablePortal={false}
  222. size="small"
  223. id="status"
  224. filterOptions={(options) => options}
  225. options={ComboData.proofStatus}
  226. value={status}
  227. getOptionLabel={(option) => option.labelCht}
  228. inputValue={status?.labelCht ? status?.labelCht : ""}
  229. onChange={(event, newValue) => {
  230. if (newValue !== null) {
  231. setStatus(newValue);
  232. }
  233. }}
  234. renderInput={(params) => (
  235. <TextField {...params}
  236. label={intl.formatMessage({id: 'status'})}
  237. />
  238. )}
  239. InputLabelProps={{
  240. shrink: true
  241. }}
  242. />
  243. </Grid>
  244. </Grid>
  245. {/*last row*/}
  246. <Grid container maxWidth justifyContent="flex-end">
  247. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  248. <Grid item sx={{ mr: 3, mb: 3 }}>
  249. <Button
  250. variant="contained"
  251. onClick={resetForm}
  252. >
  253. <FormattedMessage id="reset"/>
  254. </Button>
  255. </Grid>
  256. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  257. <Button
  258. variant="contained"
  259. type="submit"
  260. >
  261. <FormattedMessage id="submit"/>
  262. </Button>
  263. </Grid>
  264. </ThemeProvider>
  265. </Grid>
  266. </form>
  267. </MainCard>
  268. );
  269. };
  270. export default SearchPublicNoticeForm;