Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

199 рядки
8.5 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Box,
  7. Button
  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 * as DateUtils from "utils/DateUtils";
  13. import { useParams } from "react-router-dom";
  14. import { useNavigate } from "react-router-dom";
  15. import Loadable from 'components/Loadable';
  16. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  17. const PaymentDetails = Loadable(React.lazy(() => import('./PaymentDetails')));
  18. const DataGrid = Loadable(React.lazy(() => import('./DataGrid')));
  19. import ForwardIcon from '@mui/icons-material/Forward';
  20. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  21. import {FormattedMessage,useIntl} from "react-intl";
  22. const BackgroundHead = {
  23. backgroundImage: `url(${titleBackgroundImg})`,
  24. width: '100%',
  25. height: '100%',
  26. backgroundSize: 'contain',
  27. backgroundRepeat: 'no-repeat',
  28. backgroundColor: '#0C489E',
  29. backgroundPosition: 'right'
  30. }
  31. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const Index = () => {
  33. const params = useParams();
  34. const navigate = useNavigate()
  35. const intl = useIntl();
  36. const [responeData, setResponeData] = React.useState({});
  37. const [transactionData, setTransactionData] = React.useState({});
  38. const [record, setRecord] = React.useState({});
  39. const [itemList, setItemList] = React.useState([]);
  40. const [onReady, setOnReady] = React.useState(false);
  41. const [onDownload, setOnDownload] = React.useState(false);
  42. // const [detailsOrder, setDetailsOrder] = React.useState(2);
  43. const { locale } = intl;
  44. React.useEffect(() => {
  45. loadForm();
  46. // window.addEventListener('resize', handleResize)
  47. }, []);
  48. React.useEffect(() => {
  49. if (Object.keys(responeData).length > 0) {
  50. setTransactionData(responeData);
  51. }
  52. }, [responeData]);
  53. React.useEffect(() => {
  54. if (Object.keys(transactionData).length > 0) {
  55. console.log(transactionData)
  56. console.log(itemList)
  57. console.log(record)
  58. setOnReady(true);
  59. }
  60. }, [transactionData]);
  61. // const handleResize = () => {
  62. // setDetailsOrder(window.innerWidth > 1023 ? 2 : -1);
  63. // }
  64. const doPrint = () => {
  65. // window.print();
  66. setOnDownload(true)
  67. const local = locale
  68. // console.log(local)
  69. HttpUtils.fileDownload({
  70. url: UrlUtils.GEN_PAYMENT_RECEIPT+"/"+params.id+"/"+local,
  71. onResponse:()=>{
  72. setOnDownload(false)
  73. },
  74. onError:()=>{
  75. setOnDownload(false)
  76. }
  77. });
  78. };
  79. const loadForm = () => {
  80. if (params.id > 0) {
  81. HttpUtils.get({
  82. url: UrlUtils.PAYMENT_LOAD + "/" + params.id,
  83. onSuccess: (responseData) => {
  84. if (!responseData.data?.id) {
  85. navigate("/paymentPage/search");
  86. }
  87. if(responseData.data.status==null||responseData.data.status=="INPR"){
  88. HttpUtils.post({
  89. url: UrlUtils.PAYMENT_RETRY_STATUS_API,
  90. params:{
  91. "paymentId": params.id
  92. },
  93. onSuccess: function(responseData2){
  94. responseData2.data["transDateStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "DD/MM/YYYY");
  95. responseData2.data["transTimeStr"] = DateUtils.dateFormat(responseData2.data.transDateTime, "HH:mm:ss");
  96. setResponeData(responseData2.transactionData)
  97. setItemList(responseData2.paymentItemList)
  98. setRecord(responseData2.data);
  99. },
  100. onError: function(){
  101. responseData.data["transDateStr"] = DateUtils.dateFormat(responseData.data.transDateTime, "DD/MM/YYYY");
  102. responseData.data["transTimeStr"] = DateUtils.dateFormat(responseData.data.transDateTime, "HH:mm:ss");
  103. setResponeData(responseData)
  104. }
  105. });
  106. }else{
  107. responseData.data["transDateStr"] = DateUtils.dateFormat(responseData.data.transDateTime, "DD/MM/YYYY");
  108. responseData.data["transTimeStr"] = DateUtils.dateFormat(responseData.data.transDateTime, "HH:mm:ss");
  109. setResponeData(responseData)
  110. setItemList(responseData.paymentItemList)
  111. setRecord(responseData.data);
  112. }
  113. }
  114. });
  115. }
  116. }
  117. return (
  118. !onReady ?
  119. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  120. <Grid item>
  121. <LoadingComponent />
  122. </Grid>
  123. </Grid>
  124. :
  125. (
  126. <div>
  127. <style>
  128. {`@media print {.printHidden{display: none;} .printOrder{order:-1 !important;}`}
  129. </style>
  130. <Grid container className="printheight" sx={{ minHeight: '80%', backgroundColor: '#fff' }} direction="column" justifyContent="flex-start" alignItems="center" >
  131. <Grid className="printHidden" item xs={12} width="100%">
  132. <div style={BackgroundHead} width="100%">
  133. <Stack direction="row" height='70px'>
  134. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>
  135. <FormattedMessage id="payDetail"/>
  136. </Typography>
  137. </Stack>
  138. </div>
  139. </Grid>
  140. <Grid item xs={12} width={{xs:"90%", sm:"90%", md:"90%", lg:"80%"}}>
  141. <Button
  142. aria-label={intl.formatMessage({id: 'back'})}
  143. title={intl.formatMessage({id: 'back'})}
  144. sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}
  145. >
  146. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  147. </Button>
  148. </Grid>
  149. {/*row 1*/}
  150. <Grid item xs={12} md={12} spacing={2} sx={{ textAlign: "center" }}>
  151. <Grid container justifyContent="center" direction="column" spacing={2} sx={{ p: 2 }} alignitems="stretch" >
  152. <Grid item className="printOrder" xs={12} md={12} sx={{ pt: 2 }} style={{ height: '100%', order: 1 }}>
  153. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  154. <PaymentDetails
  155. formData={record}
  156. doPrint={doPrint}
  157. onDownload={onDownload}
  158. style={{
  159. display: "flex",
  160. height: "100%",
  161. flex: 1
  162. }}
  163. />
  164. </Box>
  165. </Grid>
  166. <Grid item xs={12} md={12} sx={{ pt: 1, pb: 2 }} style={{ height: '100%', order: 2 }}>
  167. <Box xs={12} md={12} sx={{ border: '3px solid #eee', borderRadius: '10px' }} >
  168. <DataGrid
  169. recordList={itemList}
  170. />
  171. </Box>
  172. </Grid>
  173. </Grid>
  174. </Grid>
  175. {/*row 2*/}
  176. </Grid >
  177. </div>
  178. )
  179. );
  180. };
  181. export default Index;