var unshownJobSiteID = [];//不需要显示的JobSiteID /******************************JobsiteObject******************************/ /******************************JobSite信息获取及显示******************************/ if (typeof (JobsiteObject) != "function") { JobsiteObject = function (mapHelper) { var allJobsites; var REDUN = 2; var MIN_LENGTH = 40; var trunc = function (val) { return (val > 0 ? Math.floor : Math.ceil)(val); }; this.getUnShownMachines = function () { return unshownMachineID; } this.setUnShownMachines = function (machines) { //if (machines) // unshownMachineID = JSON.parse(JSON.stringify(machines)); //else // unshownMachineID = []; } this.getUnShownJobsites = function () { return unshownJobSiteID; } this.setUnShownJobsites = function (jobsites) { unshownJobSiteID = []; if (jobsites) { for (var i in jobsites) { unshownJobSiteID.push(eval(jobsites[i]));//jobsite id 为数值类型 } } } var ROW_JOBSITE_HEIGHT = 26; var jobsiteData = []; var jobsiteMachines = []; var jsvm = new Vue({ el: '#jobsiteList', data: { startIndex: 0, bodyContentStyle: { top: null }, bodyContainerHeight: 0, bodyContainerStyle: { height: null }, scrollTop: 0 }, computed: { bodyClientRowCount: function () { var height = document.getElementById('contentCtrl').clientHeight; return trunc((height - 1) / ROW_JOBSITE_HEIGHT) + 1; }, innerJobsiteMachines: function () { var start = this.startIndex; if (start < 0) { start = 0; } if (jobsiteMachines == null || jobsiteMachines.length < MIN_LENGTH) { return jobsiteMachines.slice(); } var end = this.bodyClientRowCount + start + (REDUN * 2) + 1; if (end > jobsiteMachines.length) { end = jobsiteMachines.length; } return jobsiteMachines.slice(start, end); } }, methods: { fillMachines: function () { var g = []; var allindeterminate = false; var jsselcount = 0; for (var i = 0; i < jobsiteData.length; i++) { var o = jobsiteData[i]; o.__isJobsite = true; o.__indeterminate = false; g.push(o); var selcount = 0; if (o.Machines && o.Machines.length > 0) { for (var j = 0; j < o.Machines.length; j++) { var om = o.Machines[j]; if (om.State.Selected) selcount++; if (!o.Collapsed) g.push(o.Machines[j]); } if (selcount == 0) { o.Selected = false; o.__indeterminate = false; } else if (selcount == o.Machines.length) { o.Selected = true; o.__indeterminate = false; } else { o.__indeterminate = true; allindeterminate = true; } } else o.__indeterminate = false; if (o.Selected) jsselcount++; } jobsiteMachines = g; var chkSelectAll = document.getElementById("chkSelectAll"); chkSelectAll.indeterminate = allindeterminate; if (jsselcount == 0) { chkSelectAll.checked = false; } else if (jsselcount == jobsiteData.length) { chkSelectAll.checked = true; } else { chkSelectAll.indeterminate = true; } var height = g.length * ROW_JOBSITE_HEIGHT; this.bodyContainerHeight = height; this.bodyContainerStyle.height = height && (height + 'px'); var index = this.startIndex; this.startIndex = -1; this.startIndex = index; this.$nextTick(function () { var content = document.getElementById('contentCtrl'); if (this.bodyContainerHeight + 26 <= content.clientHeight) { this.bodyContentStyle.top = 0; this.startIndex = 0; } }); }, reload: function (data) { jobsiteData = data; this.fillMachines(); }, refresh: function () { var index = this.startIndex; this.startIndex = -1; this.startIndex = index; }, treeIconClick: function (e, js) { if (js) { var t = $(e.target); if (t.hasClass("treeiconc")) t.removeClass("treeiconc").addClass("treeicone"); else t.removeClass("treeicone").addClass("treeiconc"); js.Collapsed = !js.Collapsed; this.fillMachines(); } else treeIconClick(e); }, chkJobsiteClick: function (e, js) { chkJobsiteClick(js); this.fillMachines(); }, linkJobSiteClick: function (e, js) { if (!js.Selected) { js.Selected = true; chkJobsiteClick(js); this.fillMachines(); } if (js.Shown) mapHelper.locateJobSite(js); else { js.Shown = true; showJobsiteClick(e, js); mapHelper.locateJobSite(js); } }, showJobsiteClick: function (e, js) { js.Shown = !js.Shown; showJobsiteClick(e, js); }, chkMachineClick: function (m) { chkMachineClick(m); }, linkMachineClick: function (m) { linkMachineClick(m); this.refresh(); }, locationHistoryClick: function (m, ev) { if (selectedAsset) selectedAsset.State.Highlight = false; m.State.Highlight = true; selectedAsset = m; var e = { data: m }; locationHistoryClick(e); } } }); this.refreshJobsiteList = function () { jsvm.refresh(); } this.selectAllJobsites = function (checked) { if (jobsiteData) { for (var i = 0; i < jobsiteData.length; i++) { var js = jobsiteData[i]; if (js.Selected != checked) { js.Selected = checked; chkJobsiteClick(js); } } jsvm.fillMachines(); } } this.onscrollJobsiteMachines = function (e) { if (jobsiteMachines == null || jobsiteMachines.length < MIN_LENGTH) { return; } var top = e == null ? 0 : e.target.scrollTop; top -= (top % ROW_JOBSITE_HEIGHT) + (REDUN * ROW_JOBSITE_HEIGHT); if (top < 0) { top = 0; } else { var bottomTop = jsvm.bodyContainerHeight - ((jsvm.bodyClientRowCount + (REDUN * 2) + 1) * ROW_JOBSITE_HEIGHT); if (top > bottomTop) { top = bottomTop; } } if (jsvm.scrollTop !== top) { jsvm.scrollTop = top; jsvm.startIndex = top / ROW_JOBSITE_HEIGHT; jsvm.bodyContentStyle.top = top && (top + 'px'); } }; function chkJobsiteClick(js) { var checked = js.Selected; if (js && js.Machines) { var ams = []; var rms = []; var rids = []; for (var i in js.Machines) { var machine = js.Machines[i]; if (machine.State.Selected != checked) { machine.State.Selected = checked; if (checked) { ams.push(machine); //unshownMachineID.splice(unshownMachineID.indexOf(machine.ID), 1); rids.push(machine.ID); } else { rms.push(machine); unshownMachineID[unshownMachineID.length] = machine.ID; } } } if (rids.length > 0) { var unshownids = []; for (var i = 0; i < unshownMachineID.length; i++) { var id = unshownMachineID[i]; if (rids.indexOf(id) < 0) unshownids.push(id); } unshownMachineID = unshownids; } if (ams.length > 0) mapHelper.showMachines(ams); if (rms.length > 0) mapHelper.removeMachines(rms); displayFilerIcon(); } } this.searchJobSite = function (isauto) { this.getJobSites(isauto); } this.getJobSites = function (isauto) { var item = { 'IsAutoRefresh': isauto, 'ContractorID': companyids, 'SearchText': "",//htmlencode($("#txtJobSiteSearchText").val()), //在前端过滤,后端不再过滤 'Onroad': $("#selOnroad").val(), }; _network.mapviewquery("GetJobSites", JSON.stringify(item), function (data) { if (data != "-1") { showJobSite(data); } else { showJobSiteAlert(); } }, function () { showJobSiteAlert(); }); } function showJobSiteAlert() { if (jobSiteAlert) { _dialog.close(jobSiteAlert); jobSiteAlert = null; } jobSiteAlert = _dialog.showAlert(GetTextByKey("P_MV_UNABLETOOBTAINJOBSITEDATAATTEMPTINGTORECONNECT", 'Unable to obtain jobsite data. Attempting to reconnect...'), GetTextByKey("P_MV_REFRESHJOBSITEDATA", 'Refresh jobsite data')); } function showJobSite(jobsites) { mapHelper.removeJobsites(allJobsites); var shownJobsites = []; for (var i = jobsites.length - 1; i >= 0; i--) { var js = jobsites[i]; js.Collapsed = true; js.Selected = true; js.Shown = true; if (allJobsites) {//get josbite state for (var j = 0; j < allJobsites.length; j++) { var ljs = allJobsites[j]; if (js.ID === ljs.ID) { js.Collapsed = ljs.Collapsed; js.Selected = ljs.Selected; js.Shown = ljs.Shown; break; } } } var filter = $.trim($("#txtJobSiteSearchText").val()); js.Matched = true; if (filter != "" && js.Name.toLowerCase().indexOf(filter.toLocaleLowerCase()) < 0) js.Matched = false; var assets = []; if (jobsiteAssets[js.ID]) { var tempAssets = jobsiteAssets[js.ID]; for (var j = 0; j < tempAssets.length; j++) {//Assets var a = tempAssets[j]; if (js.Matched || isAssetMatch(a, filter)) { assets.push(a); } } } js.Machines = assets; if (!js.Matched && js.Machines.length == 0) { jobsites.splice(i, 1); } else if (js.Shown) { //需要显示的JobSite mapHelper.showJobSite(js); shownJobsites.push(js); } } mapHelper.refreshJobsiteTooltip(shownJobsites); allJobsites = jobsites; jsvm.reload(allJobsites); return; } function showJobsiteClick(e, js) { var t = $(e.target); if (!t.is("span")) t = t.prev(); if (js.Shown) { t.removeClass("switchoff").addClass("switchon"); mapHelper.showJobSite(js); unshownJobSiteID.splice(unshownJobSiteID.indexOf(js.ID), 1); } else { t.removeClass("switchon").addClass("switchoff"); mapHelper.removeJobSite(js, true); unshownJobSiteID[unshownJobSiteID.length] = js.ID; } displayFilerIcon(); } function chkMachineClick(machine) { if (machine) { if (machine.State.Selected) { mapHelper.showMachine(machine); unshownMachineID.splice(unshownMachineID.indexOf(machine.ID), 1); } else { mapHelper.removeMachine(machine); unshownMachineID[unshownMachineID.length] = machine.ID; } jsvm.reload(allJobsites); displayFilerIcon(); } } function linkMachineClick(machine) { if (machine) { if (machine.State.Selected) { mapHelper.locateMachine(machine); } else { machine.State.Selected = true; unshownMachineID.splice(unshownMachineID.indexOf(machine.ID), 1); mapHelper.showMachine(machine); mapHelper.locateMachine(machine); } displayFilerIcon(); } } } };