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

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