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.
 
 

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