app-base-web
Version:
web development common base package.
244 lines (240 loc) • 9.66 kB
JavaScript
import React, { Suspense, lazy } from 'react';
import { Table, Form, Row, Col, DatePicker, Button, Input, message } from 'antd';
import UtilDate from '../../../library/util-date';
import UtilDic from '../../../library/util-dic';
import Dic from '../../../library/dic';
import UtilModal from '../../../library/util-modal';
import api from '../../../library/util-axios';
// 信息管理-资讯发布
const title = "资讯发布";
const url = "IssueNews/";
const FormView = lazy(() => import('./IssueNewsView'));
const FormEdit = lazy(() => import('./IssueNewsEdit'));
export default class IssueNewsList extends React.Component {
constructor(props) {
super(props);
this.state = {
params: {},
data: [],
pagination: {},
loading: false,
selected: [],//Table checked
//显藏控制
showView: false,
showEdit: false,
//values
values: {},
};
this.columns = [{
title: "发布状态",
dataIndex: "state",
width: 100,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{UtilDic.json("app", "发布状态")[text]}</a>)
}, {
title: "类型",
dataIndex: "type",
width: 80,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{UtilDic.json("system", "newsType")[text]}</a>)
},
{
title: "子类型",
dataIndex: "subType",
width: 80,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>)
},
{
title: "标题",
dataIndex: "title",
width: 300,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>)
},
{
title: "新闻时间",
dataIndex: "newsTime",
width: 100,
render: (text, record) => {
return UtilDate.getDateTime(text)
}
},
{
title: "责任编辑",
dataIndex: "editor",
width: 120
}];
}
componentDidMount() {
this.onLoad(this.state.params);
}
/*** Table ***/
async onLoad(params) {
this.setState({ loading: true });
let rs = await api.get(url + "getList", params);
let pagination = {
pageSizeOptions: ["20", "100", "200", "500", "1000"],
pageSize: params.pageSize || 20,
defaultPageSize: params.pageSize || 20,
showSizeChanger: true,
showQuickJumper: true,
total: rs.total,
showTotal: (total) => { return `总记录 ${total} ` }
};
this.setState({
loading: false,
showEdit: false,
params,
data: rs.data,
pagination
});
}
onChange = (pagination, filters, sorter) => {
let params = this.state.params;
params.pageSize = pagination.pageSize;
params.pageIndex = pagination.current;
this.onLoad(params);
}
onSearch = (value) => {
let params = this.state.params;
params.title = value;
this.onLoad(params);
}
onAdd = () => {
let values = {};
Object.keys(this.state.values).forEach(key => values[key] = undefined);
this.setState({
showView: false,
showEdit: true,
values
});
}
onView = (values) => {
this.setState({
showView: true,
loading: false,
values
});
}
onEdit = (values) => {
let me = this;
api.get(url + "getModel?id=" + values.id, {}, function (rs) {
me.setState({
showEdit: true,
showView: false,
values: rs.data
});
});
}
onSave = (values) => {
this.onLoad(this.state.params);
}
onDel = () => {
let me = this;
if (me.state.selected.length == 0) {
message.error('请选择记录!');
return;
}
UtilModal.confirm({
content: '确定删除?',
onOk: function () {
api.delete(url + "delete?id=" + me.state.selected).then(function (rs) {
if (rs.success) {
message.info(rs.msg);
me.onLoad(me.state.params || {});
} else { message.error(rs.msg); }
});
}
})
}
onAudit = (state) => {
let me = this;
if (me.state.selected.length == 0) {
message.error('请选择记录!');
return;
}
UtilModal.confirm({
title: '警告',
content: state == '2' ? '确定撤回发布?' : '确定发布?',
okText: '确认',
cancelText: '取消',
onOk: function () {
api.post(url + "setState?state=" + state + "&id=" + me.state.selected, {
}).then(function (rs) {
if (rs.success) {
message.info(rs.msg);
me.onLoad(me.state.params || {});
} else { message.error(rs.msg); }
});
}
});
}
render() {
var tableCfg = {
scroll: { y: this.props.height - 210 },
size: "middle",
rowKey: "id",
columns: this.columns,
rowSelection: {
selectedRowKeys: this.state.selected,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
selected: selectedRowKeys
});
}
},
rowClassName: (record) => { return record.id === this.state.selectedRowId ? 'row-selected' : ''; },
onRow: (record) => {
return {
onClick: event => {
this.setState({ selectedRowId: record.id });
}
}
},
dataSource: this.state.data,
pagination: this.state.pagination,
loading: this.state.loading,
onChange: this.onChange
}
return <div className="app-admin">
<div className={this.state.showView || this.state.showEdit ? "hide" : ""}>
<Row>
<Col className="main-title" ><i className="iconfont icon-title"></i>{title}</Col>
</Row>
<Row className="main-toolbar">
<Col className="text-left" xs={8}>
<Button type="primary" onClick={this.onAdd}><span className="iconfont icon-jiahao"></span><i>录入</i></Button>
<Button className="btn-del" onClick={this.onDel}><span className="iconfont icon-remove"></span><i>删除</i></Button>
<Button className="btn-pass" onClick={() => { this.onAudit(1); }}><span className="iconfont icon-insurencebg"></span><i>发布</i></Button>
<Button className="btn-revoke" onClick={() => { this.onAudit(2); }}><span className="iconfont icon-ViewOff"></span><i>撤回</i></Button>
</Col>
<Col className="text-right" style={{ paddingRight: "8px" }} xs={3} style={{ paddingRight: "8px" }}>
<Dic placeholder="请选择状态" style={{ width: "100%" }} params={{ app: "app", type: "发布状态" }} onChange={value => { let params = this.state.params; params.state = value; this.setState({ params }); this.onLoad(this.state.params); }} />
</Col>
<Col className="text-right" style={{ paddingRight: "8px" }} xs={3} style={{ paddingRight: "8px" }}>
<Dic placeholder="请选择类型" style={{ width: "100%" }} params={{ app: "system", type: "newsType" }} onChange={value => { let params = this.state.params; params.type = value; this.setState({ params }); this.onLoad(this.state.params); }} />
</Col>
<Col className="text-right" xs={3} style={{ paddingRight: "8px" }}>
<Input placeholder="请输入子类型" value={this.state.params.subType} onChange={event => { let params = this.state.params; params.subType = event.target.value; this.setState({ params }); }} />
</Col>
<Col className="text-right" xs={7}>
<Input.Search placeholder="请输入标题" onSearch={value => this.onSearch(value)} enterButton />
</Col>
</Row>
<Table {...tableCfg} />
</div>
<Suspense fallback={<div></div>}>
{this.state.showView ? <FormView
height={this.props.height - 140}
values={this.state.values}
onEdit={this.onEdit}
onReturn={() => { this.setState({ showView: false }) }}
/> : ""}
{this.state.showEdit ? <FormEdit
height={this.props.height - 140}
values={this.state.values}
onSave={this.onSave}
onCancel={() => { this.setState({ showEdit: false }) }}
onEditReturn={() => { this.setState({ showEdit: false, showView: true }) }}
/> : ""}
</Suspense>
</div>;
}
}