(function(KDApi,$){
    function MyComponent(model){
        this._setModel(model);
    }
	var isLoadLibs = false;
    MyComponent.prototype = {
        _setModel: function(model) {
            this.model = model;
        },
        init:function(props){
          setHtml(this.model,props);
        },
        update:function(props){
			isUpdate=true;
          setHtml(this.model,props);
        },
        destoryed:function(){
            console.log('-----destoryed',this.model)
        }
    }     	
	
	var setHtml = function(model,props){
        //树数据
        var treeData; 
		var selectedUid;
		var collapseUids;
		//获取后台推送数据
        if(props!=null&&props.data!=null){
			var popsData=props.data; 
            //树数据
            treeData = popsData['treeData'];
            selectedUid = popsData['selectedUid'];
            collapseUids = popsData['collapseUids'];
		}
        //树节点获取新树
        const getNewTreeData = (tree) => {
			model.invoke('getNewTreeData', tree );
		};
        //树节点获取选中的单选节点id
		const getselectedUid = (uid) => {
			model.invoke('getselectedUid', uid );
		};

		const getCollapseUids = (uids) => {
			model.invoke('getCollapseUids', uids );
		};

        //刷新自定义控件
        var updateControl = function(){
            //创建树
            const tree = React.createElement(Archive.FileTree, {
                treeData: treeData,//树形结构化数据
                getNewTreeData: getNewTreeData,
                collapseUids: collapseUids,
                getselectedUid: getselectedUid,
				selectedUid: selectedUid,
                getCollapseUids: getCollapseUids,
                treeHeight: model.dom.clientHeight,
                treeWidth: model.dom.clientWidth,
				draggable: true
            });

            ReactDOM.render(tree, model.dom);
        }

        if (!isLoadLibs) {
            KDApi.loadFile(['../../../../kingdee/imc/viewinvoice/fullScanImages.js','../common/Archive.min.css'],model.schemaId,() => {
                isLoadLibs = true;
                updateControl();
            });
        }else {
            updateControl();
        }
    }

    KDApi.register('FileTree', MyComponent)
})(window.KDApi,jQuery);
