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 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. 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. returnBeforeDate = returnBeforeDate.setHours(14, 0, 0, 0);
  116. let current = new Date();
  117. return current.getTime() > returnBeforeDate;
  118. }
  119. return (
  120. <MainCard xs={12} md={12} lg={12}
  121. border={false}
  122. content={false}>
  123. <Typography variant="h5" sx={{ textAlign: "left", mb: 2, borderBottom: "1px solid black" }}>
  124. 公共啟事:校對回覆
  125. </Typography>
  126. <form onSubmit={formik.handleSubmit}>
  127. {
  128. formik.values.replyDate ?
  129. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  130. <Grid item xs={12} md={12} textAlign="left">
  131. 校對回覆日期: {DateUtils.datetimeStr_Cht(formik.values.replyDate)}
  132. </Grid>
  133. <Grid item xs={12} md={12} textAlign="left">
  134. 校對回覆: {formik.values.action ? (<span style={{color:'green'}}>可以付印(稿件正確)</span>): (<span style={{color:'red'}}>未能付印(需要修改)</span>)}
  135. </Grid>
  136. {
  137. formik.values.action ?
  138. null
  139. :
  140. <Grid item xs={12} md={12} textAlign="left">
  141. <FileList
  142. lang="ch"
  143. refId={params.id}
  144. refType={"proofReply"}
  145. dateHideable={true}
  146. disablePagination
  147. disableSelectionOnClick
  148. disableColumnMenu
  149. disableColumnSelector
  150. hideFooter
  151. />
  152. </Grid>
  153. }
  154. </Grid>
  155. :
  156. (
  157. isOverTime() ?
  158. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  159. <Grid item xs={12} md={12} textAlign="left">
  160. 回覆逾時,請重新申請。
  161. </Grid>
  162. </Grid>
  163. :
  164. <Grid container direction="column" sx={{ paddingLeft: 4, paddingRight: 4 }} spacing={1}>
  165. <Grid item xs={12} md={12}>
  166. <RadioGroup
  167. aria-labelledby="demo-radio-buttons-group-label"
  168. id="action"
  169. name="action"
  170. defaultValue={true}
  171. onChange={(event) => {
  172. setActionValue(event.target.value == "true" ? true : false);
  173. }}
  174. >
  175. <FormControlLabel value={true} control={<Radio />} label="可以付印(稿件正確)" />
  176. <FormControlLabel value={false} control={<Radio />} label="未能付印(需要修改)" />
  177. </RadioGroup>
  178. </Grid>
  179. {
  180. actionValue ?
  181. null
  182. :
  183. <>
  184. <Grid item xs={12} md={12} textAlign="left">
  185. 請上載稿件修改的檔案:
  186. </Grid>
  187. <Grid item xs={12} md={12} textAlign="left">
  188. <input
  189. id="uploadFileBtn"
  190. name="file"
  191. type="file"
  192. accept=".pdf"
  193. style={{ display: 'none' }}
  194. disabled={attachments.length >= (formik.values.groupType == "A" ? 2 : 1)}
  195. onChange={(event) => {
  196. readFile(event)
  197. }}
  198. />
  199. <label htmlFor="uploadFileBtn">
  200. <Button
  201. component="span"
  202. variant="contained"
  203. size="large"
  204. disabled={attachments.length >= (formik.values.groupType == "A" ? 2 : 1)}
  205. >上載</Button>
  206. </label>
  207. </Grid>
  208. <Grid item xs={12} md={12} textAlign="left">
  209. <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} />
  210. </Grid>
  211. </>
  212. }
  213. <Grid item xs={12} md={12} lg={12}>
  214. <Stack direction="row" alignItems="center">
  215. <FormLabel sx={{ paddingRight: 2, paddingBottom: 3, textAlign: "center" }}>
  216. 簽署:
  217. </FormLabel>
  218. <TextField
  219. fullWidth
  220. type="password"
  221. onChange={formik.handleChange}
  222. name="vaild"
  223. variant="outlined"
  224. error={Boolean(formik.errors["vaild"])}
  225. helperText={formik.errors["vaild"] ? formik.errors["vaild"] : ' '}
  226. placeholder="請輸入你的登入密碼"
  227. sx={
  228. {
  229. "& .MuiInputBase-input.Mui-disabled": {
  230. WebkitTextFillColor: "#000000",
  231. background: "#f8f8f8",
  232. },
  233. width: '50%'
  234. }
  235. }
  236. />
  237. </Stack>
  238. </Grid>
  239. <Grid item xs={12} md={12} textAlign="left">
  240. <Button
  241. size="large"
  242. variant="contained"
  243. color="success"
  244. type="submit"
  245. sx={{
  246. textTransform: 'capitalize',
  247. alignItems: 'end'
  248. }}>
  249. 提交回覆
  250. </Button>
  251. </Grid>
  252. </Grid>
  253. )
  254. }
  255. </form>
  256. <div>
  257. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  258. <DialogTitle>注意</DialogTitle>
  259. <DialogContent style={{ display: 'flex', }}>
  260. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  261. </DialogContent>
  262. <DialogActions>
  263. <Button onClick={() => setIsWarningPopUp(false)}>OK</Button>
  264. </DialogActions>
  265. </Dialog>
  266. </div>
  267. </MainCard>
  268. );
  269. };
  270. export default FormPanel;