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.
 
 

175 lines
5.5 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. Stack,
  5. Typography,
  6. Button,
  7. Dialog, DialogTitle, DialogContent, DialogActions
  8. } from '@mui/material';
  9. import { FiDataGrid } from "components/FiDataGrid";
  10. import * as DateUtils from "utils/DateUtils"
  11. import * as StatusUtils from "utils/statusUtils/PublicNoteStatusUtils";
  12. import { useNavigate } from "react-router-dom";
  13. // ==============================|| EVENT TABLE ||============================== //
  14. export default function SubmittedTab({ rows }) {
  15. const [selectedRowItems, setSelectedRowItems] = React.useState([]);
  16. const [isPopUp, setIsPopUp] = React.useState(false);
  17. //const [amount, setAmount] = React.useState(0);
  18. const navigate = useNavigate()
  19. const handleDetailClick = (params) => () => {
  20. navigate('/publicNotice/' + params.id);
  21. };
  22. const columns = [
  23. {
  24. id: 'appNo',
  25. field: 'appNo',
  26. headerName: '申請編號',
  27. flex: 1,
  28. },
  29. {
  30. id: 'created',
  31. field: 'created',
  32. headerName: '提交日期',
  33. flex: 1,
  34. valueGetter: (params) => {
  35. return DateUtils.datetimeStr(params.value);
  36. }
  37. },
  38. {
  39. id: 'contactPerson',
  40. field: 'contactPerson',
  41. headerName: '聯絡人',
  42. flex: 2,
  43. renderCell: (params) => {
  44. let phone = JSON.parse(params.row.contactTelNo);
  45. let faxNo = JSON.parse(params.row.contactFaxNo);
  46. let contact = "";
  47. if (phone) {
  48. contact = "電話: " + phone?.countryCode + " " + phone?.phoneNumber
  49. }
  50. if (faxNo && faxNo?.faxNumber) {
  51. if (contact != "")
  52. contact = contact + ", "
  53. contact = contact + "傳真:" + faxNo?.countryCode + " " + faxNo?.faxNumber
  54. }
  55. return (<>
  56. {params?.value}<br />
  57. {contact}
  58. </>);
  59. }
  60. },
  61. {
  62. id: 'remarks',
  63. field: 'remarks',
  64. headerName: '我的備註',
  65. flex: 3,
  66. },
  67. {
  68. id: 'status',
  69. field: 'status',
  70. headerName: '狀態',
  71. flex: 1,
  72. renderCell: (params) => {
  73. return [StatusUtils.getStatus(params)]
  74. },
  75. },
  76. {
  77. field: 'actions',
  78. type: 'actions',
  79. headerName: '',
  80. width: 100,
  81. cellClassName: 'actions',
  82. renderCell: (params) => {
  83. return <Button onClick={handleDetailClick(params)}>查看詳細</Button>;
  84. },
  85. }
  86. ];
  87. const getWindowContent = () => {
  88. var content = [];
  89. let totalAmount = 0;
  90. const datas = rows?.filter((row) =>
  91. selectedRowItems.includes(row.id)
  92. );
  93. for (var i = 0; i < datas?.length; i++) {
  94. content.push(<>
  95. <Stack direction="row" justifyContent="space-between"><Typography variant="h5">申請編號: {datas[i].appNo}</Typography>({DateUtils.datetimeStr(datas[i].created)})</Stack>
  96. 備註: {datas[i].remarks}
  97. <br /><br />
  98. </>);
  99. totalAmount += datas[i].fee;
  100. }
  101. content.push(<>
  102. 總計金額: {totalAmount} <br /><br />
  103. </>);
  104. //setAmount(totalAmount);
  105. return content;
  106. }
  107. function handleRowDoubleClick(params) {
  108. navigate('/publicNotice/' + params.id);
  109. }
  110. function doPayment() {
  111. setIsPopUp(false);
  112. let totalAmount = 0;
  113. const datas = rows?.filter((row) =>
  114. selectedRowItems.includes(row.id)
  115. );
  116. for (var i = 0; i < datas?.length; i++) {
  117. totalAmount += datas[i].fee;
  118. }
  119. navigate('/payment', { state: { amount: totalAmount } });
  120. }
  121. return (
  122. <>
  123. <div style={{ height: 400, width: '100%', padding: 4 }}>
  124. <FiDataGrid
  125. checkboxSelection
  126. disableRowSelectionOnClick
  127. rows={rows}
  128. columns={columns}
  129. initialState={{
  130. pagination: {
  131. paginationModel: { page: 0, pageSize: 5 },
  132. },
  133. }}
  134. onRowSelectionModelChange={(newSelection) => {
  135. setSelectedRowItems(newSelection);
  136. }}
  137. onRowDoubleClick={handleRowDoubleClick}
  138. />
  139. <Button variant="contained" onClick={() => { setIsPopUp(true) }}>付款</Button>
  140. </div>
  141. <div>
  142. <Dialog open={isPopUp} onClose={() => setIsPopUp(false)} >
  143. <DialogTitle></DialogTitle>
  144. <Typography variant="h2" style={{ padding: '16px' }}>確認付款</Typography>
  145. <DialogContent style={{ display: 'flex', }}>
  146. <Stack direction="column" justifyContent="space-between">
  147. {getWindowContent()}
  148. </Stack>
  149. </DialogContent>
  150. <DialogActions>
  151. <Button onClick={() => setIsPopUp(false)}>Close</Button>
  152. <Button onClick={() => doPayment()}>確認</Button>
  153. </DialogActions>
  154. </Dialog>
  155. </div>
  156. </>
  157. );
  158. }