// Tree组件,需要引入css/widget/widget.css属性
Vue.component('tree-view-node', function (resolve, reject) {
    $.get("../../js/widget/TreeViewNode.html").then(function (res) {
        resolve({
            template: res,
            props: ['node'],
			computed: {
				/**
				 * 节点是否打开
				 */
				isNodeOpen: function() {
					if(this.node.childrenDatas == undefined || this.node.childrenDatas.length == 0) {
						return undefined;
					} else {
						return this.node.open == true;
					}
				}
			},
			methods: {
				/**
				 * 展开节点
				 * @param  {Object} node 节点数据
				 * @return {void}      
				 */
				nodeExpand: function(node) {
					var _self = this;
					if(node === this.node) {
						node.open = !node.open;
					}
					_self.$emit("node-expand", node);
					
				},
		
				/**
				 * 选择节点
				 * @param  {Object} node 节点数据
				 * @return {void} 
				 */
				nodeSelect: function(node) {
					var _self = this;
				   	if(node === _self.node){
				   		if(node.selected == undefined) {
							_self.$set(node, "selected", false);
						}
						node.selected = !node.selected;
				   	}
					_self.$emit("node-select", node);
				},

				/**
				 * 移动端点击了节点
				 */
				nodeTap: function(param){
					var node = param.node;
					this.nodeSelect(node);
				},

				/**
				 * 移动端点击了展开节点
				 */
				nodeExpandTap: function(param){
					var node = param.node;
					this.nodeExpand(node);
				}
			}
        })
    });
});
