index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 AddNewMsg from './AddNewMsg.js';
  6. import './index.less';
  7. import apiObj from '@api/index';
  8. import utils from '@utils/index'
  9. const { pickCheckedTreeIds } = utils;
  10. const { post, api, xPost } = apiObj;
  11. const { Option } = Select;
  12. function MsgManage() {
  13. useEffect(() => {
  14. //刷新列表
  15. getTableData();
  16. }, []);
  17. const [isAdd,setIsAdd] = useState(false); //是否是新增页面
  18. const [current, setCurrent] = useState(1); //当前页
  19. const [size, setSize] = useState(15); //每页显示条数
  20. const [total, setTotal] = useState(0); //消息总数
  21. const [dataSource, setDataSource] = useState([]); //列表数据
  22. const [visible, setVisible] = useState(false); //弹窗查看
  23. const [delVisible, setDelVisible] = useState(false); //弹窗删除
  24. const [delId,setDelId] = useState(''); //要删除的通知id
  25. const [confirmLoading, setConfirmLoading] = useState(false);
  26. const [msgDetail, setMsgDetail] = useState({});
  27. //从state中取出状态、类型列表
  28. const staticInfo = useSelector(state => {
  29. return state.staticInfo;
  30. });
  31. const { msgTypeList, msgStatusList } = staticInfo;
  32. //获取表格数据
  33. function getTableData(param = {}) {
  34. post(api.listManagePage, param).then((res) => {
  35. if (res.data.code === 200) {
  36. let data = res.data.data;
  37. setTotal(data.total);
  38. setDataSource(data.records);
  39. }
  40. })
  41. }
  42. //弹窗取消
  43. function handleCancel() {
  44. setVisible(false);
  45. }
  46. //新增子组织弹窗
  47. function showMessage(id) {
  48. getMsgDetail(id);
  49. setVisible(true);
  50. }
  51. //删除消息
  52. function delMessage(id){
  53. setDelVisible(true);
  54. setDelId(id);
  55. }
  56. //删除通知
  57. function postDelMsg() {
  58. xPost(api.deleteNoticeInfo, { id: delId}).then((res) => {
  59. const { code } = res.data;
  60. if (code === 200) {
  61. getTableData(); //刷新列表
  62. setDelVisible(false);
  63. message.success(res.data.msg || '删除成功')
  64. } else {
  65. message.warning(res.data.msg || '删除失败,请重试')
  66. }
  67. });
  68. }
  69. //获取通知详情
  70. function getMsgDetail(id) { //type:1我的通知,0通知管理
  71. xPost(api.getNoticeInfoById, { id: id, type: 0 }).then((res) => {
  72. const { data, code } = res.data;
  73. if (code === 200) {
  74. setMsgDetail(data);
  75. } else {
  76. message.warning(res.data.msg || '获取详情失败')
  77. }
  78. });
  79. }
  80. //每页显示条数切换
  81. function onSizeChange(){
  82. const values = form.getFieldsValue();
  83. const params = {...values,current,size};
  84. setCurrent(current);
  85. getTableData(params);
  86. }
  87. //翻页
  88. function onPageChange(current){
  89. const values = form.getFieldsValue();
  90. const params = {...values,current,size};
  91. setCurrent(current);
  92. getTableData(params);
  93. }
  94. //新增通知
  95. function showAddMsg(flag){
  96. setIsAdd(flag);
  97. }
  98. //表格渲染
  99. function RenderTable() {
  100. const columns = [
  101. { title: '标题', dataIndex: 'title', key: 'title' },
  102. {
  103. title: '类型', width: 150, dataIndex: 'typeName', key:'typeName'
  104. },
  105. { title: '发送者', dataIndex: 'sender', key: 'sender' },
  106. { title: '发送时间', width: 240, dataIndex: 'gmtCreate', key: 'gmtCreate' },
  107. {
  108. title: '操作', key: 'operation', render: (row) => {
  109. return (<Space size="middle">
  110. <a onClick={() => showMessage(row.id)}>查看</a>
  111. <a className='delete' onClick={() => delMessage(row.id)}>删除</a>
  112. </Space>)
  113. }
  114. },
  115. ];
  116. return (
  117. <Table
  118. rowKey={record => record.id}
  119. scroll={{ y: 'calc(100vh - 320px)' }}
  120. columns={columns}
  121. dataSource={dataSource}
  122. pagination={{
  123. showSizeChanger:true,
  124. pageSizeOptions:[15,30,60,120],
  125. defaultPageSize:size,
  126. current: current,
  127. pageSize:size,
  128. size:'small',
  129. total: total,
  130. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  131. onChange:onPageChange,
  132. }}
  133. />
  134. )
  135. }
  136. //筛选项渲染
  137. const [form] = Form.useForm();
  138. const onFinish = (values: any) => {
  139. getTableData(values);
  140. console.log('筛选项:', values);
  141. };
  142. const onReset = () => {
  143. form.resetFields();
  144. getTableData();
  145. };
  146. if(isAdd){
  147. return (<AddNewMsg goBack={() => showAddMsg(false)}></AddNewMsg>);
  148. }
  149. return (
  150. <div className='wrapper'>
  151. <div className="filter-box">
  152. <Form form={form} name="control-hooks" onFinish={onFinish}>
  153. <Row gutter={24}>
  154. <Col span={5} key={1}>
  155. <Form.Item name="type" label="通知类型">
  156. <Select
  157. allowClear
  158. >
  159. {msgTypeList.map((item) => {
  160. return (
  161. <Option value={item.name} key={item.name}>{item.val}</Option>
  162. )
  163. })}
  164. </Select>
  165. </Form.Item>
  166. </Col>
  167. <Col span={9} key={3}>
  168. <Form.Item>
  169. <Button type="primary" htmlType="submit">
  170. 查询
  171. </Button>
  172. <Button htmlType="button" onClick={onReset}>
  173. 重置
  174. </Button>
  175. </Form.Item>
  176. </Col>
  177. </Row>
  178. </Form>
  179. </div>
  180. <div className="table">
  181. <div className="table-header">
  182. <h2 className="table-title">通知管理</h2>
  183. <Button type="primary" icon={<PlusOutlined />} onClick={() => showAddMsg(true)}>新增通知</Button>
  184. </div>
  185. <RenderTable />
  186. </div>
  187. <Modal
  188. title="查看通知"
  189. footer={null}
  190. width={724}
  191. visible={visible}
  192. onCancel={()=>setVisible(false)}
  193. confirmLoading={confirmLoading}
  194. >
  195. <div className="message-box">
  196. <p className='msg-title'>{msgDetail.title}</p>
  197. <div className="msg-content">{msgDetail.content}</div>
  198. <div className="msg-footer">
  199. <span className="msg-type">类型:{msgDetail.typeName}</span>
  200. <span className="msg-sender">发送者:{msgDetail.creatorName}</span>
  201. <span className="msg-time">发送时间:{msgDetail.gmtCreate}</span>
  202. </div>
  203. </div>
  204. <p className='message-oper'><Button type='primary' onClick={handleCancel}>返回</Button></p>
  205. </Modal>
  206. <Modal
  207. title="删除通知"
  208. width={400}
  209. visible={delVisible}
  210. okText='确定'
  211. cancelText='取消'
  212. onOk={postDelMsg}
  213. onCancel={()=>setDelVisible(false)}
  214. confirmLoading={confirmLoading}
  215. >
  216. <p>确定要删除这条通知吗?</p>
  217. </Modal>
  218. </div>
  219. )
  220. }
  221. export default MsgManage;