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

260 lines
11 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. };
  67. applySearch(temp);
  68. };
  69. function resetForm() {
  70. setStatus(ComboData.paymentStatus[0]);
  71. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  72. setMaxDate(DateUtils.dateValue(new Date()))
  73. reset({
  74. code:"",
  75. transNo:""
  76. });
  77. localStorage.setItem('searchCriteria',"")
  78. }
  79. return (
  80. <MainCard xs={12} md={12} lg={12}
  81. border={false}
  82. content={false}
  83. sx={_sx}
  84. >
  85. <form onSubmit={handleSubmit(onSubmit)}>
  86. {/*row 1*/}
  87. <CardContent sx={{ px: 2.5, pt: 3 }}>
  88. <Grid item justifyContent="space-between" alignItems="center" >
  89. <Typography variant="pnspsFormHeader">
  90. <FormattedMessage id="searchForm"/>
  91. </Typography>
  92. </Grid>
  93. </CardContent>
  94. {/*row 2*/}
  95. <Grid container alignItems={"center"}>
  96. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  97. <TextField
  98. fullWidth
  99. {...register("code")}
  100. id='code'
  101. label={intl.formatMessage({id: 'applicationId'})}
  102. defaultValue={searchCriteria.code}
  103. InputLabelProps={{
  104. shrink: true
  105. }}
  106. />
  107. </Grid>
  108. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  109. <Grid container spacing={1}>
  110. <Grid item xs={6}>
  111. <LocalizationProvider dateAdapter={AdapterDayjs}>
  112. <DemoItem components={['DatePicker']}>
  113. <DatePicker
  114. id="dateFrom"
  115. // onError={(newError) => setReceiptFromError(newError)}
  116. slotProps={{
  117. field: { readOnly: true, },
  118. // textField: {
  119. // helperText: receiptFromErrorMessage,
  120. // },
  121. }}
  122. format="DD/MM/YYYY"
  123. label={intl.formatMessage({id: 'payDateFrom'})}
  124. // defaultValue={searchCriteria.dateFrom}
  125. value={minDate === null ? null : dayjs(minDate)}
  126. maxDate={maxDate === null ? null : dayjs(maxDate)}
  127. onChange={(newValue) => {
  128. // console.log(newValue)
  129. if(newValue!=null){
  130. setMinDate(newValue);
  131. }
  132. }}
  133. />
  134. </DemoItem >
  135. </LocalizationProvider>
  136. </Grid>
  137. <Grid item xs={6}>
  138. <LocalizationProvider dateAdapter={AdapterDayjs}>
  139. <DemoItem components={['DatePicker']}>
  140. <DatePicker
  141. id="dateTo"
  142. // onError={(newError) => setReceiptFromError(newError)}
  143. slotProps={{
  144. field: { readOnly: true, },
  145. // textField: {
  146. // helperText: receiptFromErrorMessage,
  147. // },
  148. }}
  149. format="DD/MM/YYYY"
  150. label={intl.formatMessage({id: 'payDateTo'})}
  151. // defaultValue={searchCriteria.dateTo}
  152. value={maxDate === null ? null : dayjs(maxDate)}
  153. minDate={minDate === null ? null : dayjs(minDate)}
  154. onChange={(newValue) => {
  155. // console.log(newValue)
  156. if(newValue!=null){
  157. setMaxDate(newValue);
  158. }
  159. }}
  160. />
  161. </DemoItem >
  162. </LocalizationProvider>
  163. </Grid>
  164. </Grid>
  165. </Grid>
  166. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  167. <Autocomplete
  168. {...register("status")}
  169. disablePortal={false}
  170. id="status"
  171. size="small"
  172. disableClearable
  173. filterOptions={(options) => options}
  174. options={ComboData.paymentStatus}
  175. value={status}
  176. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  177. inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""}
  178. onChange={(event, newValue) => {
  179. if (newValue !== null) {
  180. setStatus(newValue);
  181. }else{
  182. setStatus(ComboData.paymentStatus[0]);
  183. }
  184. }}
  185. renderInput={(params) => (
  186. <TextField {...params}
  187. label={intl.formatMessage({id: 'status'})}
  188. />
  189. )}
  190. InputLabelProps={{
  191. shrink: true
  192. }}
  193. />
  194. </Grid>
  195. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  196. <TextField
  197. fullWidth
  198. {...register("transNo")}
  199. id='transNo'
  200. label={intl.formatMessage({id: 'payId'})}
  201. defaultValue={searchCriteria.transNo}
  202. InputLabelProps={{
  203. shrink: true
  204. }}
  205. />
  206. </Grid>
  207. </Grid>
  208. {/*last row*/}
  209. <Grid container maxWidth justifyContent="flex-end">
  210. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  211. <Grid item sx={{mr: 3, mb: 3 }}>
  212. <Button
  213. color="cancel"
  214. variant="contained"
  215. onClick={resetForm}
  216. aria-label={intl.formatMessage({id: 'reset'})}
  217. >
  218. <FormattedMessage id="reset"/>
  219. </Button>
  220. </Grid>
  221. <Grid item sx={{mr: 3, mb: 3 }}>
  222. <Button
  223. variant="contained"
  224. type="submit"
  225. aria-label={intl.formatMessage({id: 'submit'})}
  226. disabled={onGridReady}
  227. >
  228. <FormattedMessage id="submit"/>
  229. </Button>
  230. </Grid>
  231. </ThemeProvider>
  232. </Grid>
  233. </form>
  234. </MainCard>
  235. );
  236. };
  237. export default SearchPublicNoticeForm;