import React from 'react'; import { Modal, Input, Spin, Switch, Select, message, Popconfirm, Button } from 'antd'; import { provinceArr } from '../../dataDic.js'; import { companySearch } from '../../tools.js'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; export default class TheModal extends React.Component { postData() { this.setState({ loading: true }); $.ajax({ type: "POST", url: this.state.id ? globalConfig.context + "/api/admin/updateAdmin" : globalConfig.context + "/api/admin/insertAdmin", data: { 'id': this.state.id, 'name': this.state.name, 'position': this.state.position, 'email': this.state.email, 'mobile': this.state.mobile, 'province': this.state.province, 'roles': this.state.bindroles } }).done((res) => { if (res.error.length) { message.error(res.error[0].message); } else { message.success("保存成功"); this.setState({ visible: false, }); this.props.handleReturn(false, true); //第二个参数表示保存 } }).always(() => { this.setState({ loading: false }) }) this.props.postData; } constructor(props) { super(props); this.state = { name: '', position: '', email: '', mobile: '', roles: [], visible: false, loading: false, provinceOption: [], bindroles: [] } } handleCancel() { this.setState({ visible: false, }); this.props.handleReturn(false, false); } componentWillMount() { let _me = this; provinceArr.map(function (item) { _me.state.provinceOption.push( {item} ) }); } loadInitialData() { this.setState({ loading: true }); $.ajax({ url: globalConfig.context + '/api/roles', cache: false }).done((rolesres) => { this.setState({ roles: rolesres.data, loading: false }); }) } loadBindRoles(uid) { this.setState({ loading: true }); $.ajax({ url: globalConfig.context + '/api/admin/role', cache: false, data: { "uid": uid } }).done((data) => { this.setState({ bindroles: data.data || [], loading: false }); }) } componentWillReceiveProps(nextProps) { if (nextProps.show && !this.state.roles.length) { this.loadInitialData(); }; if (!this.state.visible && nextProps.show) { this.loadBindRoles(nextProps.data.id); }; let nextState = { visible: nextProps.show, id: nextProps.data ? nextProps.data.id : '', name: nextProps.data ? nextProps.data.name : '', position: nextProps.data ? nextProps.data.position : '', email: nextProps.data ? nextProps.data.email : '', mobile: nextProps.data ? nextProps.data.mobile : '', province: nextProps.data ? nextProps.data.province : '' }; this.setState(nextState) } resetPwd(e) { this.setState({ loading: true }) $.ajax({ type: 'post', url: globalConfig.context + "/api/admin/resetPwd", dataType: "json", data: { id: this.state.id } }).done((res) => { if (res.error && res.error.length) { message.error(res.error[0].message); } else { message.success("密码重置成功"); } }).always(() => { this.setState({ loading: false }) }); } getRolesSelection() { if (!this.state.id) { return
  • } else if (this.state.id != '1') { return
  • 角色
  • } else if (this.state.id == "1") { return
  • 角色系统管理员
  • } } getProvinceSelection() { if (window.showPermissionList && window.showRoleList) { return
  • 省份
  • } else { return
  • 省份
  • } } bindRoles(val) { this.setState({ bindroles: val }); } getRolesOptions() { let options = []; for (let i = 0; i < this.state.roles.length; i++) { options.push({this.state.roles[i].roleName}); } return options; } render() { return (
    • 名字 { this.state.name = e.target.value; this.setState({ name: this.state.name }); }} />
    • 职位 { this.state.position = e.target.value; this.setState({ position: this.state.position }); }} />
    • s
    • 登录账号 { this.state.mobile = e.target.value; this.setState({ mobile: this.state.mobile }); }} />
    • {this.getProvinceSelection()}
    • 邮箱 { this.state.email = e.target.value; this.setState({ email: this.state.email }); }} />
    • {this.getRolesSelection()}
    • {this.state.id ? : }
    ); } }