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.
 
 

310 line
14 KiB

  1. // material-ui
  2. import {
  3. Dialog, DialogTitle, DialogContent, DialogActions,
  4. Typography,
  5. Grid,
  6. Stack,
  7. TextField,
  8. FormLabel,
  9. Button,
  10. RadioGroup, Radio,
  11. FormControlLabel
  12. } from '@mui/material';
  13. import * as UrlUtils from "utils/ApiPathConst";
  14. import * as HttpUtils from "utils/HttpUtils";
  15. import FileList from "components/FileList"
  16. import MainCard from "components/MainCard";
  17. import * as React from "react";
  18. import * as yup from 'yup';
  19. import { useParams } from "react-router-dom";
  20. import { useFormik } from 'formik';
  21. import { useNavigate } from "react-router-dom";
  22. import * as DateUtils from "utils/DateUtils"
  23. import Loadable from 'components/Loadable';
  24. import { notifyActionSuccess } from 'utils/CommonFunction';
  25. const UploadFileTable = Loadable(React.lazy(() => import('./UploadFileTable')));
  26. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  27. const FormPanel = ({ formData }) => {
  28. const [data, setData] = React.useState({});
  29. const [attachments, setAttachments] = React.useState([]);
  30. const [actionValue, setActionValue] = React.useState(true);
  31. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  32. const [warningText, setWarningText] = React.useState("");
  33. const navigate = useNavigate()
  34. const params = useParams();
  35. React.useEffect(() => {
  36. if (formData) {
  37. setData(formData);
  38. }
  39. }, [formData]);
  40. const formik = useFormik({
  41. enableReinitialize: true,
  42. initialValues: data,
  43. validationSchema: yup.object().shape({
  44. vaild: yup.string().max(255, "請輸入你的登入密碼").required('請輸入你的登入密碼'),
  45. }),
  46. onSubmit: values => {
  47. if (!actionValue) {
  48. if (!attachments || attachments.length <= 0) {
  49. setWarningText("請選擇上傳檔案");
  50. setIsWarningPopUp(true);
  51. return;
  52. }
  53. }
  54. if (isOverTime()) {
  55. setWarningText("回覆逾時,請重新申請。");
  56. setIsWarningPopUp(true);
  57. return;
  58. }
  59. // console.log(values);
  60. HttpUtils.postWithFiles({
  61. url: UrlUtils.REPLY_PROOF,
  62. params: {
  63. id: data.id,
  64. action: actionValue,
  65. vaild: values.vaild,
  66. },
  67. files: attachments ? attachments : [],
  68. onSuccess: function () {
  69. if (actionValue) {
  70. notifyActionSuccess("提交成功!")
  71. navigate("/proof/pay/" + params.id);
  72. } else {
  73. notifyActionSuccess("提交成功!")
  74. navigate("/proof/search");
  75. }
  76. },
  77. onFail: function (response) {
  78. setWarningText("行動失敗: 請檢查內容並再次提交回覆");
  79. setIsWarningPopUp(true);
  80. console.log(response);
  81. },
  82. onError: function (error) {
  83. setWarningText("行動失敗: 請檢查內容並再次提交回覆");
  84. setIsWarningPopUp(true);
  85. console.log(error);
  86. }
  87. });
  88. }
  89. });
  90. const readFile = (event) => {
  91. let file = event.target.files[0];
  92. if (file) {
  93. if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) {
  94. setWarningText("請上傳有效檔案 (檔案格式: .pdf)");
  95. setIsWarningPopUp(true);
  96. document.getElementById("uploadFileBtn").value = "";
  97. return;
  98. }
  99. if (file.size >= (10 * 1024 * 1034)) {
  100. setWarningText("上傳檔案大小應<10MB");
  101. setIsWarningPopUp(true);
  102. return;
  103. }
  104. file['id'] = attachments.length;
  105. setAttachments([
  106. ...attachments,
  107. file
  108. ]);
  109. document.getElementById("uploadFileBtn").value = "";
  110. }
  111. }
  112. const isOverTime = () => {
  113. let returnBeforeDate = DateUtils.convertToDate(formik.values?.returnBeforeDate);
  114. if (!returnBeforeDate) return true;
  115. let current = new Date();
  116. return current.getTime() > returnBeforeDate;
  117. }
  118. return (
  119. <MainCard xs={12} md={12} lg={12}
  120. border={false}
  121. content={false}>
  122. <Typography variant="h4" sx={{ textAlign: "left", mb: 2, borderBottom: "1px solid black" }}>
  123. 公共啟事:校對回覆
  124. </Typography>
  125. <form onSubmit={formik.handleSubmit}>
  126. {
  127. formik.values.replyDate ?
  128. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  129. <Grid item xs={12} md={12} textAlign="left">
  130. <Typography variant="h5">校對回覆日期: {DateUtils.datetimeStr_Cht(formik.values.replyDate)}</Typography>
  131. </Grid>
  132. <Grid item xs={12} md={12} textAlign="left">
  133. <Typography variant="h5">校對回覆: {formik.values.action ? (<span style={{ color: 'green' }}>可以付印(稿件正確)</span>) : (<span style={{ color: 'red' }}>未能付印(需要修改)</span>)}</Typography>
  134. </Grid>
  135. {
  136. formik.values.action ?
  137. null
  138. :
  139. <Grid item xs={12} md={12} textAlign="left">
  140. <FileList
  141. lang="ch"
  142. refId={params.id}
  143. refType={"proofReply"}
  144. dateHideable={true}
  145. disablePagination
  146. disableSelectionOnClick
  147. disableColumnMenu
  148. disableColumnSelector
  149. hideFooter
  150. />
  151. </Grid>
  152. }
  153. </Grid>
  154. :
  155. (
  156. isOverTime() ?
  157. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  158. <Grid item xs={12} md={12} textAlign="left">
  159. <Typography variant="h5">回覆逾時,請重新申請。</Typography>
  160. </Grid>
  161. </Grid>
  162. :
  163. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  164. <Grid item xs={12} md={12}>
  165. <RadioGroup
  166. aria-labelledby="demo-radio-buttons-group-label"
  167. id="action"
  168. name="action"
  169. defaultValue={true}
  170. onChange={(event) => {
  171. setActionValue(event.target.value == "true" ? true : false);
  172. }}
  173. >
  174. <FormControlLabel value={true} control={<Radio />} label="可以付印(稿件正確)" />
  175. <FormControlLabel value={false} control={<Radio />} label="未能付印(需要修改)" />
  176. </RadioGroup>
  177. </Grid>
  178. {
  179. actionValue ?
  180. null
  181. :
  182. <>
  183. <Grid item xs={12} md={12} textAlign="left">
  184. <Typography variant="h5">請上載稿件修改的檔案:</Typography>
  185. </Grid>
  186. <Grid item xs={12} md={12} textAlign="left">
  187. <input
  188. id="uploadFileBtn"
  189. name="file"
  190. type="file"
  191. accept=".pdf"
  192. style={{ display: 'none' }}
  193. disabled={attachments.length >= (formik.values.groupType == "Private Bill" ? 2 : 1)}
  194. onChange={(event) => {
  195. readFile(event)
  196. }}
  197. />
  198. <label htmlFor="uploadFileBtn">
  199. <Button
  200. component="span"
  201. variant="contained"
  202. size="large"
  203. disabled={attachments.length >= (formik.values.groupType == "Private Bill" ? 2 : 1)}
  204. >
  205. <Typography variant="h5">上載</Typography>
  206. </Button>
  207. </label>
  208. </Grid>
  209. <Grid item xs={12} md={12} textAlign="left">
  210. <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} />
  211. </Grid>
  212. </>
  213. }
  214. <Grid item xs={12} md={12} lg={12}>
  215. <Stack direction="row" alignItems="center">
  216. <FormLabel sx={{ paddingRight: 2, paddingBottom: 3, textAlign: "center" }}>
  217. <Typography variant="h5">簽署:</Typography>
  218. </FormLabel>
  219. <TextField
  220. fullWidth
  221. type="password"
  222. onChange={formik.handleChange}
  223. name="vaild"
  224. variant="outlined"
  225. error={Boolean(formik.errors["vaild"])}
  226. helperText={formik.errors["vaild"] ? formik.errors["vaild"] : ' '}
  227. placeholder="請輸入你的登入密碼"
  228. sx={
  229. {
  230. "& .MuiInputBase-input.Mui-disabled": {
  231. WebkitTextFillColor: "#000000",
  232. background: "#f8f8f8",
  233. },
  234. width: '50%'
  235. }
  236. }
  237. />
  238. </Stack>
  239. </Grid>
  240. <Grid item xs={12} md={12} textAlign="left">
  241. <Button
  242. size="large"
  243. variant="contained"
  244. color="success"
  245. type="submit"
  246. sx={{
  247. textTransform: 'capitalize',
  248. alignItems: 'end'
  249. }}>
  250. <Typography variant="h5">提交回覆</Typography>
  251. </Button>
  252. </Grid>
  253. </Grid>
  254. )
  255. }
  256. </form>
  257. <div>
  258. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  259. <DialogTitle>注意</DialogTitle>
  260. <DialogContent style={{ display: 'flex', }}>
  261. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  262. </DialogContent>
  263. <DialogActions>
  264. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  265. </DialogActions>
  266. </Dialog>
  267. </div>
  268. </MainCard>
  269. );
  270. };
  271. export default FormPanel;