選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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