(function (vc) { let DEFAULT_PAGE = 1; let DEFAULT_ROW = 10; vc.extends({ data: { communityUnitTreeInfo: { units: [], callName: '' } }, _initMethod: function () { }, _initEvent: function () { vc.on('communityUnitTree', 'initCommunityUnitTree', function (_param) { $that.communityUnitTreeInfo.callName = _param.callName; $that._loadCommunityUnitTree(); }); }, methods: { _loadCommunityUnitTree: function () { let param = { params: { hc:1.8 } }; //发送get请求 vc.http.apiGet('/community.queryCommunityUnitTree', param, function (json) { let _json = JSON.parse(json); $that.communityUnitTreeInfo.units = _json.data; $that._initJsTreeCommunityUnitTree(); }, function () { console.log('请求失败处理'); }); }, _initJsTreeCommunityUnitTree: function () { let _data = $that.communityUnitTreeInfo.units; $.jstree.destroy() $("#jstree_communityUnitTreeDiv").jstree({ "checkbox": { "keep_selected_style": false }, 'state': { //一些初始化状态 "opened": true, }, 'core': { "check_callback": true, 'data': _data } }); $("#jstree_communityUnitTreeDiv").on("ready.jstree", function (e, data) { $('#jstree_communityUnitTreeDiv').jstree('select_node', _data[0].children[0].id /* , true */); }); $('#jstree_communityUnitTreeDiv').on("changed.jstree", function (e, data) { if (data.action == 'model' || data.action == 'ready') { return; } let _selected = data.selected[0]; if (_selected.startsWith('c_')) { vc.emit($that.communityUnitTreeInfo.callName, 'selectCommunity', { communityName: data.node.original.communityName, communityId: data.node.original.communityId }) return; } if (_selected.startsWith('f_')) { vc.emit($that.communityUnitTreeInfo.callName, 'selectFloor', { floorNum: data.node.original.floorNum, floorId: data.node.original.floorId }) return; } //console.log(_selected, data.node.original.unitId) if (_selected.startsWith('u_')) { vc.emit($that.communityUnitTreeInfo.callName, 'selectUnit', { unitNum: data.node.original.unitNum, unitId: data.node.original.unitId }) } }); $('#jstree_communityUnitTreeDiv') .on('click', '.jstree-anchor', function (e) { $(this).jstree(true).toggle_node(e.target); }) }, } }); })(window.vc);