您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

357 行
16 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 {FormattedMessage, 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 { locale } = intl;
  33. const [data, setData] = React.useState({});
  34. const [attachments, setAttachments] = React.useState([]);
  35. const [actionValue, setActionValue] = React.useState(true);
  36. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  37. const [warningText, setWarningText] = React.useState("");
  38. const navigate = useNavigate()
  39. const params = useParams();
  40. React.useEffect(() => {
  41. if (formData) {
  42. setData(formData);
  43. }
  44. }, [formData]);
  45. const formik = useFormik({
  46. enableReinitialize: true,
  47. initialValues: data,
  48. validationSchema: yup.object().shape({
  49. vaild: yup.string().max(255, intl.formatMessage({id: 'requireLoginPassword'})).required(intl.formatMessage({id: 'requireLoginPassword'})),
  50. }),
  51. onSubmit: values => {
  52. if (!actionValue) {
  53. if (!attachments || attachments.length <= 0) {
  54. setWarningText(intl.formatMessage({id: 'requireFile'}));
  55. setIsWarningPopUp(true);
  56. return;
  57. }
  58. }
  59. if (isOverTime()) {
  60. setWarningText("回覆逾時,請重新申請。");
  61. setIsWarningPopUp(true);
  62. return;
  63. }
  64. // console.log(values);
  65. HttpUtils.postWithFiles({
  66. url: UrlUtils.REPLY_PROOF,
  67. params: {
  68. id: data.id,
  69. action: actionValue,
  70. vaild: values.vaild,
  71. },
  72. files: attachments ? attachments : [],
  73. onSuccess: function () {
  74. notifyActionSuccess("提交成功!")
  75. if (actionValue) {
  76. if(data.creditor){
  77. navigate("/proof/search");
  78. }else{
  79. navigate("/proof/pay/" + params.id);
  80. }
  81. } else {
  82. navigate("/proof/search");
  83. }
  84. },
  85. onFail: function (response) {
  86. setWarningText(intl.formatMessage({id: 'actionFail'}));
  87. setIsWarningPopUp(true);
  88. console.log(response);
  89. },
  90. onError: function (error) {
  91. setWarningText(intl.formatMessage({id: 'actionFail'}));
  92. setIsWarningPopUp(true);
  93. console.log(error);
  94. }
  95. });
  96. }
  97. });
  98. const readFile = (event) => {
  99. let file = event.target.files[0];
  100. if (file) {
  101. if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) {
  102. setWarningText(intl.formatMessage({id: 'requireValidFileWithPdfFormat'}));
  103. setIsWarningPopUp(true);
  104. document.getElementById("uploadFileBtn").value = "";
  105. return;
  106. }
  107. if (file.size >= (10 * 1024 * 1034)) {
  108. setWarningText(intl.formatMessage({id: 'fileSizeWarning'}));
  109. setIsWarningPopUp(true);
  110. return;
  111. }
  112. file['id'] = attachments.length;
  113. setAttachments([
  114. ...attachments,
  115. file
  116. ]);
  117. document.getElementById("uploadFileBtn").value = "";
  118. }
  119. }
  120. const isOverTime = () => {
  121. let returnBeforeDate = DateUtils.convertToDate(formik.values?.returnBeforeDate);
  122. if (!returnBeforeDate) return true;
  123. let current = new Date();
  124. return current.getTime() > returnBeforeDate;
  125. }
  126. return (
  127. <MainCard xs={12} sm={12} md={12} lg={12}
  128. border={false}
  129. content={false}>
  130. <Typography variant="h4" sx={{ textAlign: "left", mb: 2, borderBottom: "1px solid black" }}>
  131. <FormattedMessage id="publicNoticePaymentProofComment"/>
  132. </Typography>
  133. <form onSubmit={formik.handleSubmit}>
  134. {
  135. formik.values.replyDate ?
  136. <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }}>
  137. <Grid item xs={12} sm={12} md={12} lg={8} textAlign="left">
  138. <Typography variant="h5">
  139. <FormattedMessage id="proofReplyDate" />:
  140. {
  141. locale === 'en' ?
  142. DateUtils.dateStr(formik.values.replyDate)
  143. :
  144. DateUtils.datetimeStr_Cht(formik.values.replyDate)
  145. }
  146. </Typography>
  147. </Grid>
  148. <Grid item xs={12} md={12} textAlign="left">
  149. <Typography variant="h5">
  150. <FormattedMessage id="proofReply" />: {formik.values.action ?
  151. (<span style={{ color: 'green' }}>
  152. <FormattedMessage id="proofErrorFree" />
  153. </span>)
  154. :
  155. (<span style={{ color: 'red' }}>
  156. <FormattedMessage id="proofWithError" />
  157. </span>)}
  158. </Typography>
  159. </Grid>
  160. {
  161. formik.values.action ?
  162. null
  163. :
  164. <Grid item xs={12} md={12} textAlign="left" sx={{ width:'95%', maxWidth: {xs:'70vw', sm:'72vw', md:'75vw',lg:'80vw'}}}>
  165. <FileList
  166. lang="ch"
  167. refId={params.id}
  168. refType={"proofReply"}
  169. dateHideable={true}
  170. disablePagination
  171. disableSelectionOnClick
  172. disableColumnMenu
  173. disableColumnSelector
  174. hideFooter
  175. />
  176. </Grid>
  177. }
  178. </Grid>
  179. :
  180. (
  181. isOverTime() ?
  182. <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }} spacing={1}>
  183. <Grid item xs={12} md={12} textAlign="left">
  184. <Typography variant="h5">回覆逾時,請重新申請。</Typography>
  185. </Grid>
  186. </Grid>
  187. :
  188. <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }} spacing={1}>
  189. <Grid item xs={12} md={12}>
  190. <RadioGroup
  191. aria-labelledby="demo-radio-buttons-group-label"
  192. id="action"
  193. name="action"
  194. defaultValue={true}
  195. onChange={(event) => {
  196. setActionValue(event.target.value === "true" ? true : false);
  197. }}
  198. >
  199. <FormControlLabel value={true} control={<Radio />} label={intl.formatMessage({id: 'proofErrorFree'})} />
  200. <FormControlLabel value={false} control={<Radio />} label={intl.formatMessage({id: 'proofWithError'})} />
  201. </RadioGroup>
  202. </Grid>
  203. {
  204. actionValue ?
  205. null
  206. :
  207. <>
  208. <Grid item xs={12} md={12} textAlign="left">
  209. <Typography variant="h5">
  210. <FormattedMessage id="requiredUploadFix" />:
  211. </Typography>
  212. </Grid>
  213. <Grid item xs={12} md={12} textAlign="left">
  214. <input
  215. id="uploadFileBtn"
  216. name="file"
  217. type="file"
  218. accept=".pdf"
  219. style={{ display: 'none' }}
  220. disabled={attachments.length >= (formik.values.groupType === "Private Bill" ? 2 : 1)}
  221. onChange={(event) => {
  222. readFile(event)
  223. }}
  224. />
  225. <label htmlFor="uploadFileBtn">
  226. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  227. <Button
  228. color="save"
  229. component="span"
  230. variant="contained"
  231. aria-label={intl.formatMessage({id: 'upload'})}
  232. disabled={attachments.length >= (formik.values.groupType === "Private Bill" ? 2 : 1)}
  233. >
  234. <FormattedMessage id="upload" />
  235. </Button>
  236. </ThemeProvider>
  237. </label>
  238. </Grid>
  239. <Grid item xs={12} sm={12} md={12} lg={12} textAlign="left" sx={{ width:'95%', maxWidth: {xs:'70vw', sm:'72vw', md:'75vw',lg:'80vw'}}} >
  240. <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} />
  241. </Grid>
  242. </>
  243. }
  244. <Grid item xs={12} sm={12} md={12} lg={12}>
  245. <Stack direction="row" alignItems="center">
  246. <FormLabel sx={{ paddingRight: 2, paddingBottom: 3, textAlign: "center" }}>
  247. <Typography variant="h5">
  248. <FormattedMessage id="sign" />:
  249. </Typography>
  250. </FormLabel>
  251. <TextField
  252. fullWidth
  253. type="password"
  254. onChange={formik.handleChange}
  255. name="vaild"
  256. variant="outlined"
  257. error={Boolean(formik.errors["vaild"])}
  258. helperText={formik.errors["vaild"] ? formik.errors["vaild"] : ' '}
  259. placeholder={intl.formatMessage({id: 'requireLoginPassword'})}
  260. sx={
  261. {
  262. "& .MuiInputBase-input.Mui-disabled": {
  263. WebkitTextFillColor: "#000000",
  264. background: "#f8f8f8",
  265. },
  266. width: '70%'
  267. }
  268. }
  269. />
  270. </Stack>
  271. </Grid>
  272. <Grid item xs={12} md={12} textAlign="left">
  273. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  274. <Button
  275. variant="contained"
  276. color="success"
  277. type="submit"
  278. aria-label={intl.formatMessage({id: 'submitReply'})}
  279. >
  280. <FormattedMessage id="submitReply" />
  281. </Button>
  282. </ThemeProvider>
  283. </Grid>
  284. </Grid>
  285. )
  286. }
  287. </form>
  288. <div>
  289. <Dialog
  290. open={isWarningPopUp}
  291. onClose={() => setIsWarningPopUp(false)}
  292. PaperProps={{
  293. sx: {
  294. minWidth: '40vw',
  295. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  296. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  297. }
  298. }}
  299. >
  300. <DialogTitle>
  301. <FormattedMessage id="attention"/>
  302. </DialogTitle>
  303. <DialogContent style={{ display: 'flex', }}>
  304. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  305. </DialogContent>
  306. <DialogActions>
  307. <Button
  308. aria-label={intl.formatMessage({id: 'ok'})}
  309. onClick={() => setIsWarningPopUp(false)}
  310. >
  311. OK
  312. </Button>
  313. </DialogActions>
  314. </Dialog>
  315. </div>
  316. </MainCard>
  317. );
  318. };
  319. export default FormPanel;