app-base-web
Version:
web development common base package.
242 lines (237 loc) • 6.45 kB
JavaScript
import React, {Suspense, lazy} from 'react'
import {Table, Row, Col, Button, Input, message} from 'antd'
import api from '../../../library/util-axios'
import UtilModal from '../../../library/util-modal'
import UtilDate from '../../../library/util-date'
import Attachment from '../../../library/attachment'
// 业务管理-业务咨询
const title = "业务咨询"
const url = "Advisory/"
const StateReply = {
"0": "未回复",
"1": "已回复"
}
const FormEdit = lazy(() => import('./AdvisoryEdit'))
export default class AdvisoryList extends React.Component {
constructor(props) {
super(props)
this.state = {
params: {},
data: [],
pagination: {},
loading: false,
selected: [],//Table checked
height: 0,
//显藏控制
showView: false,
showEdit: false,
//values
values: {},
}
this.columns = [{
title: "会员名称",
dataIndex: "userName",
width: 100,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onEdit(record)}>{text}</a>)
},
{
title: "专家名称",
dataIndex: "expertName",
width: 100,
render: (text, record) => (<a className="btn-detail" onClick={() => this.onEdit(record)}>{text}</a>)
},
{
title: "回复状态",
dataIndex: "reply",
width: 100,
render: (text, record) => {
return StateReply[text]
}
},
{
title: "预约时间",
dataIndex: "reservationTime",
width: 100,
render: (text, record) => {
return UtilDate.getDate(text)
}
},
{
title: "主题",
dataIndex: "subject",
width: 100
},
{
title: "专利号",
dataIndex: "ano",
width: 100
},
{
title: "图片地址",
dataIndex: "fileUrl",
width: 100,
ellipsis: true,
render: (text, record) => {
return <Attachment type="img" style={{height: "40px", width: "40px"}} url={text}/>
}
},
{
title: "内容",
dataIndex: "content",
width: 100,
ellipsis: true
},
{
title: "专家回复时间",
dataIndex: "replyTime",
width: 100,
render: (text, record) => {
return UtilDate.getDateTime(text)
}
},
{
title: "回复内容",
dataIndex: "replyContent",
width: 100,
ellipsis: true
}]
}
componentDidMount() {
this.onLoad(this.state.params)
}
/*** Table ***/
async onLoad(params) {
this.setState({loading: true})
let rs = await api.get(url + "getList", params)
console.log('rs',rs)
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,
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.userName = value
this.onLoad(params)
}
onAdd = () => {
let values = {}
Object.keys(this.state.values).forEach(key => values[key] = undefined)
this.setState({
showView: false,
showEdit: true,
values
})
}
onEdit = (values) => {
let me = this;
api.get(url + "getModel?id=" + values.id, {}, function (rs) {
me.setState({
showEdit: true,
showView: false,
values: rs.data
});
});
}
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); }
});
}
})
}
onSave = (values) => {
this.onLoad(this.state.params);
}
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.showEdit ? "hide" : ""}>
<Row>
<Col className="main-title" ><i className="iconfont icon-title"></i>{title}</Col>
</Row>
<Row className="main-toolbar">
<Col xs={12}>
<Button className="btn-del" onClick={this.onDel}><i className="iconfont icon-del"></i>删除</Button>
</Col>
<Col className="query-filed" xs={12}>
<Input.Search placeholder="请输入会员名称" onSearch={value => this.onSearch(value.trim())} enterButton />
</Col>
</Row>
<Table {...tableCfg} />
</div>
<Suspense fallback={<div></div>}>
{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>
)
}
}