123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import React from 'react';
- import { Table, Button, Spin, message, Popconfirm, Icon } from 'antd';
- import ajax from 'jquery/src/ajax/xhr.js'
- import $ from 'jquery/src/ajax';
- import TheModal from './modal.jsx';
- const Member = React.createClass({
- loadData(pageNo) {
- this.state.data = [];
- this.setState({
- loading: true
- });
- return $.ajax({
- type: 'get',
- cache: false,
- url: globalConfig.context + "/api/admin/adminList",
- dataType: "json",
- data: {
- pageNo: pageNo || 1,
- pageSize: this.state.pagination.pageSize
- },
- success: function (data) {
- if (!data.data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- return;
- };
- for (let i = 0; i < data.data.list.length; i++) {
- let thisdata = data.data.list[i];
- this.state.data.push({
- key: i,
- id: thisdata.id,
- mobile: thisdata.mobile,
- name: thisdata.name,
- email: thisdata.email,
- createTime: thisdata.createTime,
- number: thisdata.number,
- province: thisdata.province,
- createTimeFormattedDate: thisdata.createTimeFormattedDate
- });
- };
- this.state.pagination.current = data.data.pageNo;
- this.state.pagination.total = data.data.totalCount;
- this.setState({
- data: this.state.data,
- pagination: this.state.pagination
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getInitialState() {
- return {
- data: [],
- dataSource: [],
- selectedRowKeys: [],
- selectedRows: [],
- loading: false,
- modalData: {},
- modalShow: false,
- pagination: {
- defaultCurrent: 1,
- defaultPageSize: 10,
- showQuickJumper: true,
- pageSize: 10,
- onChange: function (page) {
- this.loadData(page);
- }.bind(this),
- showTotal: function (total) {
- return '共' + total + '条数据';
- }
- }
- }
- },
- componentDidMount() {
- this.loadData();
- },
- addNew() {
- let e = {}
- this.setState({
- modalData: e,
- modalShow: true
- })
- },
- edit(e) {
- this.setState({
- modalData: e,
- modalShow: true
- })
- },
- handleReturn(show, render) {
- this.state.modalShow = show;
- if (render) {
- this.loadData();
- }
- },
- resetPwd(e) {
- this.setState({
- loading: true
- })
- $.ajax({
- type: 'post',
- url: globalConfig.context + "/api/admin/resetPwd",
- dataType: "json",
- data: {
- id: e.id
- }
- }).done((res) => {
- if (res.error.length) {
- message.error(res.error[0].message);
- } else {
- message.success("密码重置成功");
- }
- }).always(() => {
- this.setState({
- loading: false
- })
- });
- },
- render() {
- const columns = [{
- title: '编号',
- dataIndex: 'number',
- key: 'number'
- }, {
- title: '登录账号',
- dataIndex: 'mobile',
- key: 'mobile'
- }, {
- title: '名字',
- dataIndex: 'name',
- key: 'name'
- }, {
- title: '省份',
- dataIndex: 'province',
- key: 'province'
- }, {
- title: '邮箱',
- dataIndex: 'email',
- key: 'email'
- }, {
- title: '创建时间',
- dataIndex: 'createTimeFormattedDate',
- key: 'createTimeFormattedDate'
- }, {
- title: '操作',
- dataIndex: 'act',
- key: 'act',
- render: (text, record, index) => {
- return <Popconfirm title={"用户" + record.name + "的密码将会重置为123456,确认操作?"} onConfirm={this.resetPwd.bind(null, record)} okText="确认" cancelText="取消" placement="topRight">
- <Button>重置密码</Button>
- </Popconfirm>
- },
- width: '15%'
- //onCellClick: () => { return; }
- }];
- return (
- <Spin spinning={this.state.loading}>
- <div className="set-content">
- <div className="set-title">
- <span>管理员设置</span>
- <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
- onClick={this.addNew}>添加<Icon type="plus" /></Button>
- </div>
- <TheModal data={this.state.modalData} show={this.state.modalShow} handleReturn={this.handleReturn} />
- <Table className='member-table'
- columns={columns}
- onRowClick={this.edit}
- dataSource={this.state.data}
- pagination={this.state.pagination} />
- </div>
- </Spin>
- );
- }
- });
- export default Member;
|