import React, { useRef } from 'react';
import { history } from 'umi';
import moment from 'moment';
import { Button, Popconfirm, message, Modal } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import PageTable from '@/components/PageTable';
import { getNoticeList, deleteNotice, updateNotice } from '@/services/notice';
const formatterTime = (val) => {
return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
};
export default (props) => {
const actionRef = useRef();
const gotoEdit = (id) => {
const queryStr = id ? `?id=${id}` : '';
history.push(`./notice/edit.jsx${queryStr}`);
};
const handleDelete = (id) => {
deleteNotice(id).then(() => {
message.success('删除成功');
actionRef.current.reload();
}).catch((err) => {
console.log(err.message)
});
};
//列表切换通知状态方法
const handleOK = (record, data) => {
const title = record.status
? '您确定要将该通知状态变更为未发布吗? 变更后该通知将不在移动端显示'
: '您确定要将该通知状态变更为发布吗? 发布后该通知可以在移动端显示';
Modal.confirm({
title: title,
okText: '确认',
cancelText: '取消',
onOk() {
updateNotice(record.newsId, { ...record, status: record.status === 1 ? 0 : 1 })
.then((res) => {
message.success('操作成功');
actionRef.current.reload();
})
.catch((err) => {
console.log(err.message)
});
},
});
};
const actions = () => [
} onClick={() => gotoEdit()}>
新增
,
];
const columns = [
{
title: '标题',
dataIndex: 'title',
key: 'title',
},
{
title: '权重',
dataIndex: 'weight',
key: 'weight',
search: false,
width: 100,
},
{
title: '创建时间',
dataIndex: 'createDate',
key: 'createDate',
render: formatterTime,
search: false,
width: 100,
},
{
title: '发布状态',
dataIndex: 'status',
key: 'status',
search: false,
width: 100,
render: (_, record) => {
return record.status === 1 ? '发布' : '未发布';
},
},
{
title: '操作',
valueType: 'option',
width: 240,
render: (_, record) => [
,
,
handleDelete(record.noticeId)}
okText="确定"
cancelText="取消"
>
,
],
},
];
return (
);
};