25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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