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.
 
 

228 rivejä
8.9 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Button,
  6. RadioGroup,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. Stack
  9. } from '@mui/material';
  10. import { useFormik } from 'formik';
  11. import * as yup from 'yup';
  12. import * as React from "react";
  13. import * as HttpUtils from "utils/HttpUtils";
  14. import * as UrlUtils from "utils/ApiPathConst";
  15. import * as FieldUtils from "utils/FieldUtils";
  16. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  17. import {useNavigate} from "react-router-dom";
  18. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  19. const PublicNoticeApplyForm = ({loadedData, selections}) => {
  20. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  21. const [warningText, setWarningText] = React.useState("");
  22. const [attachment, setAttachment] = React.useState({});
  23. const navigate=useNavigate();
  24. const BackgroundHead = {
  25. backgroundImage: `url(${titleBackgroundImg})`,
  26. width: '100%',
  27. height: '100%',
  28. backgroundSize:'cover'
  29. }
  30. // React.useEffect(()=>{
  31. // setFormData(loadedData);
  32. // },[]);
  33. const formik = useFormik({
  34. enableReinitialize:true,
  35. initialValues:loadedData,
  36. validationSchema:yup.object().shape({
  37. contactPerson: yup.string().max(40).required('請輸入聯絡人'),
  38. tel_countryCode: yup.string().min(3,'請輸入3位數字').required('請輸入國際區號'),
  39. fax_countryCode: yup.string().min(3,'請輸入3位數字'),
  40. phoneNumber: yup.string().min(8,'請輸入8位數字').required('請輸入聯絡電話'),
  41. faxNumber: yup.string().min(8,'請輸入8位數字'),
  42. remarks: yup.string().max(255).nullable(),
  43. }),
  44. onSubmit:values=>{
  45. if(!values.issueId){
  46. setWarningText("請選擇目標期數");
  47. setIsWarningPopUp(true);
  48. return;
  49. }
  50. if(!attachment){
  51. setWarningText("請選擇上傳文件");
  52. setIsWarningPopUp(true);
  53. return;
  54. }else if(attachment.size >= (10*1024*1034)){
  55. setWarningText("上傳文件大小應<10MB");
  56. setIsWarningPopUp(true);
  57. return;
  58. }
  59. console.log(values);
  60. HttpUtils.postWithFiles({
  61. url: UrlUtils.POST_PUBLIC_NOTICE_APPLY,
  62. params: {
  63. id: 0,
  64. contactPerson: values.contactPerson,
  65. contactTelNo: {
  66. countryCode: values.tel_countryCode,
  67. phoneNumber: values.phoneNumber
  68. },
  69. contactFaxNo:{
  70. countryCode: values.fax_countryCode,
  71. faxNumber: values.faxNumber
  72. },
  73. issueId:values.issueId,
  74. remarks:values.remarks,
  75. },
  76. files: [attachment],
  77. onSuccess: function(){
  78. navigate("/publicNotice");
  79. }
  80. });
  81. }
  82. });
  83. const readFile=(event)=>{
  84. setAttachment(event.target.files[0]);
  85. }
  86. return (
  87. <Grid container>
  88. <Grid item xs={12} mb={3}>
  89. <div style={BackgroundHead}>
  90. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  91. <Typography ml={15} color='#FFF' variant="h4">申請公共啟事</Typography>
  92. </Stack>
  93. </div>
  94. </Grid>
  95. {/* <Grid item xs={12}>
  96. <Typography variant="h5">申請公共啟事</Typography>
  97. </Grid> */}
  98. <form style={{ width: "100%"}} onSubmit={formik.handleSubmit}>
  99. <Grid container spacing={1} sx={{minHeight: '80vh'}}>
  100. <Grid item lg={4}></Grid>
  101. {FieldUtils.getTextField({
  102. label:"聯絡人:",
  103. valueName:"contactPerson",
  104. form: formik
  105. })}
  106. <Grid item lg={4}></Grid>
  107. <Grid item lg={4}></Grid>
  108. {FieldUtils.getPhoneField({
  109. label:"聯繫電話:",
  110. valueName:{
  111. code: "tel_countryCode",
  112. num:"phoneNumber"
  113. },
  114. form: formik
  115. })}
  116. <Grid item lg={4}></Grid>
  117. <Grid item lg={4}></Grid>
  118. {FieldUtils.getPhoneField({
  119. label:"聯繫傳真:",
  120. valueName:{
  121. code: "fax_countryCode",
  122. num:"faxNumber"
  123. },
  124. form: formik
  125. })}
  126. <Grid item lg={4}></Grid>
  127. <Grid item lg={4}></Grid>
  128. <Grid item lg={4}>
  129. <Grid container alignItems={"center"}>
  130. <Grid item lg={4}
  131. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  132. 目標期數:
  133. </Grid>
  134. <Grid item lg={6}>
  135. <RadioGroup
  136. aria-labelledby="demo-radio-buttons-group-label"
  137. id="issueId"
  138. name="issueId"
  139. defaultValue={formik.values.issueId}
  140. >
  141. {
  142. selections
  143. }
  144. </RadioGroup>
  145. </Grid>
  146. </Grid>
  147. </Grid>
  148. <Grid item lg={4}></Grid>
  149. <Grid item lg={4}></Grid>
  150. <Grid item lg={4}>
  151. <Grid container alignItems={"center"}>
  152. <Grid item lg={4}
  153. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  154. 上傳文件 ({"檔案大小應<10MB"}):
  155. </Grid>
  156. <Grid item lg={4}>
  157. {attachment.name}
  158. </Grid>
  159. <Grid item lg={3}>
  160. <input
  161. id="uploadFileBtn"
  162. name="file"
  163. type="file"
  164. accept="image/png, image/jpeg.doc,.pdf,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  165. style={{ display: 'none' }}
  166. onChange={(event)=> {
  167. readFile(event)
  168. }}
  169. />
  170. <label htmlFor="uploadFileBtn">
  171. <Button
  172. component="span"
  173. variant="outlined"
  174. size="large"
  175. >{attachment?"上傳文件":"重新上傳"}</Button>
  176. </label>
  177. </Grid>
  178. </Grid>
  179. </Grid>
  180. <Grid item lg={4}></Grid>
  181. <Grid item lg={4}></Grid>
  182. {FieldUtils.getTextArea({
  183. label:"備註:",
  184. valueName:"remarks",
  185. form: formik
  186. })}
  187. <Grid item lg={4}></Grid>
  188. <Grid item xs={12}>
  189. <center>
  190. <Button
  191. variant="contained"
  192. type="submit"
  193. size="large"
  194. >申請公共啟事</Button>
  195. </center>
  196. </Grid>
  197. </Grid>
  198. </form>
  199. <div>
  200. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  201. <DialogTitle>注意</DialogTitle>
  202. <DialogContent style={{ display: 'flex', }}>
  203. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  204. </DialogContent>
  205. <DialogActions>
  206. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  207. </DialogActions>
  208. </Dialog>
  209. </div>
  210. </Grid>
  211. );
  212. };
  213. export default PublicNoticeApplyForm;