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

240 行
9.9 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 {
  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. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  20. const SearchPublicNoticeForm = ({ applySearch, searchCriteria }) => {
  21. const intl = useIntl();
  22. const [type, setType] = React.useState([]);
  23. const [status, setStatus] = React.useState([{ key: 0, label: 'all', type: 'all' }]);
  24. const [minDate, setMinDate] = React.useState(searchCriteria.dateFrom);
  25. const [maxDate, setMaxDate] = React.useState(searchCriteria.dateTo);
  26. const [selectedLabelsString, setSelectedLabelsString] = React.useState('');
  27. const { reset, register, handleSubmit } = useForm()
  28. const marginBottom = 2.5;
  29. const onSubmit = (data) => {
  30. data.status = selectedLabelsString
  31. let typeArray = [];
  32. for (let i = 0; i < type.length; i++) {
  33. typeArray.push(type[i].label);
  34. }
  35. const temp = {
  36. appNo: data.appNo,
  37. dateFrom: data.dateFrom,
  38. dateTo: data.dateTo,
  39. contact: data.contact,
  40. careOf: data.careOf?data.careOf:"",
  41. status: (data.status === "" || data.status.includes('all')) ? "" : data.status,
  42. };
  43. applySearch(temp);
  44. };
  45. function resetForm() {
  46. setType([]);
  47. setStatus([{ key: 0, label: 'All', labelCht: "全部", type: 'all' }]);
  48. reset();
  49. }
  50. return (
  51. <MainCard xs={12} md={12} lg={12}
  52. border={false}
  53. content={false}>
  54. <form onSubmit={handleSubmit(onSubmit)}>
  55. {/*row 1*/}
  56. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:marginBottom}}>
  57. <Typography variant="pnspsFormTitle" >
  58. <FormattedMessage id="search"/>
  59. </Typography>
  60. </Grid>
  61. {/*row 2*/}
  62. <Grid container alignItems={"center"}>
  63. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  64. <TextField
  65. fullWidth
  66. {...register("appNo")}
  67. id='appNo'
  68. label={intl.formatMessage({id: 'applicationId'})}
  69. defaultValue={searchCriteria.appNo}
  70. InputLabelProps={{
  71. shrink: true
  72. }}
  73. />
  74. </Grid>
  75. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  76. <TextField
  77. fullWidth
  78. {...register("dateFrom")}
  79. id="dateFrom"
  80. type="date"
  81. label={intl.formatMessage({id: 'submitDateFrom'})}
  82. defaultValue={searchCriteria.dateFrom}
  83. InputProps={{ inputProps: { max: maxDate } }}
  84. onChange={(newValue) => {
  85. setMinDate(DateUtils.dateStr(newValue));
  86. }}
  87. InputLabelProps={{
  88. shrink: true
  89. }}
  90. />
  91. </Grid>
  92. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  93. <TextField
  94. fullWidth
  95. InputLabelProps={{
  96. shrink: true
  97. }}
  98. {...register("dateTo")}
  99. id="dateTo"
  100. type="date"
  101. label={intl.formatMessage({id: 'submitDateTo'})}
  102. defaultValue={searchCriteria.dateTo}
  103. InputProps={{ inputProps: { min: minDate } }}
  104. onChange={(newValue) => {
  105. setMaxDate(DateUtils.dateStr(newValue));
  106. }}
  107. />
  108. </Grid>
  109. {isORGLoggedIn()?
  110. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  111. <TextField
  112. fullWidth
  113. {...register("careOf")}
  114. id="careOf"
  115. label="Care Of"
  116. defaultValue={searchCriteria.careOf}
  117. InputLabelProps={{
  118. shrink: true
  119. }}
  120. />
  121. </Grid>:null
  122. }
  123. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  124. <TextField
  125. fullWidth
  126. {...register("contact")}
  127. id="contact"
  128. label={intl.formatMessage({id: 'contactPerson'})}
  129. defaultValue={searchCriteria.contact}
  130. InputLabelProps={{
  131. shrink: true
  132. }}
  133. />
  134. </Grid>
  135. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  136. <Autocomplete
  137. multiple
  138. {...register("status")}
  139. id="status"
  140. size="small"
  141. // filterOptions={(options)=>options}
  142. options={
  143. localStorage.getItem('userData').creditor ?
  144. ComboData.publicNoticeStatic_Creditor :
  145. ComboData.publicNoticeStatic
  146. }
  147. value={status}
  148. // inputValue={status?.labelCht}
  149. getOptionLabel={(option) => intl.formatMessage({id: option.label})}
  150. onChange={(event, newValue) => {
  151. console.log(newValue)
  152. const findAllIndex = newValue.findIndex((ele) => {
  153. return ele.type === "all"
  154. })
  155. if (findAllIndex > -1) {
  156. setStatus([newValue[findAllIndex]]);
  157. setSelectedLabelsString('all')
  158. } else {
  159. const selectedLabels = newValue.map(option => option.type);
  160. const selectedLabelsString = `${selectedLabels.join(',')}`;
  161. setStatus(newValue);
  162. console.log(newValue)
  163. setSelectedLabelsString(selectedLabelsString);
  164. }
  165. console.log(selectedLabelsString)
  166. console.log(status)
  167. }}
  168. renderInput={(params) => (
  169. <TextField {...params}
  170. label={intl.formatMessage({id: 'status'})}
  171. InputLabelProps={{
  172. shrink: true
  173. }}
  174. />
  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. {/* {...register("subDivisionId")}*/}
  185. {/* id="subDivision"*/}
  186. {/* label="Sub-Division"*/}
  187. {/* />*/}
  188. {/*</Grid>*/}
  189. </Grid>
  190. {/*last row*/}
  191. <Grid container maxWidth justifyContent="flex-end">
  192. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  193. <Grid item sx={{ ml: 3, mr: 3 }}>
  194. <Button
  195. variant="contained"
  196. onClick={resetForm}
  197. >
  198. <Typography variant="pnspsButtonText">
  199. <FormattedMessage id="reset"/>
  200. </Typography>
  201. </Button>
  202. </Grid>
  203. <Grid item sx={{ ml: 3, mr: 3}}>
  204. <Button
  205. variant="contained"
  206. type="submit"
  207. >
  208. <Typography variant="pnspsButtonText">
  209. <FormattedMessage id="search"/>
  210. </Typography>
  211. </Button>
  212. </Grid>
  213. </ThemeProvider>
  214. </Grid>
  215. </form>
  216. </MainCard>
  217. );
  218. };
  219. export default SearchPublicNoticeForm;