"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var _ = require("lodash");
var DynamicTree_1 = require("../../../_common/VTree/DynamicTree");
// 组织机构的选择器
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    default_1.prototype.render = function () {
        var _this = this;
        return React.createElement(DynamicTree_1.default
        // mustSelect={true}
        , { 
            // mustSelect={true}
            root: this.props.useRoot ? '/api-common/organization/root' : '/api-common/organization/rootinfo', child: "/api-common/organization/tree/", onSelect: function (node, parent) {
                if (node) {
                    _this.props.onSelect(node, parent);
                }
                else {
                    _this.props.onSelect(null);
                }
            }, childSuffix: _.has(this.props, 'businessLine') ? "/" + this.props.businessLine : '', keyField: 'code', nameField: 'name', parentField: 'parentCode', checkChild: "hasChildren" });
    };
    return default_1;
}(React.PureComponent));
exports.default = default_1;
// export default class extends React.PureComponent<TreeModalOpts> {
//     rootUrl = '';
//     businessLine = '';
//     state = {
//         treeData: [],
//     }
//     constructor(props) {
//         super(props);
//         this.rootUrl = this.props.useRoot ? '/api-common/organization/root' : '/api-common/organization/rootinfo';
//         this.businessLine = _.has(this.props, 'businessLine') ? this.props.businessLine : '';
//     }
//     async componentDidMount() {
//         let resp = await Ajax.GET(this.rootUrl);
//         this.setState({ treeData: [resp.data] })
//     }
//     onLoadData(treeNode): Promise<any> {
//         if (_.isArray(treeNode.props.children) && treeNode.props.children.length > 0) {
//             return new Promise((resolve) => resolve());
//         }
//         let treeUrl = `/api-common/organization/tree/${treeNode.props.eventKey}`;
//         Ajax.SESION(treeUrl);
//         if (this.businessLine) {
//             treeUrl = treeUrl + '/' + this.props.businessLine;
//         }
//         return Ajax.GET(treeUrl).then(resp => {
//             treeNode.props.dataRef.children = resp.data;
//             this.setState({
//                 treeData: [...this.state.treeData],
//             });
//         });
//     }
//     renderTreeNodes = (data, parent = null) => {
//         return data.map((item) => {
//             if (item.children) {
//                 return <Tree.TreeNode title={item.name} key={item.code} data={item} parent={parent} dataRef={item}>
//                     {this.renderTreeNodes(item.children, item)}
//                 </Tree.TreeNode>
//             }
//             return <Tree.TreeNode title={item.name} key={item.code} data={item} parent={parent} dataRef={item} />;
//         });
//     }
//     render() {
//         return this.state.treeData.length > 0 ? <Tree
//             loadData={(treeNode) => this.onLoadData(treeNode)}
//             defaultExpandedKeys={[this.state.treeData[0].code]}
//             defaultSelectedKeys={[this.state.treeData[0].code]}
//             onSelect={(evt, node) => {
//                 if (evt.length == 1) {
//                     this.props.onSelect(node.selectedNodes[0].props.data, node.selectedNodes[0].props.parent);
//                 } else {
//                     this.props.onSelect(null);
//                 }
//             }}
//         >
//             {this.renderTreeNodes(this.state.treeData)}
//         </Tree> : ''
//     }
// }
