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.
 
 

139 lines
4.4 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. Button,
  5. Typography, useMediaQuery
  6. } from '@mui/material';
  7. import * as DateUtils from "utils/DateUtils";
  8. import * as StatusUtils from "utils/statusUtils/PublicNoteStatusUtils";
  9. import {useNavigate} from "react-router-dom";
  10. import {FiDataGrid} from "components/FiDataGrid";
  11. import {
  12. isORGLoggedIn,
  13. } from "utils/Utils";
  14. import {useTheme} from "@emotion/react";
  15. import {FormattedMessage, useIntl} from "react-intl";
  16. // ==============================|| EVENT TABLE ||============================== //
  17. export default function SearchPublicNoticeTable({ recordList }) {
  18. const [rows, setRows] = React.useState([]);
  19. const navigate = useNavigate()
  20. const theme = useTheme();
  21. const isMdOrLg = useMediaQuery(theme.breakpoints.up('md'));
  22. const intl = useIntl();
  23. const handleDetailClick = (params) => () => {
  24. navigate('/publicNotice/'+ params.id);
  25. };
  26. React.useEffect(() => {
  27. setRows(recordList);
  28. }, [recordList]);
  29. const columns = [
  30. {
  31. id: 'appNo',
  32. field: 'appNo',
  33. headerName: intl.formatMessage({id: 'applicationId'}),
  34. width: isMdOrLg ? 'auto' : 160,
  35. flex: isMdOrLg ? 1 : undefined,
  36. },
  37. {
  38. id: 'created',
  39. field: 'created',
  40. headerName: intl.formatMessage({id: 'submitDate'}),
  41. width: isMdOrLg ? 'auto' : 160,
  42. flex: isMdOrLg ? 1 : undefined,
  43. valueGetter: (params) => {
  44. return DateUtils.datetimeStr(params?.value);
  45. }
  46. },
  47. // {
  48. // id: 'contactPerson',
  49. // field: 'contactPerson',
  50. // headerName: '聯絡人',
  51. // flex: 2,
  52. // renderCell: (params) => {
  53. // let phone = JSON.parse(params.row.contactTelNo);
  54. // let faxNo = JSON.parse(params.row.contactFaxNo);
  55. // let contact = "";
  56. // if (phone) {
  57. // contact = "電話: " + phone?.countryCode + " " + phone?.phoneNumber
  58. // }
  59. // if (faxNo && faxNo?.faxNumber) {
  60. // if (contact != "")
  61. // contact = contact + ", "
  62. // contact = contact + "傳真:" + faxNo?.countryCode + " " + faxNo?.faxNumber
  63. // }
  64. // return (<>
  65. // {params?.value}<br />
  66. // {contact}
  67. // </>);
  68. // }
  69. // },
  70. {
  71. id: 'remarks',
  72. field: 'remarks',
  73. headerName: isORGLoggedIn()?"Care Of / 我的備註": intl.formatMessage({id: 'myRemarks'}),
  74. width: isMdOrLg ? 'auto' : 400,
  75. flex: isMdOrLg ? 3 : undefined,
  76. renderCell: (params) => (
  77. isORGLoggedIn()?
  78. <div>
  79. <Typography>Care Of: {params.row.careOf}</Typography>
  80. <Typography>
  81. <FormattedMessage id="myRemarks"/>: {params.row.remarks}
  82. </Typography>
  83. </div>:
  84. <div>
  85. <Typography>{params.row.remarks}</Typography>
  86. </div>
  87. )
  88. },
  89. {
  90. id: 'status',
  91. field: 'status',
  92. headerName: intl.formatMessage({id: 'status'}),
  93. width: 200,
  94. renderCell: (params) => {
  95. return [StatusUtils.getStatusIntl(params, intl)]
  96. },
  97. },
  98. {
  99. field: 'actions',
  100. type: 'actions',
  101. headerName: '',
  102. width: 150,
  103. cellClassName: 'actions',
  104. renderCell: (params) => {
  105. return <Button onClick={handleDetailClick(params)}>
  106. <FormattedMessage id="viewDetail"/>
  107. </Button>;
  108. },
  109. }
  110. ];
  111. function handleRowDoubleClick(params) {
  112. navigate('/publicNotice/'+ params.id);
  113. }
  114. return (
  115. <div style={{ minHeight: 400, width: '100%' }}>
  116. <FiDataGrid
  117. rows={rows}
  118. columns={columns}
  119. initialState={{
  120. pagination: {
  121. paginationModel: { page: 0, pageSize: 20 },
  122. },
  123. }}
  124. onRowDoubleClick={handleRowDoubleClick}
  125. getRowHeight={() => 'auto'}
  126. />
  127. </div>
  128. );
  129. }