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.
 
 

211 lines
8.3 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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  18. const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
  19. const intl = useIntl();
  20. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  21. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  22. const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
  23. const _sx = {
  24. padding: "4 2 4 2",
  25. boxShadow: 1,
  26. border: 1,
  27. borderColor: '#DDD',
  28. '& .MuiDataGrid-cell': {
  29. borderTop: 1,
  30. borderBottom: 1,
  31. borderColor: "#EEE"
  32. },
  33. '& .MuiDataGrid-footerContainer': {
  34. border: 1,
  35. borderColor: "#EEE"
  36. }
  37. }
  38. const { reset, register, handleSubmit } = useForm()
  39. const onSubmit = (data) => {
  40. const temp = {
  41. code: data.code,
  42. tarnsNo: data.tarnsNo,
  43. dateFrom: data.dateFrom,
  44. dateTo: data.dateTo,
  45. status : (status?.type && status?.type != 'all') ? status?.type : "",
  46. };
  47. applySearch(temp);
  48. };
  49. function resetForm() {
  50. reset();
  51. }
  52. return (
  53. <MainCard xs={12} md={12} lg={12}
  54. border={false}
  55. content={false}
  56. sx={_sx}
  57. >
  58. <form onSubmit={handleSubmit(onSubmit)}>
  59. {/*row 1*/}
  60. <CardContent sx={{ px: 2.5, pt: 3 }}>
  61. <Grid item justifyContent="space-between" alignItems="center" >
  62. <Typography variant="pnspsFormHeader">
  63. <FormattedMessage id="searchForm"/>
  64. </Typography>
  65. </Grid>
  66. </CardContent>
  67. {/*row 2*/}
  68. <Grid container alignItems={"center"}>
  69. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  70. <TextField
  71. fullWidth
  72. {...register("code")}
  73. id='code'
  74. label={intl.formatMessage({id: 'applicationId'}) + ":"}
  75. defaultValue={searchCriteria.code}
  76. InputLabelProps={{
  77. shrink: true
  78. }}
  79. />
  80. </Grid>
  81. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  82. <Grid container>
  83. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  84. <TextField
  85. fullWidth
  86. {...register("dateFrom")}
  87. id="dateFrom"
  88. type="date"
  89. label={intl.formatMessage({id: 'payDateFrom'})}
  90. defaultValue={searchCriteria.dateFrom}
  91. InputProps={{ inputProps: { max: maxDate } }}
  92. onChange={(newValue) => {
  93. setMinDate(DateUtils.dateStr(newValue));
  94. }}
  95. InputLabelProps={{
  96. shrink: true
  97. }}
  98. />
  99. </Grid>
  100. <Grid item xs={1.5} s={1.5} md={1.5} lg={1} sx={{mt:1.3, display: 'flex', justifyContent:"center", alignItems: 'flex-start'}}>
  101. <FormattedMessage id="to" />
  102. </Grid>
  103. <Grid item xs={5.25} s={5.25} md={5.25} lg={5.5}>
  104. <TextField
  105. fullWidth
  106. InputLabelProps={{
  107. shrink: true
  108. }}
  109. {...register("dateTo")}
  110. InputProps={{ inputProps: { min: minDate } }}
  111. onChange={(newValue) => {
  112. setMaxDate(DateUtils.dateStr(newValue));
  113. }}
  114. id="dateTo"
  115. type="date"
  116. //label="付款日期(到)"
  117. defaultValue={searchCriteria.dateTo}
  118. />
  119. </Grid>
  120. </Grid>
  121. </Grid>
  122. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  123. <TextField
  124. fullWidth
  125. {...register("tarnsNo")}
  126. id='tarnsNo'
  127. label={intl.formatMessage({id: 'payId'})+":"}
  128. defaultValue={searchCriteria.tarnsNo}
  129. InputLabelProps={{
  130. shrink: true
  131. }}
  132. />
  133. </Grid>
  134. <Grid item xs={12} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  135. <Autocomplete
  136. {...register("status")}
  137. disablePortal={false}
  138. id="status"
  139. size="small"
  140. filterOptions={(options) => options}
  141. options={ComboData.paymentStatus}
  142. value={status}
  143. getOptionLabel={(option) => option.type? intl.formatMessage({ id: option.i18nLabel }) : ""}
  144. inputValue={status? intl.formatMessage({ id: status.i18nLabel }) : ""}
  145. onChange={(event, newValue) => {
  146. if (newValue !== null) {
  147. setStatus(newValue);
  148. }
  149. }}
  150. renderInput={(params) => (
  151. <TextField {...params}
  152. label={intl.formatMessage({id: 'status'})}
  153. />
  154. )}
  155. InputLabelProps={{
  156. shrink: true
  157. }}
  158. />
  159. </Grid>
  160. </Grid>
  161. {/*last row*/}
  162. <Grid container maxWidth justifyContent="flex-end">
  163. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  164. <Grid item sx={{mr: 3, mb: 3 }}>
  165. <Button
  166. color="cancel"
  167. variant="contained"
  168. onClick={resetForm}
  169. aria-label={intl.formatMessage({id: 'reset'})}
  170. >
  171. <FormattedMessage id="reset"/>
  172. </Button>
  173. </Grid>
  174. <Grid item sx={{mr: 3, mb: 3 }}>
  175. <Button
  176. variant="contained"
  177. type="submit"
  178. aria-label={intl.formatMessage({id: 'submit'})}
  179. >
  180. <FormattedMessage id="submit"/>
  181. </Button>
  182. </Grid>
  183. </ThemeProvider>
  184. </Grid>
  185. </form>
  186. </MainCard>
  187. );
  188. };
  189. export default SearchPublicNoticeForm;