Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

281 řádky
11 KiB

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