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ů.
 
 

295 řádky
14 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import { useParams } from "react-router-dom";
  13. import { useNavigate } from "react-router-dom";
  14. import * as DateUtils from "utils/DateUtils"
  15. import * as FormatUtils from "utils/FormatUtils";
  16. import Loadable from 'components/Loadable';
  17. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  18. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  19. const BackgroundHead = {
  20. backgroundImage: `url(${titleBackgroundImg})`,
  21. width: '100%',
  22. height: '100%',
  23. backgroundSize: 'contain',
  24. backgroundRepeat: 'no-repeat',
  25. backgroundColor: '#0C489E',
  26. backgroundPosition: 'right'
  27. }
  28. import {
  29. // useEffect,
  30. useState
  31. } from "react";
  32. import { PNSPS_BUTTON_THEME, PNSPS_LONG_BUTTON_THEME } from "../../../themes/buttonConst";
  33. import { ThemeProvider } from "@emotion/react";
  34. import { FormattedMessage, useIntl } from "react-intl";
  35. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  36. const Index = () => {
  37. const params = useParams();
  38. const navigate = useNavigate()
  39. const [fee, setFee] = useState(0);
  40. const [record, setRecord] = React.useState({});
  41. const [onReady, setOnReady] = React.useState(false);
  42. const [isPopUp, setIsPopUp] = useState(false);
  43. const [paymentHoldedErrText, setPaymentHoldedErrText] = React.useState("");
  44. const [paymentHoldedErr, setPaymentHoldedErr] = React.useState(false);
  45. const intl = useIntl();
  46. React.useEffect(() => {
  47. loadForm();
  48. }, []);
  49. React.useEffect(() => {
  50. setOnReady(true);
  51. }, [record]);
  52. const loadForm = () => {
  53. if (params.id > 0) {
  54. HttpUtils.get({
  55. url: UrlUtils.GET_PROOF_PAY + "/" + params.id,
  56. onSuccess: (responseData) => {
  57. // if (!responseData.data?.id) {
  58. // navigate("/proof/search");
  59. // }
  60. setRecord(responseData.data);
  61. setFee(responseData.data.fee);
  62. },
  63. onError: () => {
  64. }
  65. });
  66. }
  67. }
  68. function doPayment() {
  69. setIsPopUp(false);
  70. let appIdList = [record?.appId]
  71. handlePaymentCheck(appIdList)
  72. }
  73. const handlePaymentCheck = (appIdList) => {
  74. HttpUtils.post({
  75. url: UrlUtils.PAYMENT_CHECK,
  76. params: {
  77. appIds: appIdList
  78. },
  79. onSuccess: (responseData) => {
  80. const latestData = {};
  81. responseData.forEach(item => {
  82. const { appId, timeDiff } = item;
  83. if (latestData[appId] === undefined || timeDiff < latestData[appId].timeDiff) {
  84. latestData[appId] = item;
  85. }
  86. });
  87. const latestDataObjects = Object.values(latestData);
  88. const filteredData = latestDataObjects.filter(item => item.timeDiff > 30 || item.status !== "APPR");
  89. const filteredAppIds = filteredData.map(item => item.appId);
  90. const appIdsNotInData = appIdList.filter(appId => !latestDataObjects.some(item => item.appId === appId));
  91. const combinedAppIdsArray = [...appIdsNotInData, ...filteredAppIds];
  92. const readyToPayment = appIdList.every(appId => combinedAppIdsArray.includes(appId));
  93. if (readyToPayment) {
  94. navigate('/paymentPage', { state: { amount: fee, appIdList: appIdList } });
  95. } else {
  96. const appIdsInData = appIdList.filter(appId => !combinedAppIdsArray.some(item => item === appId));
  97. const HoldingApplication = latestDataObjects.filter(item => appIdsInData.includes(item.appId));
  98. const resultString = HoldingApplication.map(item => item.appNo).join(' , ');
  99. setPaymentHoldedErrText(resultString);
  100. // setPaymentHoldedErrText(intl.formatMessage({ id: 'MSG.paymentHolded' }, { appNo: record.appNo }));
  101. setPaymentHoldedErr(true);
  102. }
  103. }
  104. });
  105. };
  106. return (
  107. !onReady ?
  108. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  109. <Grid item>
  110. <LoadingComponent />
  111. </Grid>
  112. </Grid>
  113. :
  114. (
  115. <Grid container sx={{ minHeight: '110vh', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  116. <Grid item xs={12} width="100%">
  117. <div style={BackgroundHead} width="100%" >
  118. <Stack direction="row" height='70px'>
  119. <Typography ml={15} color='#FFF' variant="h4" sx={{ display: { xs: 'none', sm: 'none', md: 'block' }, pt: 2 }}>
  120. <FormattedMessage id="proofRecord" />
  121. </Typography>
  122. </Stack>
  123. </div>
  124. </Grid>
  125. {/*row 1*/}
  126. <Grid item xs={12} md={12} >
  127. <Grid container justifyContent="flex-start" alignItems="center" >
  128. <center>
  129. <Grid item xs={12} md={8} >
  130. <Typography variant="h3" sx={{ textAlign: "left", ml: 4, mr: 4, mt: 4, borderBottom: "1px solid black" }}>
  131. <FormattedMessage id="proofPaymentHeader_online" />
  132. </Typography>
  133. <Typography variant="h4" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  134. <div dangerouslySetInnerHTML={{
  135. __html: intl.formatMessage(
  136. {
  137. id: 'proofPaymentBody_online'
  138. },
  139. {
  140. appNo: record?.appNo,
  141. }
  142. )
  143. }} />
  144. <br />
  145. <div dangerouslySetInnerHTML={{
  146. __html: intl.formatMessage(
  147. {
  148. id: 'proofPaymentBody_online2'
  149. },
  150. {
  151. paymentDeadline: DateUtils.dateStr(record?.closingDate),
  152. }
  153. )
  154. }} />
  155. <br />
  156. </Typography>
  157. <Typography variant="h4" sx={{ ml: 8, textAlign: "left" }}>
  158. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  159. <Button
  160. component="span"
  161. variant="contained"
  162. sx={{mr: 4 }}
  163. onClick={() => { setIsPopUp(true) }}
  164. >
  165. <FormattedMessage id="payInstantly" />
  166. </Button>
  167. </ThemeProvider>
  168. <FormattedMessage id="or" />
  169. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  170. <Button
  171. component="span"
  172. variant="contained"
  173. sx={{ ml: { sm: 4, md: 4, lg: 4 }, mr: 4, mt: { xs: 2, sm: 2 }, mb: { xs: 2, sm: 2 } }}
  174. onClick={() => {
  175. navigate("/publicNotice");
  176. }}
  177. >
  178. <FormattedMessage id="payLater" />
  179. </Button>
  180. (<FormattedMessage id="backToNoticePage" />)
  181. </ThemeProvider>
  182. </Typography>
  183. <Typography variant="h4" sx={{ ml: 8, mt: 4, mr: 8, textAlign: "left" }}>
  184. <div dangerouslySetInnerHTML={{
  185. __html: intl.formatMessage(
  186. {
  187. id: 'proofPaymentBody_online3'
  188. }
  189. )
  190. }} />
  191. <br />
  192. </Typography>
  193. </Grid>
  194. </center>
  195. </Grid>
  196. </Grid>
  197. <div>
  198. <Dialog
  199. open={isPopUp}
  200. onClose={() => setIsPopUp(false)}
  201. PaperProps={{
  202. sx: {
  203. minWidth: '40vw',
  204. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '30vw' },
  205. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '50vh' }
  206. }
  207. }}
  208. >
  209. <DialogTitle>
  210. <Typography variant="h3" >
  211. <FormattedMessage id="payConfirm" />
  212. </Typography>
  213. </DialogTitle>
  214. <DialogContent style={{ display: 'flex', }}>
  215. <Stack direction="column" justifyContent="space-between">
  216. <Typography variant="h4">
  217. <FormattedMessage id="totalAmount" /> (HK$): {FormatUtils.currencyFormat(fee)}
  218. </Typography>
  219. </Stack>
  220. </DialogContent>
  221. <DialogActions>
  222. <Button onClick={() => setIsPopUp(false)}>
  223. <Typography variant="h5">
  224. <FormattedMessage id="close" />
  225. </Typography></Button>
  226. <Button onClick={() => doPayment()}><Typography variant="h5">
  227. <FormattedMessage id="confirm" />
  228. </Typography></Button>
  229. </DialogActions>
  230. </Dialog>
  231. </div>
  232. {/*row 2*/}
  233. <div>
  234. <Dialog
  235. open={paymentHoldedErr}
  236. onClose={() => setPaymentHoldedErr(false)}
  237. PaperProps={{
  238. sx: {
  239. minWidth: '40vw',
  240. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  241. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  242. }
  243. }}
  244. >
  245. <DialogTitle></DialogTitle>
  246. <Typography variant="h4" style={{ paddingLeft: '24px' }}><FormattedMessage id="MSG.actionFail" /></Typography>
  247. <DialogContent style={{ display: 'flex', }}>
  248. <Stack direction="column" justifyContent="space-between">
  249. <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: 'MSG.paymentHolded' }, { appNo: paymentHoldedErrText }) }} />
  250. </Stack>
  251. </DialogContent>
  252. <DialogActions>
  253. <Button onClick={() => setPaymentHoldedErr(false)} aria-label={intl.formatMessage({ id: 'close' })}>
  254. <Typography variant="h5">
  255. <FormattedMessage id="close" />
  256. </Typography></Button>
  257. </DialogActions>
  258. </Dialog>
  259. </div>
  260. </Grid >
  261. )
  262. );
  263. };
  264. export default Index;