(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 selectedId;
		var collapseIds;
		//获取后台推送数据
        if(props!=null&&props.data!=null){
			var popsData=props.data; 
            //树数据
            treeData = popsData['treeData'];
            selectedId = popsData['selectedId'];
            collapseIds = popsData['collapseIds'];
		}
        //树节点获取选中的单选节点id
		const getSelectedId = (uid) => {
			model.invoke('getSelectedId', uid );
		};

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

        //刷新自定义控件
        var updateControl = function(){
            //创建树
            const tree = React.createElement(Archive.IconTree, {
                treeData: treeData,//树形结构化数据
                selectedId: selectedId,
                collapseIds: collapseIds,
                getSelectedId: getSelectedId,
                getCollapseIds: getCollapseIds,
                treeHeight: model.dom.clientHeight,
                treeWidth: model.dom.clientWidth,
            });

            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('IconTree', MyComponent)
})(window.KDApi,jQuery);
