|
- // material-ui
- import {
- Button,
- CardContent,
- Grid, TextField,
- Autocomplete,
- Typography
- } from '@mui/material';
- import MainCard from "components/MainCard";
- import { useForm } from "react-hook-form";
- import * as React from "react";
- import * as DateUtils from "utils/DateUtils";
- import * as ComboData from "utils/ComboData";
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-
- const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
-
- const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
- const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
- const [status, setStatus] = React.useState(ComboData.paymentStatus[0]);
-
- const _sx = {
- padding: "4 2 4 2",
- boxShadow: 1,
- border: 1,
- borderColor: '#DDD',
- '& .MuiDataGrid-cell': {
- borderTop: 1,
- borderBottom: 1,
- borderColor: "#EEE"
- },
- '& .MuiDataGrid-footerContainer': {
- border: 1,
- borderColor: "#EEE"
- }
- }
-
- const { reset, register, handleSubmit } = useForm()
-
- const onSubmit = (data) => {
- const temp = {
- code: data.code,
- dateFrom: data.dateFrom,
- dateTo: data.dateTo,
- status : (status?.type && status?.type != 'all') ? status?.type : "",
- };
- applySearch(temp);
- };
-
- function resetForm() {
- reset();
- }
-
-
- return (
- <MainCard xs={12} md={12} lg={12}
- border={false}
- content={false}
- sx={_sx}
- >
-
- <form onSubmit={handleSubmit(onSubmit)}>
- {/*row 1*/}
- <CardContent sx={{ px: 2.5, pt: 3 }}>
- <Grid item justifyContent="space-between" alignItems="center" >
- <Typography variant="h4">搜尋</Typography>
- </Grid>
- </CardContent>
-
- {/*row 2*/}
- <Grid container alignItems={"center"}>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("code")}
- id='code'
- label="申請/付款編號:"
- defaultValue={searchCriteria.code}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("dateFrom")}
- id="dateFrom"
- type="date"
- label="付款日期(從)"
- defaultValue={searchCriteria.dateFrom}
- InputProps={{ inputProps: { max: maxDate } }}
- onChange={(newValue) => {
- setMinDate(DateUtils.dateStr(newValue));
- }}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- InputLabelProps={{
- shrink: true
- }}
- {...register("dateTo")}
- InputProps={{ inputProps: { min: minDate } }}
- onChange={(newValue) => {
- setMaxDate(DateUtils.dateStr(newValue));
- }}
- id="dateTo"
- type="date"
- label="付款日期(到)"
- defaultValue={searchCriteria.dateTo}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("status")}
- disablePortal={false}
- id="status"
- filterOptions={(options) => options}
- options={ComboData.paymentStatus}
- value={status}
- getOptionLabel={(option) => option.labelCht}
- inputValue={status?.labelCht ? status?.labelCht : ""}
- onChange={(event, newValue) => {
- if (newValue !== null) {
- setStatus(newValue);
- }
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="狀態"
- />
- )}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- </Grid>
-
-
- {/*last row*/}
- <Grid container maxWidth justifyContent="flex-end">
-
- <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
- <Button
- size="large"
- variant="contained"
- onClick={resetForm}
- sx={{
- textTransform: 'capitalize',
- alignItems: 'end'
- }}>
- <Typography variant="h5">重置</Typography>
- </Button>
- </Grid>
-
- <Grid item sx={{ ml: 3, mr: 3, mb: 3, mt: 3 }}>
- <Button
- size="large"
- variant="contained"
- type="submit"
- sx={{
- textTransform: 'capitalize',
- alignItems: 'end'
- }}>
- <Typography variant="h5">提交</Typography>
- </Button>
- </Grid>
- </Grid>
- </form>
- </MainCard>
- );
- };
-
- export default SearchPublicNoticeForm;
|