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

290 行
13 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as DateUtils from "utils/DateUtils";
  12. import * as ComboData from "utils/ComboData";
  13. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. import {DatePicker} from "@mui/x-date-pickers/DatePicker";
  16. import dayjs from "dayjs";
  17. import {DemoItem} from "@mui/x-date-pickers/internals/demo";
  18. import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
  19. import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
  20. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  21. const SearchPublicNoticeForm = ({ applySearch, searchCriteria, onGridReady }) => {
  22. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  23. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  24. const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
  25. const [payMethod, setPayMethod] = React.useState(ComboData.payMethod[0]);
  26. const { reset, register, handleSubmit } = useForm()
  27. const marginBottom = 2.5;
  28. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  29. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  30. React.useEffect(() => {
  31. if(searchCriteria.status!=undefined){
  32. if(searchCriteria.status === ""){
  33. ComboData.paymentStatus[0]
  34. }else{
  35. setStatus(ComboData.paymentStatus.find(item => item.type === searchCriteria.status))
  36. }
  37. }else{
  38. setStatus(ComboData.paymentStatus[0])
  39. }
  40. }, [searchCriteria]);
  41. React.useEffect(() => {
  42. setFromDateValue(minDate);
  43. }, [minDate]);
  44. React.useEffect(() => {
  45. setToDateValue(maxDate);
  46. }, [maxDate]);
  47. const onSubmit = (data) => {
  48. let sentDateFrom = "";
  49. let sentDateTo = "";
  50. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  51. sentDateFrom = DateUtils.dateValue(fromDateValue)
  52. sentDateTo = DateUtils.dateValue(toDateValue)
  53. }
  54. const temp = {
  55. code: data.code,
  56. transNo: data.transNo,
  57. dateFrom: sentDateFrom,
  58. dateTo: sentDateTo,
  59. status : (status?.type && status?.type != 'all') ? status?.type : "",
  60. payMethod : (payMethod?.type && payMethod?.type != 'all') ? payMethod?.type : "",
  61. start:0,
  62. limit:10
  63. };
  64. applySearch(temp);
  65. };
  66. function resetForm() {
  67. setStatus(ComboData.paymentStatus[0]);
  68. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  69. setMaxDate(DateUtils.dateValue(new Date()))
  70. reset({
  71. code:"",
  72. transNo:""
  73. });
  74. localStorage.setItem('searchCriteria',"")
  75. }
  76. return (
  77. <MainCard xs={12} md={12} lg={12}
  78. border={false}
  79. content={false}
  80. >
  81. <form onSubmit={handleSubmit(onSubmit)} >
  82. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1, mb: marginBottom}} width="98%">
  83. {/*row 1*/}
  84. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  85. <Typography variant="pnspsFormHeader" >
  86. Search
  87. </Typography>
  88. </Grid>
  89. {/*row 2*/}
  90. <Grid container display="flex" alignItems={"center"}>
  91. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3,mb: marginBottom}}>
  92. <TextField
  93. fullWidth
  94. {...register("code")}
  95. id='code'
  96. label="Application No."
  97. defaultValue={searchCriteria.code}
  98. InputLabelProps={{
  99. shrink: true
  100. }}
  101. />
  102. </Grid>
  103. <Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:marginBottom}}>
  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="Transaction Date (From)"
  119. value={minDate === null ? null : dayjs(minDate)}
  120. maxDate={maxDate === null ? null : dayjs(maxDate)}
  121. onChange={(newValue) => {
  122. // console.log(newValue)
  123. if(newValue!=null){
  124. setMinDate(newValue);
  125. }
  126. }}
  127. />
  128. </DemoItem >
  129. </LocalizationProvider>
  130. </Grid>
  131. <Grid item xs={6}>
  132. <LocalizationProvider dateAdapter={AdapterDayjs}>
  133. <DemoItem components={['DatePicker']}>
  134. <DatePicker
  135. id="dateTo"
  136. // onError={(newError) => setReceiptFromError(newError)}
  137. slotProps={{
  138. field: { readOnly: true, },
  139. // textField: {
  140. // helperText: receiptFromErrorMessage,
  141. // },
  142. }}
  143. format="DD/MM/YYYY"
  144. label="Transaction Date (To)"
  145. value={maxDate === null ? null : dayjs(maxDate)}
  146. minDate={minDate === null ? null : dayjs(minDate)}
  147. onChange={(newValue) => {
  148. // console.log(newValue)
  149. if(newValue!=null){
  150. setMaxDate(newValue);
  151. }
  152. }}
  153. />
  154. </DemoItem >
  155. </LocalizationProvider>
  156. </Grid>
  157. </Grid>
  158. </Grid>
  159. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom}}>
  160. <TextField
  161. fullWidth
  162. {...register("transNo")}
  163. id='transNo'
  164. label="Transaction No."
  165. defaultValue={searchCriteria.transNo}
  166. InputLabelProps={{
  167. shrink: true
  168. }}
  169. />
  170. </Grid>
  171. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  172. <Autocomplete
  173. {...register("status")}
  174. disablePortal={false}
  175. size="small"
  176. id="status"
  177. filterOptions={(options) => options}
  178. options={ComboData.paymentStatus}
  179. value={status}
  180. getOptionLabel={(option) => option.label}
  181. inputValue={status?.label ? status?.label : ""}
  182. onChange={(event, newValue) => {
  183. if(newValue==null){
  184. setStatus(ComboData.paymentStatus[0]);
  185. }else{
  186. setStatus(newValue);
  187. }
  188. }}
  189. sx={{
  190. '& .MuiInputBase-root': { alignItems: 'center' },
  191. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  192. '& .MuiOutlinedInput-root': { height: 40 }
  193. }}
  194. renderInput={(params) => (
  195. <TextField {...params}
  196. label="Status"
  197. />
  198. )}
  199. InputLabelProps={{
  200. shrink: true
  201. }}
  202. />
  203. </Grid>
  204. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: marginBottom }}>
  205. <Autocomplete
  206. {...register("payMethod")}
  207. disablePortal={false}
  208. size="small"
  209. id="payMethod"
  210. filterOptions={(options) => options}
  211. options={ComboData.payMethod}
  212. value={payMethod}
  213. getOptionLabel={(option) => option.label}
  214. inputValue={payMethod?.label ? payMethod?.label : ""}
  215. onChange={(event, newValue) => {
  216. if(newValue==null){
  217. setPayMethod(ComboData.payMethod[0]);
  218. }else{
  219. setPayMethod(newValue);
  220. }
  221. }}
  222. sx={{
  223. '& .MuiInputBase-root': { alignItems: 'center' },
  224. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  225. '& .MuiOutlinedInput-root': { height: 40 }
  226. }}
  227. renderInput={(params) => (
  228. <TextField {...params}
  229. label="Payment Means"
  230. />
  231. )}
  232. InputLabelProps={{
  233. shrink: true
  234. }}
  235. />
  236. </Grid>
  237. </Grid>
  238. </Grid>
  239. {/*last row*/}
  240. <Grid container maxWidth justifyContent="flex-end">
  241. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  242. <Grid item sx={{ ml: 3, mb: 3}}>
  243. <Button
  244. variant="contained"
  245. color="cancel"
  246. onClick={resetForm}
  247. >
  248. Reset
  249. </Button>
  250. </Grid>
  251. <Grid item sx={{ ml: 3, mr: 3, mb: 3 }}>
  252. <Button
  253. variant="contained"
  254. type="submit"
  255. disabled={onGridReady}
  256. >
  257. Submit
  258. </Button>
  259. </Grid>
  260. </ThemeProvider>
  261. </Grid>
  262. </form>
  263. </MainCard>
  264. );
  265. };
  266. export default SearchPublicNoticeForm;