您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

290 行
12 KiB

  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Autocomplete,
  6. Typography
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import * as React from "react";
  11. import * as ComboData from "utils/ComboData";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as FormatUtils from "utils/FormatUtils";
  14. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  15. import {ThemeProvider} from "@emotion/react";
  16. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  17. const SearchDemandNoteForm = ({ applySearch, orgComboData, searchCriteria, issueComboData
  18. }) => {
  19. const [type, setType] = React.useState([]);
  20. // const [status, setStatus] = React.useState({ key: 0, label: 'All', type: 'all' });
  21. const [orgSelected, setOrgSelected] = React.useState({});
  22. const [orgCombo, setOrgCombo] = React.useState();
  23. const [issueSelected, setIssueSelected] = React.useState({});
  24. const [issueCombo, setIssueCombo] = React.useState([]);
  25. const [selectedStatus, setSelectedStatus] = React.useState([]);
  26. const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
  27. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  28. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  29. const { reset, register, handleSubmit } = useForm()
  30. const onSubmit = (data) => {
  31. data.status = selectedLabelsString
  32. let typeArray = [];
  33. for (let i = 0; i < type.length; i++) {
  34. typeArray.push(type[i].label);
  35. }
  36. const temp = {
  37. appNo: data.appNo,
  38. issueId: issueSelected?.id,
  39. orgId: (orgSelected?.key && orgSelected?.key > 0) ? orgSelected?.key : "",
  40. dnNo: data.dnNo,
  41. dateFrom: data.dateFrom,
  42. dateTo: data.dateTo,
  43. status: (data.status === '' || data.status.includes("all")) ? "" : data.status,
  44. };
  45. applySearch(temp);
  46. };
  47. React.useEffect(() => {
  48. if (orgComboData && orgComboData.length > 0) {
  49. setOrgCombo(orgComboData);
  50. }
  51. }, [orgComboData]);
  52. React.useEffect(() => {
  53. if (issueComboData && issueComboData.length > 0) {
  54. setIssueCombo(issueComboData);
  55. }
  56. }, [issueComboData]);
  57. function resetForm() {
  58. setType([]);
  59. // setStatus({ key: 0, label: 'All', type: 'all' });
  60. setOrgSelected({});
  61. setIssueSelected({});
  62. reset();
  63. }
  64. function getIssueLabel(data) {
  65. if (data == {}) return "";
  66. return data.issueYear
  67. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  68. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  69. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  70. }
  71. return (
  72. <MainCard xs={12} md={12} lg={12}
  73. border={false}
  74. content={false}
  75. sx={{ backgroundColor: '#fff' }}
  76. >
  77. <form onSubmit={handleSubmit(onSubmit)}>
  78. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1 }} width="98%">
  79. {/*row 1*/}
  80. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1, ml:3,mb:2.5}}>
  81. <Typography variant="pnspsFormHeader" >
  82. Search
  83. </Typography>
  84. </Grid>
  85. {/*row 2*/}
  86. <Grid container display="flex" alignItems={"center"}>
  87. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  88. <Autocomplete
  89. {...register("issueId")}
  90. disablePortal
  91. id="issueId"
  92. size="small"
  93. options={issueCombo}
  94. value={issueSelected}
  95. inputValue={(issueSelected?.id) ? getIssueLabel(issueSelected) : ""}
  96. getOptionLabel={(option) => getIssueLabel(option)}
  97. onChange={(event, newValue) => {
  98. if (newValue !== null) {
  99. setIssueSelected(newValue);
  100. }
  101. }}
  102. renderInput={(params) => (
  103. <TextField {...params}
  104. label="Gazette Issue"
  105. InputLabelProps={{
  106. shrink: true
  107. }}
  108. />
  109. )}
  110. />
  111. </Grid>
  112. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  113. <TextField
  114. fullWidth
  115. {...register("appNo")}
  116. id='appNo'
  117. label={"App No."}
  118. defaultValue={searchCriteria.appNo}
  119. InputLabelProps={{
  120. shrink: true
  121. }}
  122. />
  123. </Grid>
  124. {
  125. orgCombo ?
  126. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  127. <Autocomplete
  128. {...register("orgId")}
  129. disablePortal
  130. id="orgId"
  131. size="small"
  132. options={orgCombo}
  133. value={orgSelected}
  134. inputValue={(orgSelected?.label) ? orgSelected?.label : ""}
  135. onChange={(event, newValue) => {
  136. if (newValue !== null) {
  137. setOrgSelected(newValue);
  138. }
  139. }}
  140. renderInput={(params) => (
  141. <TextField {...params}
  142. label="BR No./Organisation"
  143. InputLabelProps={{
  144. shrink: true
  145. }}
  146. />
  147. )}
  148. />
  149. </Grid>
  150. : <></>
  151. }
  152. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  153. <TextField
  154. fullWidth
  155. {...register("dnNo")}
  156. id='dnNo'
  157. label="DN No."
  158. defaultValue={searchCriteria.dnNo}
  159. InputLabelProps={{
  160. shrink: true
  161. }}
  162. />
  163. </Grid>
  164. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  165. <TextField
  166. fullWidth
  167. {...register("dateFrom")}
  168. id="dateFrom"
  169. type="date"
  170. label={"Issue Date(From)"}
  171. defaultValue={searchCriteria.dateFrom}
  172. InputProps={{ inputProps: { max: maxDate } }}
  173. onChange={(newValue) => {
  174. setMinDate(DateUtils.dateStr(newValue));
  175. }}
  176. InputLabelProps={{
  177. shrink: true
  178. }}
  179. />
  180. </Grid>
  181. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  182. <TextField
  183. fullWidth
  184. InputLabelProps={{
  185. shrink: true
  186. }}
  187. {...register("dateTo")}
  188. InputProps={{ inputProps: { min: minDate } }}
  189. onChange={(newValue) => {
  190. setMaxDate(DateUtils.dateStr(newValue));
  191. }}
  192. id="dateTo"
  193. type="date"
  194. label={"Issue Date(To)"}
  195. defaultValue={searchCriteria.dateTo}
  196. />
  197. </Grid>
  198. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  199. <Autocomplete
  200. multiple
  201. size="small"
  202. {...register("status")}
  203. id="status"
  204. options={ComboData.denmandNoteStatus}
  205. value={selectedStatus}
  206. onChange={(event, newValue) => {
  207. const findAllIndex = newValue.findIndex((ele) => {
  208. return ele.type === "all"
  209. })
  210. if (findAllIndex > -1) {
  211. setSelectedStatus([newValue[findAllIndex]]);
  212. setSelectedLabelsString('all')
  213. } else {
  214. const selectedLabels = newValue.map(option => option.type);
  215. const selectedLabelsString = `${selectedLabels.join(',')}`;
  216. setSelectedStatus(newValue);
  217. setSelectedLabelsString(selectedLabelsString);
  218. }
  219. }}
  220. getOptionLabel={(option) => option.label}
  221. renderInput={(params) => (
  222. <TextField
  223. {...params}
  224. label="Status"
  225. InputLabelProps={{
  226. shrink: true
  227. }}
  228. />
  229. )}
  230. />
  231. </Grid>
  232. </Grid>
  233. {/*last row*/}
  234. <Grid container maxWidth justifyContent="flex-end">
  235. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  236. <Grid item sx={{ ml: 3, mb:3 }}>
  237. <Button
  238. variant="contained"
  239. onClick={resetForm}
  240. >
  241. Clear
  242. </Button>
  243. </Grid>
  244. <Grid item sx={{ ml: 3, mr: 3, mb:3}}>
  245. <Button
  246. variant="contained"
  247. type="submit"
  248. >
  249. Submit
  250. </Button>
  251. </Grid>
  252. </ThemeProvider>
  253. </Grid>
  254. </Grid>
  255. </form>
  256. </MainCard>
  257. );
  258. };
  259. export default SearchDemandNoteForm;