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

335 行
15 KiB

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