import React from 'react'; import { Icon, Table, Modal, message, Spin, Input, Select, Button, Form } from 'antd'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import './userMangagement.less'; import {} from '../../../dataDic.js'; const Newrole = Form.create()(React.createClass({ addloadData() { this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/customer/listAllPersonalCustomer', data: { pageNo: 1, pageSize: 10, }, success: function(data) { let theArr = []; if(!data.data || !data.data.list) { if(data.error && data.error.length) { message.warning(data.error[0].message); }; } else { for(let i = 0; i < data.data.list.length; i++) { let thisdata = data.data.list[i]; let nub = Math.floor(Math.random() * 100000); theArr.push({ key: 'AM' + nub, id: 'nub' + i + 'b', name: '成果录入' + i, Interface: 'api/admin/customer' + i, children: [{ key: 'BM' + nub, id: 'nub' + i + 'b' + i, name: '成果录入' + i + i, Interface: 'api/admin/customer' + i + i + i, }, { key: 'BM' + nub + i, id: 'nub' + i + 'c' + i, name: '成果录入' + i + i, Interface: 'api/admin/customer' + i + i + i, } ] }); }; }; this.setState({ Interface: theArr, }); }.bind(this), }).always(function() { this.setState({ loading: false }); }.bind(this)); }, getInitialState() { return { orgCodeUrl: [], loading: false, visible: false, addColumns: [{ title: '选择角色权限', dataIndex: 'name', key: 'name', }, { title: '', dataIndex: 'Interface', key: 'Interface', }], }; }, handleSubmit(e) { e.preventDefault(); //let api=this.props.userDetaile?'保存':'新建'; this.props.form.validateFields((err, values) => { let idsArr = this.state.selectedRowst || []; let prekeys = this.state.selectedRowKeyst; let Interfaces = this.state.Interface; let ineIds = []; let ids = []; if(idsArr.length) { idsArr.map(function(index) { ids.push( index.id ) if(idsArr.children) { idsArr.children.map(function(item) { ids.push( item.id ) }) } }) } else { prekeys.map(function(item) { ineIds.push(Interfaces[item].id) }); } if(!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/customer/addCustomer', data: { roleName: this.state.roleName, id: ids.length ? JSON.stringify(ids) : JSON.stringify(ineIds) } }).done(function(data) { this.setState({ loading: false }); if(!data.error.length) { message.success('保存成功!'); this.handleCancel() } else { message.warning(data.error[0].message); } }.bind(this)); } }); }, //查看基本详情基本信息 loaduser(record) { if(record) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/customer/toUpdateBusiness', data: { businessId: record.id }, success: function(data) { let thisData = data.data; if(!thisData) { if(data.error && data.error.length) { message.warning(data.error[0].message); }; thisData = {}; }; this.setState({ detaileuser: thisData, uids: thisData.uid, //selectedRowKeyst:[0,1,2] }); }.bind(this), }).always(function() { this.setState({ loading: false }); }.bind(this)); } }, handleOk(e) { this.setState({ visible: false, }); this.props.closeDesc(false, true); }, handleCancel(e) { this.setState({ visible: false, }); this.props.closeDesc(false); }, componentWillMount() { this.addloadData() }, componentWillReceiveProps(nextProps) { //props改变时触发 this.state.visible = nextProps.showDesc; if(nextProps.userDetaile && nextProps.showDesc) { if(nextProps.datauser && nextProps.datauser.id) { this.loaduser(nextProps.datauser); } } this.setState({ selectedRowKeyst: [], datauser: {}, }) }, render() { const theData = this.state.detaileuser || {}; const FormItem = Form.Item const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, }; const rowSelection = { selectedRowKeys: this.state.selectedRowKeyst, onChange: (selectedRowKeys, selectedRows) => { this.setState({ selectedRowst: selectedRows, selectedRowKeyst: selectedRowKeys }); }, onSelect: (recordt, selected, selectedRows) => { this.setState({ recordt:recordt.id }) }, }; return(
{this.setState({roleName:e.target.value})}} style={{width:'200px'}} required="required"/> *
) } })); export default Newrole;