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

304 lines
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.issueYear
  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="pnspsFormHeader">
  92. <FormattedMessage id="searchForm"/>
  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. <FormattedMessage id="to" />
  187. </Grid>
  188. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  189. <TextField
  190. fullWidth
  191. InputLabelProps={{
  192. shrink: true
  193. }}
  194. {...register("dateTo")}
  195. InputProps={{ inputProps: { min: minDate } }}
  196. onChange={(newValue) => {
  197. setMaxDate(DateUtils.dateStr(newValue));
  198. }}
  199. id="dateTo"
  200. type="date"
  201. //label="校對日期(到)"
  202. defaultValue={searchCriteria.dateTo}
  203. />
  204. </Grid>
  205. </Grid>
  206. </Grid>
  207. {/* <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  208. <TextField
  209. fullWidth
  210. {...register("contact")}
  211. id="contact"
  212. label="聯絡人"
  213. defaultValue={searchCriteria.contact}
  214. InputLabelProps={{
  215. shrink: true
  216. }}
  217. />
  218. </Grid> */}
  219. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  220. <Autocomplete
  221. {...register("status")}
  222. disablePortal={false}
  223. size="small"
  224. id="status"
  225. filterOptions={(options) => options}
  226. options={ComboData.proofStatus}
  227. value={status}
  228. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  229. inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""}
  230. onChange={(event, newValue) => {
  231. if (newValue !== null) {
  232. setStatus(newValue);
  233. }
  234. }}
  235. renderInput={(params) => (
  236. <TextField {...params}
  237. label={intl.formatMessage({id: 'status'})}
  238. />
  239. )}
  240. InputLabelProps={{
  241. shrink: true
  242. }}
  243. />
  244. </Grid>
  245. </Grid>
  246. {/*last row*/}
  247. <Grid container maxWidth justifyContent="flex-end">
  248. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  249. <Grid item sx={{ mr: 3, mb: 3 }}>
  250. <Button
  251. variant="contained"
  252. color="cancel"
  253. onClick={resetForm}
  254. aria-label={intl.formatMessage({id: 'reset'})}
  255. >
  256. <FormattedMessage id="reset"/>
  257. </Button>
  258. </Grid>
  259. <Grid item sx={{mr: 3, mb: 3 }}>
  260. <Button
  261. variant="contained"
  262. type="submit"
  263. aria-label={intl.formatMessage({id: 'submit'})}
  264. >
  265. <FormattedMessage id="submit"/>
  266. </Button>
  267. </Grid>
  268. </ThemeProvider>
  269. </Grid>
  270. </form>
  271. </MainCard>
  272. );
  273. };
  274. export default SearchPublicNoticeForm;