Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

265 rindas
12 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. // setFormData(loadedData);
  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. remarks: values.remarks ? values.remarks : "",
  84. },
  85. files: [attachment],
  86. onSuccess: function () {
  87. notifyActionSuccess('申請提交成功!')
  88. navigate("/publicNotice");
  89. // location.reload();
  90. }
  91. });
  92. }
  93. });
  94. const readFile = (event) => {
  95. let file = event.target.files[0];
  96. if (file) {
  97. if (file.name.toLowerCase().substr(file.name.length - 4).includes(".doc")
  98. || file.name.toLowerCase().substr(file.name.length - 5).includes(".docx")
  99. || file.name.toLowerCase().substr(file.name.length - 4).includes(".xls")
  100. || file.name.toLowerCase().substr(file.name.length - 5).includes(".xlsx")
  101. ) {
  102. setAttachment(event.target.files[0]);
  103. } else {
  104. setWarningText("請上傳有效檔案 (檔案格式: .doc, .docx, .xls, .xlsx)");
  105. setIsWarningPopUp(true);
  106. setAttachment({});
  107. document.getElementById("uploadFileBtn").value = "";
  108. return;
  109. }
  110. }
  111. }
  112. return (
  113. <Grid container sx={{ minHeight: '95vh', backgroundColor: '#ffffff', mb: 3 }} direction="column" alignItems="center">
  114. <Grid item xs={12} md={12} width="100%" >
  115. <div style={BackgroundHead}>
  116. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  117. <Typography ml={15} color='#FFF' variant="h4">申請公共啟事</Typography>
  118. </Stack>
  119. </div>
  120. </Grid>
  121. <Grid item xs={12} width="60%">
  122. <Button title="返回" sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate("/publicNotice") }}>
  123. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  124. </Button>
  125. </Grid>
  126. {/* <Grid item xs={12}>
  127. <Typography variant="h5">申請公共啟事</Typography>
  128. </Grid> */}
  129. <Grid item xs={12} md={12} width={{ md: "60%", xs: "90%" }}>
  130. <Box xs={12} mt={1} sx={{ p: 2, border: '3px groove grey', borderRadius: '10px' }}>
  131. <form onSubmit={formik.handleSubmit}>
  132. <Grid container spacing={1} sx={{ minHeight: '80vh' }} direction="row" justifyContent="flex-start" alignItems="center">
  133. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1 }}>
  134. {FieldUtils.getTextField({
  135. label: "聯絡人:",
  136. valueName: "contactPerson",
  137. form: formik,
  138. disabled: true
  139. })}
  140. </Grid>
  141. <Grid item xs={12} md={12}>
  142. {FieldUtils.getPhoneField({
  143. label: "聯繫電話:",
  144. disabled: true,
  145. valueName: {
  146. code: "tel_countryCode",
  147. num: "phoneNumber",
  148. },
  149. form: formik
  150. })}
  151. </Grid>
  152. <Grid item xs={12} md={12}>
  153. {FieldUtils.getPhoneField({
  154. label: "聯繫傳真:",
  155. disabled: true,
  156. valueName: {
  157. code: "fax_countryCode",
  158. num: "faxNumber",
  159. },
  160. form: formik
  161. })}
  162. </Grid>
  163. <Grid item xs={12} lg={12}>
  164. <Grid container alignItems={"center"}>
  165. <Grid item xs={12} md={3} lg={3}
  166. sx={{ display: 'flex', alignItems: 'center' }}>
  167. <Typography variant="h5">目標期數:</Typography>
  168. </Grid>
  169. <Grid item xs={12} md={6} lg={6}>
  170. <RadioGroup
  171. aria-labelledby="demo-radio-buttons-group-label"
  172. id="issueId"
  173. name="issueId"
  174. defaultValue={issueId}
  175. onChange={(event) => {
  176. setIssueId(event.target.value);
  177. }}
  178. >
  179. {
  180. selections
  181. }
  182. </RadioGroup>
  183. </Grid>
  184. </Grid>
  185. </Grid>
  186. <Grid item xs={12} md={12} lg={12}>
  187. <Grid container direction="row" justifyContent="flex-start" alignItems="center">
  188. <Grid item xs={12} md={3} lg={3}
  189. sx={{ display: 'flex', alignItems: 'center' }}>
  190. <Typography variant="h5">稿件檔案 ({"檔案大小應<10MB"}):</Typography>
  191. </Grid>
  192. <Grid item xs={12} md={3} lg={3}>
  193. <input
  194. id="uploadFileBtn"
  195. name="file"
  196. type="file"
  197. accept=".doc,.docx,.xls,.xlsx"
  198. style={{ display: 'none' }}
  199. onChange={(event) => {
  200. readFile(event)
  201. }}
  202. />
  203. {attachment.name}
  204. </Grid>
  205. <Grid item xs={12} md={3} lg={3}>
  206. <label htmlFor="uploadFileBtn">
  207. <Button
  208. component="span"
  209. variant="outlined"
  210. size="large"
  211. >{attachment ? "上傳檔案" : "重新上傳"}</Button>
  212. </label>
  213. </Grid>
  214. </Grid>
  215. </Grid>
  216. <Grid item xs={12} md={12} lg={12}>
  217. {FieldUtils.getTextArea({
  218. label: "備註:",
  219. valueName: "remarks",
  220. form: formik,
  221. inputProps: { maxLength: 255 }
  222. })}
  223. </Grid>
  224. <Grid item xs={12}>
  225. <center>
  226. <Button
  227. variant="contained"
  228. type="submit"
  229. size="large"
  230. >申請公共啟事</Button>
  231. </center>
  232. </Grid>
  233. </Grid>
  234. </form>
  235. </Box>
  236. </Grid>
  237. <div>
  238. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  239. <DialogTitle>注意</DialogTitle>
  240. <DialogContent style={{ display: 'flex', }}>
  241. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  242. </DialogContent>
  243. <DialogActions>
  244. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  245. </DialogActions>
  246. </Dialog>
  247. </div>
  248. </Grid>
  249. );
  250. };
  251. export default PublicNoticeApplyForm;