// 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 (
{/*row 1*/} 搜尋 {/*row 2*/} { setMinDate(DateUtils.dateStr(newValue)); }} InputLabelProps={{ shrink: true }} /> { setMaxDate(DateUtils.dateStr(newValue)); }} /> 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) => ( )} // InputLabelProps={{ // shrink: true // }} /> {/**/} {/* */} {/**/} {/*last row*/}
); }; export default SearchPublicNoticeForm;