/**
|
* 徐祥健<xuxj@hugeinfo.com.cn>
|
* 2018年8月28日 10:41
|
*
|
*/
|
|
|
import React from 'react';
|
|
import HeadView from '../view/HeadView';
|
import TableBtnView from '../view/TableBtnView';
|
import { Input, Button, DatePicker, Divider, Modal, message } from 'antd'
|
import moment from 'moment'
|
import Fetch from '../fetch';
|
import TableView from '../view/TableView';
|
const confirm = Modal.confirm;
|
export default class Company extends React.Component {
|
constructor(props) {
|
super(props);
|
this.state = {
|
data: [],
|
loading: false,
|
visible: false,
|
savedate: {},
|
formdata: {},
|
resetKey: Date.now(),
|
closeKey: Date.now()
|
};
|
}
|
|
componentDidMount() {
|
document.title = '自贸区公司';
|
this.getData();
|
}
|
getData = () => {
|
const { formdata } = this.state;
|
Fetch.getCompanyList(formdata)
|
.then(res => {
|
for (var i = 0; i < res.length; i++) {
|
res[i]['index'] = i + 1;
|
}
|
this.setState({
|
data: res
|
});
|
});
|
}
|
onInputChange = ({ target: { value, name } }) => {
|
this.setState(({ formdata }) => ({
|
formdata: {
|
...formdata,
|
[name]: value
|
}
|
}))
|
}
|
saveInputChange = ({ target: { value, name } }) => {
|
this.setState(({ savedate }) => ({
|
savedate: {
|
...savedate,
|
[name]: value
|
}
|
}))
|
}
|
Seaech = () => {
|
const { formdata } = this.state;
|
Fetch.getCompanyList(formdata)
|
.then(res => {
|
for (var i = 0; i < res.length; i++) {
|
res[i]['index'] = i + 1;
|
}
|
this.setState({
|
data: res
|
});
|
});
|
}
|
Reset = () => {
|
this.setState({
|
resetKey: Date.now(),
|
formdata: {}
|
}, this.getData);
|
}
|
|
showModal = (id) => {
|
this.setState({
|
visible: true,
|
});
|
Fetch.getCompanyDetail(id)
|
.then(res => {
|
this.setState({ savedate: res })
|
})
|
}
|
|
handleOk = () => {
|
this.setState({ loading: true });
|
const { savedate } = this.state;
|
if (savedate.companyTel) {
|
if (!validator.mobile(savedate.companyTel)) {
|
this.setState({
|
loading: false
|
});
|
return message.warning("电话号码格式不正确");
|
}
|
}
|
if (!savedate.companyAccount) {
|
return message.warning("账号不能为空");
|
}
|
if (!savedate.companyPassword) {
|
return message.warning("密码不能为控");
|
}
|
Fetch.saveCompany(savedate)
|
.then(res => {
|
if (res.statuscode === 1) {
|
this.setState({
|
loading: false,
|
visible: false,
|
closeKey: Date.now()
|
}, this.getData);
|
message.success("提交成功!")
|
} else {
|
message.error('保存失败,请联系管理员', 2)
|
}
|
});
|
}
|
|
handleCancel = () => {
|
this.setState({
|
closeKey: Date.now(),
|
visible: false
|
});
|
}
|
|
deleteItems = (id) => {
|
confirm({
|
title: '确认要删除这条数据吗?',
|
onOk: () => {
|
Fetch.deleteCompany(id)
|
.then(data => {
|
if (data.statuscode == 1) {
|
message.success("删除成功!")
|
this.setState({
|
resetKey: Date.now(),
|
formdata: {}
|
}, this.getData);
|
} else {
|
message.error('删除失败,请联系管理员', 2)
|
}
|
})
|
}
|
});
|
}
|
render() {
|
const columns = [{
|
title: '序号',
|
dataIndex: 'index',
|
key: 'index'
|
}, {
|
title: '公司名称',
|
dataIndex: 'companyName',
|
key: 'companyName'
|
}, {
|
title: '法人姓名',
|
dataIndex: 'companyLegal',
|
key: 'companyLegal',
|
}, {
|
title: '联系电话',
|
dataIndex: 'companyTel',
|
key: 'companyTel',
|
}, {
|
title: '公司地址',
|
dataIndex: 'companyAddress',
|
key: 'companyAddress',
|
}, {
|
title: '管理员账号',
|
dataIndex: 'companyAccount',
|
key: 'companyAccount',
|
}, {
|
title: '管理员密码',
|
dataIndex: 'companyPassword',
|
key: 'companyPassword',
|
render: text => <span>***********</span>
|
}, {
|
title: '创建时间',
|
dataIndex: 'createTime',
|
key: 'createTime',
|
render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
|
}, {
|
title: '操作',
|
key: 'action',
|
render: (text, record) => (
|
<span>
|
<label onClick={() => this.showModal(record.id)} className='theme-color' style={{ cursor: 'pointer' }}>编辑</label>
|
<Divider type="vertical" />
|
<label onClick={() => this.deleteItems(record.id)} className='theme-color' style={{ cursor: 'pointer' }}>删除</label>
|
</span>
|
),
|
}];
|
const { data, resetKey, visible, loading, savedate, closeKey } = this.state;
|
return (
|
|
<div className="app-page">
|
<HeadView history={this.props.history} />
|
<TableBtnView key={-resetKey} type="infoManage" name='自贸区公司信息库' btnName='新建公司' onClick={() => this.showModal('new')}>
|
<Input placeholder="根据公司名称模糊查询" style={{ width: "200px" }} name='companyName' onChange={this.onInputChange} />
|
<Input placeholder="根据法人姓名模糊查询" style={{ width: "200px" }} name='companyLegal' onChange={this.onInputChange} />
|
<Input placeholder="根据联系电话模糊查询" style={{ width: "200px" }} name='companyTel' onChange={this.onInputChange} />
|
<Input placeholder="根据管理员账号模糊查询" style={{ width: "200px" }} name='companyAccount' onChange={this.onInputChange} />
|
<DatePicker onChange={(_, value) => this.onInputChange({ target: { name: 'createTime', value } })} placeholder="根据创建时间查询" />
|
<Button type="primary" onClick={this.Seaech}>查询</Button>
|
<Button onClick={this.Reset}>重置</Button>
|
</TableBtnView>
|
<TableView columns={columns} data={data} pageSize='10' size='default' />
|
<Modal
|
key={closeKey}
|
confirmLoading={loading}
|
visible={visible}
|
title="公司信息"
|
onOk={this.handleOk}
|
onCancel={this.handleCancel}
|
bodyStyle={{ lineHeight: 4 }}
|
>
|
<Input addonBefore="公司名称" name='companyName' onChange={this.saveInputChange} value={savedate.companyName || ''} />
|
<Input addonBefore="法人姓名" name='companyLegal' onChange={this.saveInputChange} value={savedate.companyLegal || ''} />
|
<Input addonBefore="联系电话" name='companyTel' onChange={this.saveInputChange} value={savedate.companyTel || ''} />
|
<Input addonBefore="公司地址" name='companyAddress' onChange={this.saveInputChange} value={savedate.companyAddress || ''} />
|
<Input addonBefore="管理员账号" name='companyAccount' onChange={this.saveInputChange} value={savedate.companyAccount || ''} />
|
<Input addonBefore="管理员密码" name='companyPassword' onChange={this.saveInputChange} value={savedate.companyPassword || ''} />
|
</Modal>
|
</div>
|
);
|
}
|
|
}
|