|
- // 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 ComboData from "utils/ComboData";
- import * as DateUtils from "utils/DateUtils";
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-
- const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
-
- const [type, setType] = React.useState([]);
- const [status, setStatus] = React.useState([{ key: 0, label: 'All', labelCht: "全部", type: 'all' }]);
-
- const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
- const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
- const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
-
- const { reset, register, handleSubmit } = useForm()
- const onSubmit = (data) => {
- data.status = selectedLabelsString
- let typeArray = [];
-
- for (let i = 0; i < type.length; i++) {
- typeArray.push(type[i].label);
- }
-
- const temp = {
- appNo: data.appNo,
- dateFrom: data.dateFrom,
- dateTo: data.dateTo,
- contact: data.contact,
- status: (data.status === "" || data.status.includes('all')) ? "" : data.status,
- };
- applySearch(temp);
- };
-
- function resetForm() {
- setType([]);
- setStatus([{ key: 0, label: 'All', labelCht: "全部", type: 'all' }]);
- reset();
- }
-
- return (
- <MainCard xs={12} md={12} lg={12}
- border={false}
- content={false}>
-
- <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("appNo")}
- id='appNo'
- label="申請編號"
- defaultValue={searchCriteria.appNo}
- 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")}
- id="dateTo"
- type="date"
- label="提交日期(到)"
- defaultValue={searchCriteria.dateTo}
- InputProps={{ inputProps: { min: minDate } }}
- onChange={(newValue) => {
- setMaxDate(DateUtils.dateStr(newValue));
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("contact")}
- id="contact"
- label="聯絡人"
- defaultValue={searchCriteria.contact}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- multiple
- {...register("status")}
- id="status"
- // filterOptions={(options)=>options}
- options={
- localStorage.getItem('userData').creditor ?
- ComboData.publicNoticeStatic_Creditor :
- ComboData.publicNoticeStatic
- }
- value={status}
- // inputValue={status?.labelCht}
- getOptionLabel={(option) => option.labelCht}
- onChange={(event, newValue) => {
- console.log(newValue)
- const findAllIndex = newValue.findIndex((ele) => {
- return ele.type === "all"
- })
-
- if (findAllIndex > -1) {
- setStatus([newValue[findAllIndex]]);
- setSelectedLabelsString('all')
- } else {
- const selectedLabels = newValue.map(option => option.type);
- const selectedLabelsString = `${selectedLabels.join(',')}`;
- setStatus(newValue);
- console.log(newValue)
- setSelectedLabelsString(selectedLabelsString);
- }
- console.log(selectedLabelsString)
- console.log(status)
- }}
- renderInput={(params) => (
- <TextField {...params}
- label="狀態"
- InputLabelProps={{
- shrink: true
- }}
- />
- )}
- // InputLabelProps={{
- // shrink: true
- // }}
- />
- </Grid>
- {/*<Grid item xs={9} s={6} md={5} lg={3} sx={{ml:3, mr:3, mb:3}}>*/}
- {/* <TextField*/}
- {/* fullWidth*/}
- {/* {...register("subDivisionId")}*/}
- {/* id="subDivision"*/}
- {/* label="Sub-Division"*/}
- {/* />*/}
- {/*</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;
|