UNPKG

app-base-web

Version:
269 lines (265 loc) 9.58 kB
import React, { Suspense, lazy } from 'react'; import { Table, Row, Col, Button, Input, message } from 'antd'; import api from '../../../library/util-axios'; import UtilDic from '../../../library/util-dic'; import UtilModal from '../../../library/util-modal'; import RadioGroup from '../../../library/radio-group'; // 信息管理-邮件管理 const title = "邮件管理"; const url = "MsgEmail/"; const FormView = lazy(() => import('./MsgEmailView')); const FormEdit = lazy(() => import('./MsgEmailEdit')); export default class MsgEmailList 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: "序号", width: 50, fixed: "left", render: (text, record, index) => { return index + 1 } // }, { // title: "业务ID", // dataIndex: "parentId", // width: 100, // render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, { title: "业务名称", dataIndex: "parentName", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, // { // title: "发件人Id", // dataIndex: "senderId", // width: 100 // }, { title: "发件人", dataIndex: "sendEmail", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{UtilDic.json("app", "发送邮件")[text]}</a>) }, // { // title: "收件人", // dataIndex: "recipientId", // width: 100 // }, { title: "收件人", dataIndex: "receiveEmail", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, { title: "抄送", dataIndex: "cc", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, { title: "标题", dataIndex: "title", width: 150, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, // { // title: "内容", // dataIndex: "content", // width: 300 // }, // { // title: "附件", // dataIndex: "file", // width: 100 // }, { title: "发送时间", dataIndex: "sendTime", width: 100 }, // { // title: "发送码", // dataIndex: "code", // width: 100 // }, { title: "发送结果", dataIndex: "sendResult", width: 100 }, { title: "邮件状态", dataIndex: "state", width: 100, render: (text, record) => { return UtilDic.json("app", "邮件状态")[text] } }]; } 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 = (values) => { let params = { ...this.state.params, ...values } 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); } }); } }) } 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 xs={8}> <Button className="btn-add" onClick={this.onAdd}><i className="iconfont icon-add"></i>手动发送</Button> <Button className="btn-del" onClick={this.onDel}><i className="iconfont icon-del"></i>删除</Button> </Col> <Col className="query-filed" xs={4}> <Input placeholder="发送邮件地址" onChange={event => { let params = this.state.params; params.sendEmail = event.target.value; this.setState({ params }); }} /> </Col> <Col className="query-filed" xs={4}> <Input placeholder="接收邮件地址" onChange={event => { let params = this.state.params; params.receiveEmail = event.target.value; this.setState({ params }); }} /> </Col> <Col className="query-filed" xs={4}> <RadioGroup value={this.state.params.state} dic={{ app: "app", type: "邮件状态" }} type="button" onChange={(e) => { this.onSearch({ state: e.target.value }); }} /> </Col> <Col className="query-filed" xs={4}> <Input.Search placeholder="请输入邮件标题" onSearch={(value) => { this.onSearch({ title: 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>; } }