import React from 'react';
import ReactDom from 'react-dom';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import { Form, Radio, Icon, Button, Input, Select, Popconfirm, Spin, Table, Switch, message, DatePicker, Modal, Upload } from 'antd';
import Addjurisdiction from "./addjurisdiction.jsx"
import './userMangagement.less'
import { techAuditStatusList, station, post } from '../../../dataDic.js';
const Jurisdiction = Form.create()(React.createClass({
	loadData(pageNo) {
		this.state.data = [];
		this.setState({
			loading: true
		});
		$.ajax({
			method: "post",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/permissions',
			success: function(data) {
				if(!data.data || !data.data.one) {
					if(data.error && data.error.length) {
						message.warning(data.error[0].message);
					};
				} else {
					this.setState({
						dataSource: data.data.one,
					});
				}
			}.bind(this),
		}).always(function() {
			this.setState({
				loading: false
			});
		}.bind(this));
	},
	getInitialState() {
		return {
			datauser: {},
			selectedRowKeys: [],
			selectedRows: [],
			loading: false,
			addnextVisible: false,
			columns: [{
				title: '接口名称',
				dataIndex: 'name',
				key: 'name',
				width: '400px'
			}, {
				title: '接口路径',
				dataIndex: 'url',
				key: 'url',
			}, {
				title: '操作',
				dataIndex: 'id',
				key: 'id',
				render: (text, recard) => {
					return(
						
							
	                        {this.delectRow(recard)}}
	                                okText="确认"
	                                cancelText="取消"
	                                placement="topLeft">
	                                
	                        
                         
					)
				}
			}],
			dataSource: [],
		};
	},
	componentWillMount() {
		this.loadData();
	},
	tableRowClick(record, index) {
		this.state.userDetaile = true;
		this.state.datauser = record;
		this.setState({
			ids:record.id,
			showDesc: true
		});
	},
	//删除(已改接口)
	delectRow(ids) {
		this.setState({
			loading: true
		});
		$.ajax({
			method: "POST",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + "/api/admin/deleteById",
			data: {
				id: ids.id
			}
		}).done(function(data) {
			if(!data.error.length) {
				message.success('删除成功!');
				this.setState({
					loading: false,
				});
			} else {
				message.warning(data.error[0].message);
			};
			this.loadData();
		}.bind(this));
	},
	addClick() {
		this.state.userDetaile = false;
		this.setState({
			showDesc: true
		});
	},
	closeDesc(e, s) {
		this.state.userDetaile = false;
		this.state.showDesc = e;
		if(s) {
			this.loadData();
		};
	},
	//新建下级
	addNext() {
		this.setState({
			addnextVisible: false
		})
	},
	nextCancel() {
		this.setState({
			addnextVisible: false
		})
	},
	addNextURL(e) {
		this.state.name = '';
		this.state.url = '';
		this.setState({
			ids: e.id,
			preName: e.name,
			addnextVisible: true
		})
	},
	//新建二级接口保存
	nextSubmit() {
		this.setState({
			loading: true
		});
		$.ajax({
			method: "POST",
			dataType: "json",
			crossDomain: false,
			url: globalConfig.context + '/api/admin/addPermission',
			data: {
				superId: this.state.preName,
				name: this.state.name, //接口名称
				url: this.state.url //接口路径
			}
		}).done(function(data) {
			this.setState({
				loading: false
			});
			if(!data.error.length) {
				message.success('保存成功!');
				this.addNext();
				this.loadData();
			} else {
				message.warning(data.error[0].message);
			}
		}.bind(this));
	},
	render() {
		const FormItem = Form.Item;
		const formItemLayout = {
			labelCol: { span: 8 },
			wrapperCol: { span: 14 },
		};
		const hasSelected = this.state.selectedRowKeys.length > 0;
		return(
			
		);
	}
}));
export default Jurisdiction;