161 lines
4.8 KiB
JavaScript
161 lines
4.8 KiB
JavaScript
import {stationInfoTableList,layuiObj} from "./index.js";
|
|
import { showSchoolBaseInfo } from "./schoolBaseInfo.js";
|
|
import { showMoveDeviceInfoWindow } from "./marker/moveDeviceMarker.js";
|
|
var schoolTreeData=[];
|
|
function createSchoolTree(){
|
|
schoolTreeData=[];
|
|
for(var i=0;i<stationInfoTableList.length;i++){
|
|
setDeviceMenu(stationInfoTableList[i]);//构建节点数据(4层)
|
|
}
|
|
setParameterTree(schoolTreeData);
|
|
initSchoolSearchSelect();
|
|
}
|
|
|
|
function setDeviceMenu(deviceData){
|
|
var borough=deviceData["borough"];
|
|
var detachment=deviceData["detachment"];
|
|
var station=deviceData["name"];
|
|
var mdevArr=deviceData["mdev"];
|
|
for(var iRoot=0;iRoot<schoolTreeData.length;iRoot++){
|
|
var oneNodeName=schoolTreeData[iRoot]["text"];
|
|
if(oneNodeName == borough){
|
|
var brigadeChildren=schoolTreeData[iRoot]["children"];
|
|
for(var boroughNode=0;boroughNode<brigadeChildren.length;boroughNode++){
|
|
var twoNodeName=brigadeChildren[boroughNode]["text"];
|
|
if(twoNodeName==detachment){
|
|
/*找不到中队
|
|
创建3级中队
|
|
创建4级节点*/
|
|
brigadeChildren[boroughNode]["children"].push(
|
|
{
|
|
"id":3,
|
|
"text":station,
|
|
"iconCls":"icon_detachment",
|
|
"children":mdevArr
|
|
}
|
|
)
|
|
|
|
|
|
return;
|
|
}
|
|
}
|
|
/*找不到大队
|
|
创建大队
|
|
创建中队
|
|
创建4级节点 */
|
|
schoolTreeData[iRoot]["children"].push({
|
|
"id":2,
|
|
"text":detachment,
|
|
"state":"closed",
|
|
"iconCls":"icon_borough",
|
|
"children":[
|
|
{
|
|
"id":3,
|
|
"text":station,
|
|
"iconCls":"icon_detachment",
|
|
}
|
|
]
|
|
})
|
|
return;
|
|
}
|
|
}
|
|
/*创建 支队 节点
|
|
创建大队
|
|
创建中队
|
|
创建4级节点 */
|
|
var stationObj={
|
|
"id":1,
|
|
"text":borough,
|
|
"iconCls":"icon_brigade",
|
|
"children":[
|
|
{
|
|
"id":2,
|
|
"text":detachment,
|
|
"state":"closed",
|
|
"iconCls":"icon_borough",
|
|
"children":[
|
|
{
|
|
"id":3,
|
|
"text":station,
|
|
"iconCls":"icon_detachment",
|
|
"children":mdevArr
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
schoolTreeData.push(stationObj);
|
|
return;
|
|
}
|
|
|
|
//设置节点数
|
|
function setParameterTree(schoolTreeData){
|
|
$('.orgTree').tree({
|
|
data:schoolTreeData,
|
|
formatter:function(node){
|
|
var s = "";
|
|
var text=node.text;
|
|
s += `<span >${text}</span>`
|
|
if (node.children){
|
|
s += `<span>(${node.children.length})</span>`
|
|
}
|
|
return s;
|
|
},
|
|
animate:true,
|
|
checkbox:true,
|
|
onClick: function(node){//显示对应的设备总数跟在线
|
|
var id=node["id"];
|
|
switch(id){
|
|
case 3:
|
|
var name=node["text"];
|
|
getNameSchoolInfo(name)
|
|
break;
|
|
case 4:
|
|
showMoveDeviceInfoWindow(node)
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
function getNameSchoolInfo(name){
|
|
for(var i=0;i<stationInfoTableList.length;i++){
|
|
if(name==stationInfoTableList[i]["name"]){
|
|
showSchoolBaseInfo(stationInfoTableList[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
//初始化快速搜索的
|
|
function initSchoolSearchSelect(){
|
|
$("#orgboxSelect").html(getSchoolOptions());
|
|
layuiObj.layuiForm.render("select","orgboxSelectForm");
|
|
$("#orgboxSelect").siblings("div.layui-form-select").find("div.layui-select-title").find("input").attr("onfocus","this.select()");
|
|
schoolSearchSelectChange();
|
|
}
|
|
|
|
//获取所有的设备
|
|
function getSchoolOptions(){
|
|
var options="<option value='000'>请选择学校</option>"
|
|
for(var i=0;i<stationInfoTableList.length;i++){
|
|
var name=stationInfoTableList[i]["name"];
|
|
options+=`<option value="${name}">${name}</option>`
|
|
}
|
|
return options;
|
|
}
|
|
|
|
//监听select变化
|
|
function schoolSearchSelectChange(){
|
|
layuiObj.layuiForm.on('select(orgboxSelect)', function(data){
|
|
var name=data["value"];
|
|
getNameSchoolInfo(name)
|
|
})
|
|
}
|
|
|
|
export {
|
|
createSchoolTree,
|
|
getSchoolOptions,
|
|
getNameSchoolInfo
|
|
} |