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.
 
 

267 line
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 DateUtils from "utils/DateUtils";
  13. import * as ComboData from "utils/ComboData";
  14. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  15. import {ThemeProvider} from "@emotion/react";
  16. import {FormattedMessage, useIntl} from "react-intl";
  17. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  18. import dayjs from "dayjs";
  19. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  20. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  21. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  22. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  23. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, onGridReady }) => {
  24. const intl = useIntl();
  25. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  26. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  27. const [status, setStatus] = React.useState(searchCriteria.status!=undefined?ComboData.paymentStatus.find(item => item.type === searchCriteria.status):ComboData.paymentStatus[0]);
  28. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  29. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  30. React.useEffect(() => {
  31. // console.log(minDate)
  32. setFromDateValue(minDate);
  33. }, [minDate]);
  34. React.useEffect(() => {
  35. setToDateValue(maxDate);
  36. }, [maxDate]);
  37. const _sx = {
  38. padding: "4 2 4 2",
  39. boxShadow: 1,
  40. border: 1,
  41. borderColor: '#DDD',
  42. '& .MuiDataGrid-cell': {
  43. borderTop: 1,
  44. borderBottom: 1,
  45. borderColor: "#EEE"
  46. },
  47. '& .MuiDataGrid-footerContainer': {
  48. border: 1,
  49. borderColor: "#EEE"
  50. }
  51. }
  52. const { reset, register, handleSubmit } = useForm()
  53. const onSubmit = (data) => {
  54. let sentDateFrom = "";
  55. let sentDateTo = "";
  56. if( fromDateValue!="dd / mm / yyyy"&&toDateValue!="dd / mm / yyyy"){
  57. sentDateFrom = DateUtils.dateValue(fromDateValue)
  58. sentDateTo = DateUtils.dateValue(toDateValue)
  59. }
  60. const temp = {
  61. code: data.code,
  62. transNo: data.transNo,
  63. dateFrom: sentDateFrom,
  64. dateTo: sentDateTo,
  65. status : (status?.type && status?.type != 'all') ? status?.type : "",
  66. start:0,
  67. limit:10
  68. };
  69. applySearch(temp);
  70. };
  71. function resetForm() {
  72. setStatus(ComboData.paymentStatus[0]);
  73. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  74. setMaxDate(DateUtils.dateValue(new Date()))
  75. reset({
  76. code:"",
  77. transNo:""
  78. });
  79. localStorage.setItem('searchCriteria',"")
  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("code")}
  102. id='code'
  103. label={intl.formatMessage({id: 'applicationId'})}
  104. defaultValue={searchCriteria.code}
  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. <Grid container spacing={1}>
  112. <Grid item xs={6}>
  113. <LocalizationProvider dateAdapter={AdapterDayjs}>
  114. <DemoItem components={['DatePicker']}>
  115. <DatePicker
  116. id="dateFrom"
  117. // onError={(newError) => setReceiptFromError(newError)}
  118. slotProps={{
  119. field: { readOnly: true, },
  120. // textField: {
  121. // helperText: receiptFromErrorMessage,
  122. // },
  123. }}
  124. format="DD/MM/YYYY"
  125. label={intl.formatMessage({id: 'payDateFrom'})}
  126. // defaultValue={searchCriteria.dateFrom}
  127. value={minDate === null ? null : dayjs(minDate)}
  128. maxDate={maxDate === null ? null : dayjs(maxDate)}
  129. onChange={(newValue) => {
  130. // console.log(newValue)
  131. if(newValue!=null){
  132. setMinDate(newValue);
  133. }
  134. }}
  135. />
  136. </DemoItem >
  137. </LocalizationProvider>
  138. </Grid>
  139. <Grid item xs={6}>
  140. <LocalizationProvider dateAdapter={AdapterDayjs}>
  141. <DemoItem components={['DatePicker']}>
  142. <DatePicker
  143. id="dateTo"
  144. // onError={(newError) => setReceiptFromError(newError)}
  145. slotProps={{
  146. field: { readOnly: true, },
  147. // textField: {
  148. // helperText: receiptFromErrorMessage,
  149. // },
  150. }}
  151. format="DD/MM/YYYY"
  152. label={intl.formatMessage({id: 'payDateTo'})}
  153. // defaultValue={searchCriteria.dateTo}
  154. value={maxDate === null ? null : dayjs(maxDate)}
  155. minDate={minDate === null ? null : dayjs(minDate)}
  156. onChange={(newValue) => {
  157. // console.log(newValue)
  158. if(newValue!=null){
  159. setMaxDate(newValue);
  160. }
  161. }}
  162. />
  163. </DemoItem >
  164. </LocalizationProvider>
  165. </Grid>
  166. </Grid>
  167. </Grid>
  168. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  169. <Autocomplete
  170. {...register("status")}
  171. disablePortal={false}
  172. id="status"
  173. size="small"
  174. disableClearable
  175. filterOptions={(options) => options}
  176. options={ComboData.paymentStatus}
  177. value={status}
  178. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  179. inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""}
  180. onChange={(event, newValue) => {
  181. if (newValue !== null) {
  182. setStatus(newValue);
  183. }else{
  184. setStatus(ComboData.paymentStatus[0]);
  185. }
  186. }}
  187. sx={{
  188. '& .MuiInputBase-root': { alignItems: 'center' },
  189. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  190. '& .MuiOutlinedInput-root': { height: 40 }
  191. }}
  192. renderInput={(params) => (
  193. <TextField {...params}
  194. label={intl.formatMessage({id: 'status'})}
  195. />
  196. )}
  197. InputLabelProps={{
  198. shrink: true
  199. }}
  200. />
  201. </Grid>
  202. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  203. <TextField
  204. fullWidth
  205. {...register("transNo")}
  206. id='transNo'
  207. label={intl.formatMessage({id: 'payId'})}
  208. defaultValue={searchCriteria.transNo}
  209. InputLabelProps={{
  210. shrink: true
  211. }}
  212. />
  213. </Grid>
  214. </Grid>
  215. {/*last row*/}
  216. <Grid container maxWidth justifyContent="flex-end">
  217. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  218. <Grid item sx={{mr: 3, mb: 3 }}>
  219. <Button
  220. color="cancel"
  221. variant="contained"
  222. onClick={resetForm}
  223. aria-label={intl.formatMessage({id: 'reset'})}
  224. >
  225. <FormattedMessage id="reset"/>
  226. </Button>
  227. </Grid>
  228. <Grid item sx={{mr: 3, mb: 3 }}>
  229. <Button
  230. variant="contained"
  231. type="submit"
  232. aria-label={intl.formatMessage({id: 'submit'})}
  233. disabled={onGridReady}
  234. >
  235. <FormattedMessage id="submit"/>
  236. </Button>
  237. </Grid>
  238. </ThemeProvider>
  239. </Grid>
  240. </form>
  241. </MainCard>
  242. );
  243. };
  244. export default SearchPublicNoticeForm;