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

OrganizationSearchForm.js 8.1 KiB

2年前
2年前
2年前
1年前
2年前
1年前
2年前
2年前
2年前
1年前
2年前
2年前
2年前
2年前
2年前
2年前
1年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
1年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // material-ui
  2. import {
  3. Button,
  4. Grid, TextField,
  5. Typography,
  6. Autocomplete,
  7. } from '@mui/material';
  8. import MainCard from "components/MainCard";
  9. import { useForm } from "react-hook-form";
  10. import { useState,useEffect } from "react";
  11. import * as React from "react";
  12. import * as UrlUtils from "utils/ApiPathConst";
  13. import * as HttpUtils from "utils/HttpUtils";
  14. import * as ComboData from "utils/ComboData";
  15. import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
  16. import {ThemeProvider} from "@emotion/react";
  17. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  18. const OrganizationSearchForm = ({ applySearch, onGridReady, searchCriteria }) => {
  19. const [type, setType] = useState([]);
  20. const [creditorSelected, setCreditorSelected] = React.useState(ComboData.CreditorStatus[0]);
  21. const { reset, register, handleSubmit } = useForm()
  22. const [onDownload, setOnDownload] = React.useState(false);
  23. useEffect(() => {
  24. if(searchCriteria.creditor!=undefined){
  25. setCreditorSelected(ComboData.CreditorStatus.find(item => item.type === searchCriteria.creditor.toString()))
  26. }else{
  27. setCreditorSelected(ComboData.CreditorStatus[0]);
  28. }
  29. }, [searchCriteria]);
  30. const onSubmit = (data) => {
  31. let typeArray = [];
  32. for (let i = 0; i < type.length; i++) {
  33. typeArray.push(type[i].label);
  34. }
  35. const temp = {
  36. brNo: data.brNo,
  37. enCompanyName: data.enCompanyName,
  38. chCompanyName: data.chCompanyName,
  39. };
  40. if(creditorSelected.type == 'true'){
  41. temp["creditor"] = true;
  42. }else if(creditorSelected.type == 'false'){
  43. temp["creditor"] = false;
  44. }
  45. applySearch(temp);
  46. };
  47. function resetForm() {
  48. setType([]);
  49. setCreditorSelected(ComboData.CreditorStatus[0]);
  50. reset({
  51. brNo: "",
  52. enCompanyName: "",
  53. chCompanyName: "",
  54. });
  55. }
  56. const doExport=()=>{
  57. setOnDownload(true)
  58. HttpUtils.fileDownload({
  59. url: UrlUtils.GET_ORG_EXPORT,
  60. onResponse:()=>{
  61. setOnDownload(false)
  62. },
  63. onError:()=>{
  64. setOnDownload(false)
  65. }
  66. });
  67. }
  68. return (
  69. <MainCard xs={12} md={12} lg={12}
  70. border={false}
  71. content={false}>
  72. <form onSubmit={handleSubmit(onSubmit)}>
  73. {/*row 1*/}
  74. <Grid container sx={{ backgroundColor: '#ffffff', ml: 2, mt: 1}} width="98%">
  75. {/*row 1*/}
  76. <Grid item justifyContent="space-between" alignItems="center" sx={{mt:1,ml:3,mb:2.5}}>
  77. <Typography variant="pnspsFormHeader" >
  78. Search
  79. </Typography>
  80. </Grid>
  81. {/*row 2*/}
  82. <Grid container display="flex" alignItems={"center"}>
  83. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  84. <TextField
  85. fullWidth
  86. {...register("brNo")}
  87. id='brNo'
  88. label="BR No."
  89. defaultValue={searchCriteria.brNo}
  90. InputLabelProps={{
  91. shrink: true
  92. }}
  93. />
  94. </Grid>
  95. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  96. <TextField
  97. fullWidth
  98. {...register("enCompanyName")}
  99. id="enCompanyName"
  100. label="Name (English)"
  101. defaultValue={searchCriteria.enCompanyName}
  102. InputLabelProps={{
  103. shrink: true
  104. }}
  105. />
  106. </Grid>
  107. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3 }}>
  108. <TextField
  109. fullWidth
  110. {...register("chCompanyName")}
  111. id="chCompanyName"
  112. label="Name (Chinese)"
  113. defaultValue={searchCriteria.chCompanyName}
  114. InputLabelProps={{
  115. shrink: true
  116. }}
  117. />
  118. </Grid>
  119. <Grid item xs={9} s={6} md={5} lg={3} sx={{ ml: 3, mr: 3, mb: 3}}>
  120. <Autocomplete
  121. {...register("searchCreditor")}
  122. id="searchCreditor"
  123. size="small"
  124. options={ComboData.CreditorStatus}
  125. value={creditorSelected}
  126. onChange={(event, newValue) => {
  127. if(newValue == null){
  128. setCreditorSelected(ComboData.CreditorStatus[0]);
  129. }else{
  130. setCreditorSelected(newValue);
  131. }
  132. }}
  133. sx={{
  134. '& .MuiInputBase-root': { alignItems: 'center' },
  135. '& .MuiAutocomplete-endAdornment': { top: '50%', transform: 'translateY(-50%)' },
  136. '& .MuiOutlinedInput-root': { height: 40 }
  137. }}
  138. getOptionLabel={(option) => option.label}
  139. renderInput={(params) => (
  140. <TextField
  141. {...params}
  142. label="Credit Client/Non-Credit Client"
  143. InputLabelProps={{
  144. shrink: true
  145. }}
  146. />
  147. )}
  148. />
  149. </Grid>
  150. </Grid>
  151. {/*last row*/}
  152. <Grid container maxWidth justifyContent="flex-end">
  153. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  154. <Grid item sx={{mr: 3, mb: 3 }}>
  155. <Button
  156. variant="contained"
  157. onClick={doExport}
  158. disabled={onDownload}
  159. >
  160. Export
  161. </Button>
  162. </Grid>
  163. <Grid item sx={{ mr: 3, mb: 3}}>
  164. <Button
  165. variant="contained"
  166. color="cancel"
  167. onClick={resetForm}
  168. >
  169. Reset
  170. </Button>
  171. </Grid>
  172. <Grid item sx={{ mb: 3}}>
  173. <Button
  174. variant="contained"
  175. type="submit"
  176. disabled={onGridReady}
  177. >
  178. Submit
  179. </Button>
  180. </Grid>
  181. </ThemeProvider>
  182. </Grid>
  183. </Grid>
  184. </form>
  185. </MainCard>
  186. );
  187. };
  188. export default OrganizationSearchForm;