您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

249 行
9.9 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Typography
  6. } from '@mui/material';
  7. import MainCard from "components/MainCard";
  8. import { useForm } from "react-hook-form";
  9. import * as React from "react";
  10. import * as DateUtils from "utils/DateUtils";
  11. import { ThemeProvider } from "@emotion/react";
  12. // import { useNavigate } from "react-router-dom";
  13. import { PNSPS_BUTTON_THEME } from "../../../themes/buttonConst";
  14. import { FormattedMessage, useIntl } from "react-intl";
  15. import { makeStyles } from '@mui/styles';
  16. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  17. const useStyles = makeStyles(() => ({
  18. root: {
  19. position: "relative"
  20. },
  21. display: {
  22. position: "absolute",
  23. top: 2,
  24. left: 12,
  25. bottom: 2,
  26. background: "white",
  27. pointerEvents: "none",
  28. right: 50,
  29. display: "flex",
  30. alignItems: "center"
  31. },
  32. }));
  33. const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
  34. // const navigate = useNavigate()
  35. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  36. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  37. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  38. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  39. const intl = useIntl();
  40. React.useEffect(() => {
  41. // console.log(minDate)
  42. setFromDateValue(minDate);
  43. }, [minDate]);
  44. React.useEffect(() => {
  45. setToDateValue(maxDate);
  46. }, [maxDate]);
  47. function FormDateInputComponent({inputRef, ...props }) {
  48. const classes = useStyles();
  49. return (
  50. <>
  51. <div className={classes.display}>
  52. {DateUtils.dateStr(fromDateValue)=="Invalid Date"?
  53. fromDateValue
  54. :
  55. DateUtils.dateStr(fromDateValue)}
  56. </div>
  57. <input
  58. // className={classes.input}
  59. ref={inputRef}
  60. {...props}
  61. // onChange={handleChange}
  62. value={fromDateValue}
  63. max= {maxDate}
  64. />
  65. </>
  66. );
  67. }
  68. function ToDateInputComponent({inputRef, ...props }) {
  69. const classes = useStyles();
  70. return (
  71. <>
  72. <div className={classes.display}>
  73. {DateUtils.dateStr(toDateValue)=="Invalid Date"?
  74. toDateValue
  75. :
  76. DateUtils.dateStr(toDateValue)}
  77. </div>
  78. <input
  79. // className={classes.input}
  80. ref={inputRef}
  81. {...props}
  82. // onChange={handleChange}
  83. value={toDateValue}
  84. min = {minDate}
  85. />
  86. </>
  87. );
  88. }
  89. const marginBottom = 2.5;
  90. const { reset, register, handleSubmit } = useForm()
  91. const onSubmit = (data) => {
  92. let sentDateFrom = "";
  93. let sentDateTo = "";
  94. if( fromDateValue!="dd / mm / yyyy"&&toDateValue!="dd / mm / yyyy"){
  95. sentDateFrom = DateUtils.dateValue(fromDateValue)!="Invalid Date"?DateUtils.dateValue(fromDateValue):""
  96. sentDateTo = DateUtils.dateValue(toDateValue)!="Invalid Date"?DateUtils.dateValue(toDateValue):""
  97. }
  98. const temp = {
  99. key: data.key,
  100. dateFrom: sentDateFrom,
  101. dateTo: sentDateTo,
  102. };
  103. applySearch(temp);
  104. };
  105. function resetForm() {
  106. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  107. setMaxDate(DateUtils.dateValue(new Date()))
  108. reset();
  109. }
  110. return (
  111. <MainCard xs={12} md={12} lg={12}
  112. border={false}
  113. content={false}
  114. sx={{ backgroundColor: '#fff' }}
  115. >
  116. <form onSubmit={handleSubmit(onSubmit)}>
  117. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom }} width="98%">
  118. {/*row 1*/}
  119. <Grid item justifyContent="space-between" alignItems="center" sx={{ mt: 1, ml: 3, mb: marginBottom }}>
  120. <Typography variant="pnspsFormHeader" >
  121. <FormattedMessage id="search"></FormattedMessage>
  122. </Typography>
  123. </Grid>
  124. {/*row 2*/}
  125. <Grid container display="flex" alignItems={"center"}>
  126. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  127. <TextField
  128. fullWidth
  129. {...register("key")}
  130. id='key'
  131. label={intl.formatMessage({ id: 'keyword' }) + ":"}
  132. defaultValue={searchCriteria.key}
  133. InputLabelProps={{
  134. shrink: true
  135. }}
  136. />
  137. </Grid>
  138. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  139. <Grid container>
  140. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  141. <TextField
  142. fullWidth
  143. {...register("dateFrom")}
  144. id="dateFrom"
  145. type="date"
  146. label={intl.formatMessage({ id: 'dateFrom' }) + ":"}
  147. defaultValue={searchCriteria.dateFrom}
  148. InputProps={{
  149. inputComponent: FormDateInputComponent,
  150. }}
  151. onChange={(newValue) => {
  152. if(newValue.target.value!=""){
  153. setMinDate(newValue.target.value);
  154. }
  155. }}
  156. InputLabelProps={{
  157. shrink: true
  158. }}
  159. sx={{ "& .MuiInputBase-input": {display:"block", textIndent: "-9999px"} }}
  160. />
  161. </Grid>
  162. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{ mt: 0.8, display: 'flex', justifyContent: "center", alignItems: 'flex-start' }}>
  163. <FormattedMessage id="to"></FormattedMessage>
  164. </Grid>
  165. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  166. <TextField
  167. fullWidth
  168. InputLabelProps={{
  169. shrink: true
  170. }}
  171. {...register("dateTo")}
  172. InputProps={{
  173. inputComponent: ToDateInputComponent,
  174. }}
  175. onChange={(newValue) => {
  176. if(newValue.target.value!=""){
  177. setMaxDate(newValue.target.value);
  178. }
  179. }}
  180. id="dateTo"
  181. type="date"
  182. //label={"Submit Date(To)"}
  183. defaultValue={searchCriteria.dateTo}
  184. sx={{ "& .MuiInputBase-input": {display:"block", textIndent: "-9999px"} }}
  185. />
  186. </Grid>
  187. </Grid>
  188. </Grid>
  189. </Grid>
  190. {/*last row*/}
  191. <Grid container maxWidth justifyContent="flex-end">
  192. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  193. {/* <Grid item sx={{ ml: 3 }}>
  194. <Button
  195. variant="contained"
  196. color="green"
  197. onClick={() => {
  198. navigate('/setting/announcement/details/' + 0);
  199. }}
  200. >
  201. <FormattedMessage id="create"></FormattedMessage>
  202. </Button>
  203. </Grid> */}
  204. <Grid item sx={{ ml: 3 }}>
  205. <Button
  206. variant="contained"
  207. onClick={resetForm}
  208. >
  209. <FormattedMessage id="reset"></FormattedMessage>
  210. </Button>
  211. </Grid>
  212. <Grid item sx={{ ml: 3 }}>
  213. <Button
  214. variant="contained"
  215. type="submit"
  216. >
  217. <FormattedMessage id="submit"></FormattedMessage>
  218. </Button>
  219. </Grid>
  220. </ThemeProvider>
  221. </Grid>
  222. </Grid>
  223. </form>
  224. </MainCard>
  225. );
  226. };
  227. export default SearchPublicNoticeForm;