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

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