spug/spug_web/src/pages/alarm/contact/Table.js

94 lines
2.4 KiB
JavaScript

/**
* Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
* Copyright (c) <spug.dev@gmail.com>
* Released under the AGPL-3.0 License.
*/
import React from 'react';
import { observer } from 'mobx-react';
import { Table, Modal, message } from 'antd';
import ComForm from './Form';
import {http, hasPermission} from 'libs';
import store from './store';
import { Action } from "components";
@observer
class ComTable extends React.Component {
componentDidMount() {
store.fetchRecords()
}
columns = [{
title: '序号',
key: 'series',
render: (_, __, index) => index + 1,
width: 80,
}, {
title: '姓名',
dataIndex: 'name',
}, {
title: '手机号',
dataIndex: 'phone',
}, {
title: '邮箱',
dataIndex: 'email',
ellipsis: true
}, {
title: '钉钉',
dataIndex: 'ding',
ellipsis: true
}, {
title: '企业微信',
dataIndex: 'qy_wx',
ellipsis: true
}, {
title: '操作',
className: hasPermission('alarm.contact.edit|alarm.contact.del') ? null : 'none',
render: info => (
<Action>
<Action.Button auth="alarm.contact.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
<Action.Button auth="alarm.contact.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
</Action>
)
}];
handleDelete = (text) => {
Modal.confirm({
title: '删除确认',
content: `确定要删除【${text['name']}】?`,
onOk: () => {
return http.delete('/api/alarm/contact/', {params: {id: text.id}})
.then(() => {
message.success('删除成功');
store.fetchRecords()
})
}
})
};
render() {
let data = store.records;
if (store.f_name) {
data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
}
return (
<React.Fragment>
<Table
rowKey="id"
loading={store.isFetching}
dataSource={data}
pagination={{
showSizeChanger: true,
showLessItems: true,
hideOnSinglePage: true,
showTotal: total => `${total}`,
pageSizeOptions: ['10', '20', '50', '100']
}}
columns={this.columns}/>
{store.formVisible && <ComForm/>}
</React.Fragment>
)
}
}
export default ComTable