Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

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