You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

352 rivejä
14 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. CardContent,
  5. Grid, TextField,
  6. Autocomplete,
  7. Typography
  8. } from '@mui/material';
  9. import MainCard from "components/MainCard";
  10. import { useForm } from "react-hook-form";
  11. import * as React from "react";
  12. import * as ComboData from "utils/ComboData";
  13. import * as DateUtils from "utils/DateUtils";
  14. import * as FormatUtils from "utils/FormatUtils";
  15. import { FormattedMessage, useIntl } from "react-intl";
  16. import { PNSPS_BUTTON_THEME } from "../../../themes/buttonConst";
  17. import { ThemeProvider } from "@emotion/react";
  18. import { makeStyles } from '@mui/styles';
  19. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  20. const useStyles = makeStyles(() => ({
  21. root: {
  22. position: "relative"
  23. },
  24. display: {
  25. position: "absolute",
  26. top: 2,
  27. left: 12,
  28. bottom: 2,
  29. background: "white",
  30. pointerEvents: "none",
  31. right: 50,
  32. display: "flex",
  33. alignItems: "center"
  34. },
  35. }));
  36. const SearchDemandNoteForm = ({ applySearch, searchCriteria, issueComboData
  37. }) => {
  38. const intl = useIntl();
  39. const { locale } = intl;
  40. const [type, setType] = React.useState([]);
  41. const [issueSelected, setIssueSelected] = React.useState({ key: 0, i18nLabel: 'all', labelCht: '全部', label: 'All', type: 'all' });
  42. const [issueCombo, setIssueCombo] = React.useState([]);
  43. const [selectedStatus, setSelectedStatus] = React.useState(ComboData.denmandNoteStatus_Public[0]);
  44. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  45. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  46. const [fromDateValue, setFromDateValue] = React.useState("dd / mm / yyyy");
  47. const [toDateValue, setToDateValue] = React.useState("dd / mm / yyyy");
  48. React.useEffect(() => {
  49. setFromDateValue(minDate);
  50. }, [minDate]);
  51. React.useEffect(() => {
  52. setToDateValue(maxDate);
  53. }, [maxDate]);
  54. function FormDateInputComponent({ inputRef, ...props }) {
  55. const classes = useStyles();
  56. return (
  57. <>
  58. <div className={classes.display}>
  59. {DateUtils.dateStr(fromDateValue) == "Invalid Date" ?
  60. fromDateValue
  61. :
  62. DateUtils.dateStr(fromDateValue)}
  63. </div>
  64. <input
  65. // className={classes.input}
  66. ref={inputRef}
  67. {...props}
  68. // onChange={handleChange}
  69. value={fromDateValue}
  70. max={maxDate}
  71. />
  72. </>
  73. );
  74. }
  75. function ToDateInputComponent({ inputRef, ...props }) {
  76. const classes = useStyles();
  77. return (
  78. <>
  79. <div className={classes.display}>
  80. {DateUtils.dateStr(toDateValue) == "Invalid Date" ?
  81. toDateValue
  82. :
  83. DateUtils.dateStr(toDateValue)}
  84. </div>
  85. <input
  86. // className={classes.input}
  87. ref={inputRef}
  88. {...props}
  89. // onChange={handleChange}
  90. value={toDateValue}
  91. min={minDate}
  92. />
  93. </>
  94. );
  95. }
  96. const { reset, register, handleSubmit } = useForm()
  97. const onSubmit = (data) => {
  98. let typeArray = [];
  99. let sentDateFrom = "";
  100. let sentDateTo = "";
  101. for (let i = 0; i < type.length; i++) {
  102. typeArray.push(type[i].label);
  103. }
  104. if (fromDateValue != "dd / mm / yyyy" && toDateValue != "dd / mm / yyyy") {
  105. sentDateFrom = DateUtils.dateValue(fromDateValue)
  106. sentDateTo = DateUtils.dateValue(toDateValue)
  107. }
  108. const temp = {
  109. appNo: data.appNo,
  110. issueId: issueSelected?.id,
  111. dnNo: data.dnNo,
  112. sentDateFrom: sentDateFrom,
  113. sentDateTo: sentDateTo,
  114. status: (selectedStatus?.type && selectedStatus?.type != 'all') ? selectedStatus?.type : "",
  115. };
  116. // console.log(temp)
  117. applySearch(temp);
  118. };
  119. React.useEffect(() => {
  120. if (issueComboData && issueComboData.length > 0) {
  121. setIssueCombo(issueComboData);
  122. }
  123. }, [issueComboData]);
  124. function resetForm() {
  125. setType([]);
  126. // setStatus({ key: 0, label: 'All', type: 'all' });
  127. // setOrgSelected({});
  128. setMinDate(DateUtils.dateValue(new Date().setDate(new Date().getDate()-14)))
  129. setMaxDate(DateUtils.dateValue(new Date()))
  130. setIssueSelected({});
  131. reset();
  132. }
  133. function getIssueLabel(data) {
  134. let issueYear = data.issueYear
  135. let volume = data.volume;
  136. let issueNo = data.issueNo;
  137. let issueDate = data.issueDate;
  138. if (locale === 'zh-HK') {
  139. return issueYear
  140. + " 第" + volume + "卷,"
  141. + " 第" + issueNo + "期,"
  142. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  143. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  144. } else if (locale === 'zh-CN') {
  145. return issueYear
  146. + " 第" + volume + "卷,"
  147. + " 第" + issueNo + "期,"
  148. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  149. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  150. }
  151. return issueYear
  152. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  153. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  154. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  155. }
  156. return (
  157. <MainCard xs={12} md={12} lg={12}
  158. border={false}
  159. content={false}
  160. sx={{ backgroundColor: '#fff' }}
  161. >
  162. <form onSubmit={handleSubmit(onSubmit)}>
  163. <Grid container sx={{ backgroundColor: '#ffffff' }} width="98%">
  164. {/*row 1*/}
  165. <Grid item xs={12}>
  166. <CardContent sx={{ px: 2.5, pt: 3 }}>
  167. <Grid item justifyContent="space-between" alignItems="center" >
  168. <Typography variant="pnspsFormHeader">
  169. <FormattedMessage id="searchForm" />
  170. </Typography>
  171. </Grid>
  172. </CardContent>
  173. </Grid>
  174. {/*row 2*/}
  175. <Grid container display="flex" alignItems={"center"}>
  176. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  177. <Autocomplete
  178. {...register("issueId")}
  179. disablePortal
  180. id="issueId"
  181. options={issueCombo}
  182. value={issueSelected}
  183. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  184. getOptionLabel={(option) => getIssueLabel(option)}
  185. onChange={(event, newValue) => {
  186. if (newValue !== null) {
  187. setIssueSelected(newValue);
  188. }
  189. }}
  190. renderInput={(params) => (
  191. <TextField {...params}
  192. label={intl.formatMessage({ id: 'gazetteCount' })}
  193. InputLabelProps={{
  194. shrink: true
  195. }}
  196. />
  197. )}
  198. />
  199. </Grid>
  200. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  201. <TextField
  202. fullWidth
  203. {...register("appNo")}
  204. id='appNo'
  205. label={intl.formatMessage({ id: 'applicationId' })}
  206. defaultValue={searchCriteria.appNo}
  207. InputLabelProps={{
  208. shrink: true
  209. }}
  210. />
  211. </Grid>
  212. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  213. <TextField
  214. fullWidth
  215. {...register("dnNo")}
  216. id='dnNo'
  217. label={intl.formatMessage({ id: 'paymentRecordId' })}
  218. defaultValue={searchCriteria.dnNo}
  219. InputLabelProps={{
  220. shrink: true
  221. }}
  222. />
  223. </Grid>
  224. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  225. <TextField
  226. fullWidth
  227. {...register("dateFrom")}
  228. id="dateFrom"
  229. type="date"
  230. label={intl.formatMessage({ id: 'sendDateFrom' })}
  231. defaultValue={searchCriteria.dateFrom}
  232. // InputProps={{ inputProps: { max: maxDate } }}
  233. InputProps={{
  234. inputComponent: FormDateInputComponent,
  235. }}
  236. onChange={(newValue) => {
  237. if(newValue.target.value!=""){
  238. setMinDate(newValue.target.value);
  239. }
  240. }}
  241. InputLabelProps={{
  242. shrink: true
  243. }}
  244. />
  245. </Grid>
  246. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  247. <TextField
  248. fullWidth
  249. InputLabelProps={{
  250. shrink: true
  251. }}
  252. {...register("dateTo")}
  253. InputProps={{
  254. inputComponent: ToDateInputComponent,
  255. }}
  256. onChange={(newValue) => {
  257. if(newValue.target.value!=""){
  258. setMaxDate(newValue.target.value);
  259. }
  260. }}
  261. id="dateTo"
  262. type="date"
  263. label={intl.formatMessage({ id: 'sendDateTo' })}
  264. defaultValue={searchCriteria.dateTo}
  265. />
  266. </Grid>
  267. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  268. <Autocomplete
  269. {...register("status")}
  270. id="status"
  271. size="small"
  272. options={ComboData.denmandNoteStatus_Public}
  273. getOptionLabel={(option) => option?.i18nLabel ? intl.formatMessage({ id: option.i18nLabel }) : ""}
  274. inputValue={selectedStatus?.i18nLabel ? intl.formatMessage({ id: selectedStatus.i18nLabel }) : ""}
  275. value={selectedStatus}
  276. onChange={(event, newValue) => {
  277. if (newValue !== null) {
  278. setSelectedStatus(newValue);
  279. }
  280. }}
  281. renderInput={(params) => (
  282. <TextField
  283. {...params}
  284. label={intl.formatMessage({ id: 'status' })}
  285. />
  286. )}
  287. InputLabelProps={{
  288. shrink: true
  289. }}
  290. />
  291. </Grid>
  292. </Grid>
  293. {/*last row*/}
  294. <Grid container maxWidth justifyContent="flex-end">
  295. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  296. <Grid item sx={{ mr: 3, mb: 3 }}>
  297. <Button
  298. color="cancel"
  299. variant="contained"
  300. onClick={resetForm}
  301. >
  302. <FormattedMessage id="reset" />
  303. </Button>
  304. </Grid>
  305. <Grid item sx={{ mb: 3 }}>
  306. <Button
  307. variant="contained"
  308. type="submit"
  309. >
  310. <FormattedMessage id="submit" />
  311. </Button>
  312. </Grid>
  313. </ThemeProvider>
  314. </Grid>
  315. </Grid>
  316. </form>
  317. </MainCard>
  318. );
  319. };
  320. export default SearchDemandNoteForm;