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.
 
 

274 lines
13 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Button,
  6. RadioGroup,
  7. Dialog, DialogTitle, DialogContent, DialogActions,
  8. Stack, Box
  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 ForwardIcon from '@mui/icons-material/Forward';
  18. import { useNavigate } from "react-router-dom";
  19. import { notifyActionSuccess } from 'utils/CommonFunction';
  20. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  21. const PublicNoticeApplyForm = ({ loadedData, selections }) => {
  22. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  23. const [warningText, setWarningText] = React.useState("");
  24. const [attachment, setAttachment] = React.useState({});
  25. const [issueId, setIssueId] = React.useState(loadedData.issueId);
  26. const navigate = useNavigate();
  27. const BackgroundHead = {
  28. backgroundImage: `url(${titleBackgroundImg})`,
  29. width: 'auto',
  30. height: 'auto',
  31. backgroundSize: 'contain',
  32. backgroundRepeat: 'no-repeat',
  33. backgroundColor: '#0C489E',
  34. backgroundPosition: 'right'
  35. }
  36. // React.useEffect(()=>{
  37. // loadedData.careOf = loadedData.contactPerson
  38. // },[]);
  39. const formik = useFormik({
  40. enableReinitialize: true,
  41. initialValues: loadedData,
  42. validationSchema: yup.object().shape({
  43. contactPerson: yup.string().max(40, "不得超過 40 個字符").required('請輸入聯絡人'),
  44. tel_countryCode: yup.string().min(3, '請輸入3位數字').required('請輸入國際區號'),
  45. fax_countryCode: yup.string().min(3, '請輸入3位數字'),
  46. phoneNumber: yup.string().min(8, '請輸入8位數字').required('請輸入聯絡電話'),
  47. faxNumber: yup.string().min(8, '請輸入8位數字'),
  48. remarks: yup.string().max(255, "不得超過 255 個字符").nullable(),
  49. }),
  50. onSubmit: values => {
  51. if (!values.issueId) {
  52. setWarningText("請選擇目標期數");
  53. setIsWarningPopUp(true);
  54. return;
  55. }
  56. if (!attachment) {
  57. setWarningText("請選擇上傳檔案");
  58. setIsWarningPopUp(true);
  59. return;
  60. } else if (!attachment.size || attachment.size <= 0) {
  61. setWarningText("請上傳有效檔案");
  62. setIsWarningPopUp(true);
  63. return;
  64. } else if (attachment.size >= (10 * 1024 * 1034)) {
  65. setWarningText("上傳檔案大小應<10MB");
  66. setIsWarningPopUp(true);
  67. return;
  68. }
  69. HttpUtils.postWithFiles({
  70. url: UrlUtils.POST_PUBLIC_NOTICE_APPLY,
  71. params: {
  72. id: 0,
  73. contactPerson: values.contactPerson,
  74. contactTelNo: {
  75. countryCode: values.tel_countryCode,
  76. phoneNumber: values.phoneNumber
  77. },
  78. contactFaxNo: {
  79. countryCode: values.fax_countryCode,
  80. faxNumber: values.faxNumber
  81. },
  82. issueId: issueId,
  83. careOf: values.careOf ? values.careOf: "",
  84. remarks: values.remarks ? values.remarks : "",
  85. },
  86. files: [attachment],
  87. onSuccess: function () {
  88. notifyActionSuccess('申請提交成功!')
  89. navigate("/publicNotice");
  90. // location.reload();
  91. }
  92. });
  93. }
  94. });
  95. const readFile = (event) => {
  96. let file = event.target.files[0];
  97. if (file) {
  98. if (file.name.toLowerCase().substr(file.name.length - 4).includes(".doc")
  99. || file.name.toLowerCase().substr(file.name.length - 5).includes(".docx")
  100. || file.name.toLowerCase().substr(file.name.length - 4).includes(".xls")
  101. || file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")
  102. ) {
  103. setAttachment(event.target.files[0]);
  104. } else {
  105. setWarningText("請上傳有效檔案 (檔案格式: .doc, .docx, .xls, .xlsx)");
  106. setIsWarningPopUp(true);
  107. setAttachment({});
  108. document.getElementById("uploadFileBtn").value = "";
  109. return;
  110. }
  111. }
  112. }
  113. return (
  114. <Grid container sx={{ minHeight: '95vh', backgroundColor: '#ffffff', mb: 3 }} direction="column" alignItems="center">
  115. <Grid item xs={12} md={12} width="100%" >
  116. <div style={BackgroundHead}>
  117. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  118. <Typography ml={15} color='#FFF' variant="h4">申請公共啟事</Typography>
  119. </Stack>
  120. </div>
  121. </Grid>
  122. <Grid item xs={12} width="60%">
  123. <Button title="返回" sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate("/publicNotice") }}>
  124. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  125. </Button>
  126. </Grid>
  127. {/* <Grid item xs={12}>
  128. <Typography variant="h5">申請公共啟事</Typography>
  129. </Grid> */}
  130. <Grid item xs={12} md={12} width={{ md: "60%", xs: "90%" }}>
  131. <Box xs={12} mt={1} sx={{ p: 2, border: '3px groove grey', borderRadius: '10px' }}>
  132. <form onSubmit={formik.handleSubmit}>
  133. <Grid container spacing={1} sx={{ minHeight: '80vh' }} direction="row" justifyContent="flex-start" alignItems="center">
  134. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  135. {FieldUtils.getTextField({
  136. label: "聯絡人:",
  137. valueName: "contactPerson",
  138. form: formik,
  139. disabled: true
  140. })}
  141. </Grid>
  142. <Grid item xs={12} md={12}>
  143. {FieldUtils.getPhoneField({
  144. label: "聯繫電話:",
  145. disabled: true,
  146. valueName: {
  147. code: "tel_countryCode",
  148. num: "phoneNumber",
  149. },
  150. form: formik
  151. })}
  152. </Grid>
  153. <Grid item xs={12} md={12}>
  154. {FieldUtils.getPhoneField({
  155. label: "聯繫傳真:",
  156. disabled: true,
  157. valueName: {
  158. code: "fax_countryCode",
  159. num: "faxNumber",
  160. },
  161. form: formik
  162. })}
  163. </Grid>
  164. <Grid item xs={12} lg={12}>
  165. <Grid container alignItems={"center"}>
  166. <Grid item xs={12} md={3} lg={3}
  167. sx={{ display: 'flex', alignItems: 'center' }}>
  168. <Typography variant="h5">目標期數:</Typography>
  169. </Grid>
  170. <Grid item xs={12} md={6} lg={6}>
  171. <RadioGroup
  172. aria-labelledby="demo-radio-buttons-group-label"
  173. id="issueId"
  174. name="issueId"
  175. defaultValue={issueId}
  176. onChange={(event) => {
  177. setIssueId(event.target.value);
  178. }}
  179. >
  180. {
  181. selections
  182. }
  183. </RadioGroup>
  184. </Grid>
  185. </Grid>
  186. </Grid>
  187. <Grid item xs={12} md={12} lg={12}>
  188. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  189. <Grid item xs={12} md={3} lg={3}
  190. sx={{ display: 'flex', alignItems: 'center' }}>
  191. <Typography variant="h5">稿件檔案 ({"檔案大小應<10MB"}):</Typography>
  192. </Grid>
  193. <Grid item xs={12} md={3} lg={3}>
  194. <input
  195. id="uploadFileBtn"
  196. name="file"
  197. type="file"
  198. accept=".doc,.docx,.xls,.xlsx"
  199. style={{ display: 'none' }}
  200. onChange={(event) => {
  201. readFile(event)
  202. }}
  203. />
  204. {attachment.name}
  205. </Grid>
  206. <Grid item xs={12} md={3} lg={3}>
  207. <label htmlFor="uploadFileBtn">
  208. <Button
  209. component="span"
  210. variant="outlined"
  211. size="large"
  212. >{attachment ? "上傳檔案" : "重新上傳"}</Button>
  213. </label>
  214. </Grid>
  215. </Grid>
  216. </Grid>
  217. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  218. {FieldUtils.getTextField({
  219. label: "代理人:",
  220. valueName: "careOf",
  221. form: formik,
  222. // disabled: true
  223. })}
  224. </Grid>
  225. <Grid item xs={12} md={12} lg={12}>
  226. {FieldUtils.getTextArea({
  227. label: "備註:",
  228. valueName: "remarks",
  229. form: formik,
  230. inputProps: { maxLength: 255 }
  231. })}
  232. </Grid>
  233. <Grid item xs={12}>
  234. <center>
  235. <Button
  236. variant="contained"
  237. type="submit"
  238. size="large"
  239. >申請公共啟事</Button>
  240. </center>
  241. </Grid>
  242. </Grid>
  243. </form>
  244. </Box>
  245. </Grid>
  246. <div>
  247. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  248. <DialogTitle>注意</DialogTitle>
  249. <DialogContent style={{ display: 'flex', }}>
  250. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  251. </DialogContent>
  252. <DialogActions>
  253. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  254. </DialogActions>
  255. </Dialog>
  256. </div>
  257. </Grid>
  258. );
  259. };
  260. export default PublicNoticeApplyForm;