UNPKG

app-base-web

Version:
248 lines (245 loc) 8.54 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 = "MsgShort/"; const FormView = lazy(() => import('./MsgShortView')); const FormEdit = lazy(() => import('./MsgShortEdit')); export default class MsgShortList extends React.Component { constructor(props) { super(props); this.state = { params: { receiveMobile: "" }, 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: "sendMobile", width: 100 }, { title: "接收人", dataIndex: "receiver", width: 100 }, { title: "接收手机号", dataIndex: "receiveMobile", width: 100 }, { title: "内容", dataIndex: "content", width: 300 }, { 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={9}> <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={5}> <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={5}> <Input placeholder="请输入接收手机号码" onChange={event => { let params = this.state.params; params.receiveMobile = event.target.value; this.setState({ params }); }} /> </Col> <Col className="query-filed" xs={5}> <Input.Search placeholder="请输入名称" onSearch={(value) => { this.onSearch({ name: 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>; } }