index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import { useEffect, useState } from 'react';
  2. import { useSelector } from 'react-redux'
  3. import { Table, Modal, message, Menu, Breadcrumb, Dropdown, Space, Form, Input, Button, Row, Col, Select } from 'antd';
  4. import { DownOutlined, PlusOutlined } from '@ant-design/icons';
  5. import './index.less';
  6. import apiObj from '@api/index';
  7. import utils from '@utils/index'
  8. const { pickCheckedTreeIds } = utils;
  9. const { post, api, xPost } = apiObj;
  10. const { Option } = Select;
  11. function MyMessage() {
  12. useEffect(() => {
  13. //刷新列表
  14. getTableData();
  15. }, []);
  16. const [size, setSize] = useState(15); //每页显示条数
  17. const [total, setTotal] = useState(0); //每页显示条数
  18. const [dataSource, setDataSource] = useState([]); //列表数据
  19. const [visible, setVisible] = useState(false); //弹窗查看
  20. const [confirmLoading, setConfirmLoading] = useState(false);
  21. const [msgDetail, setMsgDetail] = useState({});
  22. //从state中取出状态、类型列表
  23. const staticInfo = useSelector(state => {
  24. return state.staticInfo;
  25. });
  26. const { msgTypeList, msgStatusList } = staticInfo;
  27. //获取表格数据
  28. function getTableData(param = {}) {
  29. post(api.listManagePage, param).then((res) => {
  30. if (res.data.code === 200) {
  31. let data = res.data.data;
  32. setTotal(data.total);
  33. setDataSource(data.records);
  34. }
  35. })
  36. }
  37. //弹窗取消
  38. function handleCancel() {
  39. setVisible(false);
  40. }
  41. //新增子组织弹窗
  42. function showMessage(id) {
  43. getMsgDetail(id);
  44. setVisible(true);
  45. }
  46. function getMsgDetail(id) { //type:1我的通知,0通知管理
  47. xPost(api.getNoticeInfoById, { id: id, type: 1 }).then((res) => {
  48. const { data, code } = res.data;
  49. if (code === 200) {
  50. setMsgDetail(data);
  51. } else {
  52. message.warning(res.data.msg || '获取详情失败')
  53. }
  54. });
  55. }
  56. //每页显示条数切换
  57. function onSizeChange(){
  58. }
  59. //翻页
  60. function onPageChange(){
  61. }
  62. //表格渲染
  63. function RenderTable() {
  64. const columns = [
  65. { title: '标题', dataIndex: 'title', key: 'title' },
  66. {
  67. title: '类型', width: 150, dataIndex: 'typeName', key:'typeName'
  68. },
  69. { title: '发送者', dataIndex: 'sender', key: 'sender' },
  70. { title: '发送时间', width: 240, dataIndex: 'gmtCreate', key: 'gmtCreate' },
  71. {
  72. title: '阅读状态', key: 'statusName', dataIndex:'statusName'
  73. },
  74. {
  75. title: '操作', key: 'operation', render: (row) => {
  76. return (<Space size="middle">
  77. <a onClick={() => showMessage(row.id)}>查看</a>
  78. </Space>)
  79. }
  80. },
  81. ];
  82. return (
  83. <Table
  84. rowKey={record => record.id}
  85. scroll={{ y: 'calc(100vh - 320px)' }}
  86. columns={columns}
  87. dataSource={dataSource}
  88. pagination={{
  89. showSizeChanger:true,
  90. pageSizeOptions:[15,30,60,120],
  91. defaultPageSize:size,
  92. pageNo: 1,
  93. size:'small',
  94. total: total,
  95. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  96. }}
  97. />
  98. )
  99. }
  100. //筛选项渲染
  101. const [form] = Form.useForm();
  102. const onFinish = (values: any) => {
  103. getTableData(values);
  104. console.log('筛选项:', values);
  105. };
  106. const onReset = () => {
  107. form.resetFields();
  108. getTableData();
  109. };
  110. return (
  111. <div className='wrapper'>
  112. <div className="filter-box">
  113. <Form form={form} name="control-hooks" onFinish={onFinish}>
  114. <Row gutter={24}>
  115. <Col span={5} key={1}>
  116. <Form.Item name="type" label="通知类型">
  117. <Select
  118. allowClear
  119. >
  120. {msgTypeList.map((item) => {
  121. return (
  122. <Option value={item.name} key={item.name}>{item.val}</Option>
  123. )
  124. })}
  125. </Select>
  126. </Form.Item>
  127. </Col>
  128. <Col span={5} key={2}>
  129. <Form.Item name="status" label="阅读状态">
  130. <Select
  131. allowClear
  132. >
  133. {msgStatusList.map((item) => {
  134. return (
  135. <Option value={item.name} key={item.name}>{item.val}</Option>
  136. )
  137. })}
  138. </Select>
  139. </Form.Item>
  140. </Col>
  141. <Col span={9} key={3}>
  142. <Form.Item>
  143. <Button type="primary" htmlType="submit">
  144. 查询
  145. </Button>
  146. <Button htmlType="button" onClick={onReset}>
  147. 重置
  148. </Button>
  149. </Form.Item>
  150. </Col>
  151. </Row>
  152. </Form>
  153. </div>
  154. <div className="table">
  155. <div className="table-header">
  156. <h2 className="table-title">我的通知</h2>
  157. </div>
  158. <RenderTable />
  159. </div>
  160. <Modal
  161. title="查看通知"
  162. footer={null}
  163. width={724}
  164. visible={visible}
  165. confirmLoading={confirmLoading}
  166. onCancel={()=>setVisible(false)}
  167. >
  168. <div className="message-box">
  169. <p className='msg-title'>{msgDetail.title}</p>
  170. <div className="msg-content">{msgDetail.content}</div>
  171. <div className="msg-footer">
  172. <span className="msg-type">类型:{msgDetail.typeName}</span>
  173. <span className="msg-sender">发送者:{msgDetail.creatorName}</span>
  174. <span className="msg-time">发送时间:{msgDetail.gmtCreate}</span>
  175. </div>
  176. </div>
  177. <p className='message-oper'><Button type='primary' onClick={handleCancel}>返回</Button></p>
  178. </Modal>
  179. </div>
  180. )
  181. }
  182. export default MyMessage;