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.
 
 

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