import React, { Component } from 'react';
import { Modal, message } from 'antd';
import ColumnAuthoritys from './ColumnAuthoritys'
import { $http } from '../../containers/config/https';

import './CSS/index.less';

let userData;
class ColumnAuthoritysModel extends Component {
    constructor(props) {
        userData = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        super(props);
        this.state = {
            visible: false,
        };
    }
    componentDidMount() {
        if (this.props.onRef) {
            this.props.onRef(this);
        }
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }

    UNSAFE_componentWillReceiveProps(nextProps) {
        if (nextProps.visible) {
            message.warn("请按照\"列权限维护组件调用修改\" 文档进行修改");
        }
    }
    // 获取编辑权限
    getEditAuth = () => {
        let data = { params: [{}] };
        $http.post('urlDeault', this, {
            code: "01040094",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    if (res.result.editFlag == "Y") {

                        this.setState({
                            visible: true,
                        }, () => {
                            if (this.child) {
                                this.child.reloadData();
                            }
                        })
                    } else {
                        this.setState({
                            visible: false,
                        });

                        message.warn(userData.language == "EN" ? "No Authoritys" : "暂无编辑权限！");
                    }
                } else {
                    this.setState({
                        visible: false,
                    });
                    message.warn(userData.language == "EN" ? "No Authoritys" : "暂无编辑权限！");
                }
            }
        });
    }
    //打开组件权限编辑组件
    onOpenModel = () => {
        this.getEditAuth();
    }
    //关闭组件权限编辑组件
    onCloseModel = () => {
        this.setState({
            visible: false
        }, () => {
            this.props.reloadData();
        })
    }
    onRef = (ref) => {
        this.child = ref;
    }
    render() {
        let title=userData.language == "EN" ? "ComponentConfig"+""+" ("+this.props.compontName+")" : "组件信息维护"+" ("+this.props.compontName+")" ; 
        return (
            <Modal
                className="authority"
                title={title}
                width='800px'
                onCancel={() => {
                    this.setState({
                        visible: false,
                    })
                }}
                onOk={this.onCloseModel}
                visible={this.state.visible}
                footer={null}
                style={{
                    overflow: 'hidden',
                    paddingBottom: '108px',
                    height: '700px',
                }}>
                <ColumnAuthoritys onRef={this.onRef} onCancel={this.onCloseModel} visible={this.state.visible} compontName={this.props.compontName} configType={this.props.configType} />
            </Modal>
        );
    }
}

export default ColumnAuthoritysModel;