|
- // 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";
- import * as FormatUtils from "utils/FormatUtils";
- import {FormattedMessage, useIntl} from "react-intl";
- import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
- import {ThemeProvider} from "@emotion/react";
- import { makeStyles } from '@mui/styles';
-
- // ==============================|| DASHBOARD - DEFAULT ||============================== //
- const useStyles = makeStyles(() => ({
- root: {
- position: "relative"
- },
- display: {
- position: "absolute",
- top: 2,
- left: 12,
- bottom: 2,
- background: "white",
- pointerEvents: "none",
- right: 50,
- display: "flex",
- alignItems: "center"
- },
- }));
-
- const SearchDemandNoteForm = ({ applySearch, searchCriteria, issueComboData
- }) => {
-
- const intl = useIntl();
- const { locale } = intl;
-
- const [type, setType] = React.useState([]);
- const [issueSelected, setIssueSelected] = React.useState({ key: 0, i18nLabel: 'all', labelCht: '全部', label: 'All', type: 'all' });
- const [issueCombo, setIssueCombo] = React.useState([]);
- const [selectedStatus, setSelectedStatus] = React.useState(ComboData.denmandNoteStatus_Public[0]);
-
- const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
- const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
- const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
- const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
-
- React.useEffect(() => {
- console.log(minDate)
- if (minDate != searchCriteria.dateFrom){
- setFromDateValue(minDate);
- }
- }, [minDate]);
-
- React.useEffect(() => {
- console.log(maxDate)
- if (maxDate != searchCriteria.dateTo){
- setToDateValue(maxDate);
- }
- }, [maxDate]);
-
- function FormDateInputComponent({inputRef, ...props }) {
- const classes = useStyles();
- return (
- <>
- <div className={classes.display}>
- {DateUtils.dateStr(fromDateValue)=="Invalid Date"?
- fromDateValue
- :
- DateUtils.dateStr(fromDateValue)}
- </div>
- <input
- // className={classes.input}
- ref={inputRef}
- {...props}
- // onChange={handleChange}
- value={fromDateValue}
- max= {maxDate}
- />
- </>
- );
- }
-
- function ToDateInputComponent({inputRef, ...props }) {
- const classes = useStyles();
- return (
- <>
- <div className={classes.display}>
- {DateUtils.dateStr(toDateValue)=="Invalid Date"?
- toDateValue
- :
- DateUtils.dateStr(toDateValue)}
- </div>
- <input
- // className={classes.input}
- ref={inputRef}
- {...props}
- // onChange={handleChange}
- value={toDateValue}
- min = {minDate}
- />
- </>
- );
- }
-
- const { reset, register, handleSubmit } = useForm()
- const onSubmit = (data) => {
- let typeArray = [];
- let sentDateFrom = "";
- let sentDateTo = "";
-
- for (let i = 0; i < type.length; i++) {
- typeArray.push(type[i].label);
- }
-
- if( fromDateValue!="dd / mm / yyyy"&&toDateValue!="dd / mm / yyyy"){
- sentDateFrom = DateUtils.dateValue(fromDateValue)
- sentDateTo = DateUtils.dateValue(toDateValue)
- }
-
- const temp = {
- appNo: data.appNo,
- issueId: issueSelected?.id,
- dnNo: data.dnNo,
- sentDateFrom: sentDateFrom,
- sentDateTo: sentDateTo,
- status: (selectedStatus?.type && selectedStatus?.type != 'all') ? selectedStatus?.type : "",
- };
- console.log(temp)
- applySearch(temp);
- };
-
- React.useEffect(() => {
- if (issueComboData && issueComboData.length > 0) {
- setIssueCombo(issueComboData);
- }
- }, [issueComboData]);
-
- function resetForm() {
- setType([]);
- // setStatus({ key: 0, label: 'All', type: 'all' });
- setOrgSelected({});
- setIssueSelected({});
- reset();
- }
-
- function getIssueLabel(data) {
- let issueYear = data.issueYear
- let volume = data.volume;
- let issueNo = data.issueNo;
- let issueDate = data.issueDate;
- if (locale === 'zh-HK') {
- return issueYear
- + " 第" + volume + "卷,"
- + " 第" + issueNo + "期,"
- + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
- + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
- } else if (locale === 'zh-CN') {
- return issueYear
- + " 第" + volume + "卷,"
- + " 第" + issueNo + "期,"
- + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
- + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
- }
- return issueYear
- + " Vol. " + FormatUtils.zeroPad(volume, 3)
- + ", No. " + FormatUtils.zeroPad(issueNo, 2)
- + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
- }
-
- return (
- <MainCard xs={12} md={12} lg={12}
- border={false}
- content={false}
- sx={{ backgroundColor: '#fff' }}
- >
-
- <form onSubmit={handleSubmit(onSubmit)}>
- <Grid container sx={{ backgroundColor: '#ffffff' }} width="98%">
- {/*row 1*/}
- <Grid item xs={12}>
- <CardContent sx={{ px: 2.5, pt: 3 }}>
- <Grid item justifyContent="space-between" alignItems="center" >
- <Typography variant="pnspsFormHeader">
- <FormattedMessage id="searchForm"/>
- </Typography>
- </Grid>
- </CardContent>
- </Grid>
- {/*row 2*/}
- <Grid container display="flex" alignItems={"center"}>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("issueId")}
- disablePortal
- id="issueId"
- options={issueCombo}
- value={issueSelected}
- inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
- getOptionLabel={(option) => getIssueLabel(option)}
- onChange={(event, newValue) => {
- if (newValue !== null) {
- setIssueSelected(newValue);
- }
- }}
- renderInput={(params) => (
- <TextField {...params}
- label={intl.formatMessage({id: 'gazetteCount'})}
- InputLabelProps={{
- shrink: true
- }}
- />
- )}
- />
- </Grid>
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <TextField
- fullWidth
- {...register("appNo")}
- id='appNo'
- label={intl.formatMessage({id: 'applicationId'})}
- 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("dnNo")}
- id='dnNo'
- label={intl.formatMessage({id: 'paymentRecordId'})}
- defaultValue={searchCriteria.dnNo}
- 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={intl.formatMessage({id: 'sendDateFrom'})}
- defaultValue={searchCriteria.dateFrom}
- // InputProps={{ inputProps: { max: maxDate } }}
- InputProps={{
- inputComponent: FormDateInputComponent,
- inputProps: { max: maxDate }
- }}
- onChange={(newValue) => {
- setMinDate(newValue.target.value);
- }}
- 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={{ inputComponent: ToDateInputComponent,
- inputProps: { min: minDate }
- }}
- onChange={(newValue) => {
- setMaxDate(newValue.target.value);
- }}
- id="dateTo"
- type="date"
- label={intl.formatMessage({id: 'sendDateTo'})}
- defaultValue={searchCriteria.dateTo}
- />
- </Grid>
-
-
- <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
- <Autocomplete
- {...register("status")}
- id="status"
- size="small"
- options={ComboData.denmandNoteStatus_Public}
- getOptionLabel={(option) => option?.i18nLabel? intl.formatMessage({ id: option.i18nLabel }) : ""}
- inputValue={selectedStatus?.i18nLabel? intl.formatMessage({ id: selectedStatus.i18nLabel }) : ""}
- value={selectedStatus}
- onChange={(event, newValue) => {
- if (newValue !== null) {
- setSelectedStatus(newValue);
- }
- }}
- renderInput={(params) => (
- <TextField
- {...params}
- label={intl.formatMessage({id: 'status'})}
- />
- )}
- InputLabelProps={{
- shrink: true
- }}
- />
- </Grid>
-
-
-
- </Grid>
-
- {/*last row*/}
- <Grid container maxWidth justifyContent="flex-end">
- <ThemeProvider theme={PNSPS_BUTTON_THEME}>
- <Grid item sx={{mr: 3, mb: 3}}>
- <Button
- color="cancel"
- variant="contained"
- onClick={resetForm}
- >
- <FormattedMessage id="reset"/>
- </Button>
- </Grid>
-
- <Grid item sx={{ mb: 3 }}>
- <Button
- variant="contained"
- type="submit"
- >
- <FormattedMessage id="submit" />
- </Button>
- </Grid>
- </ThemeProvider>
- </Grid>
- </Grid>
- </form>
- </MainCard>
- );
- };
-
- export default SearchDemandNoteForm;
|