if (typeof manageassetsCtrl !== 'function') { $manageassetsCtrl = function manageassetsCtrl() { this.tmpobj = { }; this.wizardCtrl = null; this.vue = null; }; (function () { 'use strict'; var dataGrid = window.DataGrid || window['g5-datagrid']; $manageassetsCtrl.prototype.getData = function (/*dataObj, tmpdata*/) { return this.vue.source; }; $manageassetsCtrl.prototype.setData = function (assetData) { if (assetData) { for (var i = 0; i < assetData.length; i++) { var a = assetData[i]; a.Selected = false; if (a.Highlight == undefined) a.Highlight = false; } } this.vue.source = assetData ? assetData : []; this.vue.$refs.grid.resize(); }; $manageassetsCtrl.prototype.reload = function () { this.vue.$refs.grid.reload() }; $manageassetsCtrl.prototype.Init = function (parent, newselected) { var ethis = this; //加载子页面模版 parent.load('../template/ManageAssetsCtrl.html?v=8', function () { ethis.vue = new Vue({ el: parent.find('.ManageAssetsCtrl')[0], components: { 'data-grid': dataGrid }, data: { wnd: window.parent, editable: true, columns: [], source: [] }, computed: { }, watch: { source: function (val) { } }, methods: { cellvaluechanged: function (item, key) { }, rowdblclick: function (e) { } } }); ethis.vue.columns = createGridColumn(newselected); }); }; function createGridColumn(newselected) { var editable = false; var columns = [ { key: 'Selected', caption: '', type: dataGrid.COLUMN_TYPE.checkbox, width: 30, align: 'center', sortable: false, orderable: false, enabled: true, resizable: false, allcheck: false, visible: !newselected }, { key: 'VIN', caption: GetTextByKey("P_PM_SN", 'SN'), type: dataGrid.COLUMN_TYPE.lable, width: 140, orderable: false, resizable: true, enabled: editable, styleFilter: function (item) { if (item.Highlight) return { 'background-color': 'yellow' }; } }, { key: 'Name', caption: GetTextByKey("P_PM_NAME", 'Name'), type: dataGrid.COLUMN_TYPE.lable, width: 140, orderable: false, resizable: true, enabled: editable, styleFilter: function (item) { if (item.Highlight) return { 'background-color': 'yellow' }; } }, { key: 'MakeName', caption: GetTextByKey("P_PM_MAKE", 'Make'), type: dataGrid.COLUMN_TYPE.lable, width: 100, orderable: false, enabled: editable, resizable: true, visible: !newselected, styleFilter: function (item) { if (item.Highlight) return { 'background-color': 'yellow' }; } }, { key: 'ModelName', caption: GetTextByKey("P_PM_MODEL", 'Model'), type: dataGrid.COLUMN_TYPE.lable, width: 100, orderable: false, resizable: true, enabled: editable, visible: !newselected, styleFilter: function (item) { if (item.Highlight) return { 'background-color': 'yellow' }; } }, { key: 'EngineHours', caption: GetTextByKey("P_PM_CURRENTHOURS", 'Current Hours'), type: dataGrid.COLUMN_TYPE.lable, width: 100, orderable: false, resizable: true, visible: (scheduletype === "HM" || scheduletype === "PM") }, { key: 'StartHours', caption: GetTextByKey("P_PM_STARTINGHOURS", 'Starting Hours'), type: dataGrid.COLUMN_TYPE.input, width: 100, orderable: false, resizable: false, enabled: 'Enabled', visible: (scheduletype === "HM" || scheduletype === "PM") }, { key: 'Odometer', caption: GetTextByKey("P_PM_CURRENTODOMETER", 'Current Odometer'), type: dataGrid.COLUMN_TYPE.lable, width: 120, orderable: false, resizable: true, visible: (scheduletype === "RDM" || scheduletype === "ADM") }, { key: 'StartOdometer', caption: GetTextByKey("P_PM_STARTODOMETER", 'Start Odometer'), type: dataGrid.COLUMN_TYPE.input, width: 100, orderable: false, resizable: false, enabled: 'Enabled', visible: (scheduletype === "RDM" || scheduletype === "ADM") }, { key: 'StartDateString', caption: GetTextByKey("P_PM_PLANSTARTDATE", 'Plan Start Date'), type: dataGrid.COLUMN_TYPE.datepicker, width: 100, orderable: false, resizable: false, enabled: 'Enabled', visible: scheduletype === "TBM" }, { key: 'StartIntervalValue', caption: GetTextByKey("P_PM_STARTINTERVAL", 'Start Interval'), type: dataGrid.COLUMN_TYPE.dropdown, source: 'TempIntervals', width: 100, orderable: false, resizable: false, enabled: 'Enabled', visible: (scheduletype === "HM" || scheduletype === "RDM" || scheduletype === "TBM") } ]; return columns; } }()); } function getIntervalValues(currentValue) { var result = [];//取当前值的前两个和后10个Interval if (allintervals && allintervals.length > 0) { var maxInterval = allintervals[allintervals.length - 1]; var pervoid = parseInt(currentValue / maxInterval); var remain = currentValue % maxInterval; if (remain > 0) pervoid++; var maxpervoid = pervoid + 1; var minpervoid = pervoid - parseInt(10 / allintervals.length) - 1;//10表示向后取10 if (minpervoid < 0) minpervoid = 0; for (var pi = maxpervoid; pi >= minpervoid; pi--) { for (var i = allintervals.length - 1; i >= 0; i--) { var interval = allintervals[i]; var tempinterval = pi * maxInterval + interval; result.push(tempinterval); if (tempinterval >= currentValue) { if (result.length > 2) result.splice(0, 1); } else if (result.length == 12) break; } } } return result; } /******************************Assets********************************/ function getMachineTypes() { pmquery('GetMachineTypes', '', function (data) { var types = []; types.push($('')); if (data && data.length > 0) { for (var i = 0; i < data.length; i++) { types.push($('').val(data[i].ID).text(data[i].Name)); } } types[0].prop('selected', true); $('#sel_machine_type').empty().append(types); GetSelectedMachines(); }); } function GetSelectedMachines() { _ScheduleAssets = []; pmquery('GetSelectedMachines', iid, function (data) { if (typeof data === "string") { showAlert(data, GetTextByKey("P_PM_ASSETASSIGNMENT", 'Asset Assignment')); return; } _ScheduleAssets = data; for (var i = 0; i < _SelectedUnSavedMachines.length; i++) { _ScheduleAssets.push(_SelectedUnSavedMachines[i]); } getMatchSelectedMachines(); }); } function getMatchSelectedMachines() { var typeid = $('#sel_machine_type').val(); var machinefilter = $('#txt_machine_key').val().toLowerCase(); var showallassigned = $('#chk_showallassignedassets').prop('checked'); _showSelectedMachines = []; var unMatched = []; for (var i = 0; i < _ScheduleAssets.length; i++) { var m = _ScheduleAssets[i]; m.Enabled = !m.AlertsCount || m.AlertsCount == 0; m.Highlight = false; if (((typeid == -1 || typeid == m.TypeID) && (machinefilter == "" || m.VIN.toLowerCase().indexOf(machinefilter) >= 0 || m.Name.toLowerCase().indexOf(machinefilter) >= 0))) { m.Highlight = showallassigned && (machinefilter !== "" || typeid != -1); if (scheduletype == "HM" || scheduletype == "RDM") { var value = 0; if (scheduletype == "HM") value = m.StartHours; else value = m.StartOdometer; m.TempIntervals = getIntervalValues(value); m.TempIntervals.splice(0, 0, ""); } else { m.TempIntervals = []; m.TempIntervals.push(""); if (allintervals) { for (var j = 0; j < allintervals.length; j++) m.TempIntervals.push(allintervals[j]); } } _showSelectedMachines.push(m);//Show All时,满足是啥条件的放在前面并高亮显示 } else if (showallassigned) unMatched.push(m); } if (showallassigned) { for (var i in unMatched) _showSelectedMachines.push(unMatched[i]); } if (assignedassetCtrl) { assignedassetCtrl.setData(_showSelectedMachines); //assignedassetCtrl.reload(); } } function OnSaveMachines() { var assets = []; for (var i = 0; i < _ScheduleAssets.length; i++) { var machine = _ScheduleAssets[i]; var asset = {}; asset.AssetId = machine.AssetId; asset.StartIntervalValue = machine.StartIntervalValue; switch (scheduletype) { case "TBM": asset.StartDate = machine.StartDateString; if (asset.StartDate == "") asset.StartDate = "1900-01-01"; break; case "PM": case "HM": asset.StartHours = machine.StartHours; if (asset.StartHours == "") asset.StartHours = "0"; break; case "ADM": case "RDM": asset.StartOdometer = machine.StartOdometer; if (asset.StartOdometer == "") asset.StartOdometer = "0"; break; } assets.push(asset); } var item = { 'IID': iid, 'Assets': assets }; pmquery('SaveMachines', JSON.stringify(item), function (data) { if (!data || data.length == 0) { // success for (var i = 0; i < _ScheduleAssets.length; i++) { _ScheduleAssets[i].unSaved = false; } showAlert(GetTextByKey("P_PM_SAVEASSETLISTSUCCESSFUL", 'Save asset list successful.')); } else { showAlert(GetTextByKey("P_PM_FAILEDTOSAVEASSETLIST", 'Failed to save asset list.') + "\n" + data); } }); } var dialogAssets = undefined; function OnAddAssets() { if (!dialogAssets) { dialogAssets = new $assetselector("dialog_assets"); dialogAssets.allowhidden = false; dialogAssets.onDialogClosed = function () { showmaskbg(false); } dialogAssets.onOK = function (assets) { if (assets && assets.length > 0) { setNewSelectedAseets(assets); } } } showmaskbg(true); var assets = []; for (var i = 0; i < _ScheduleAssets.length; i++) { assets.push(_ScheduleAssets[i].AssetId); } dialogAssets.exceptSource = assets; dialogAssets.showSelector(assets); } function convertOdometer(odometer, odounit) { var unit = scheduleUom; var value = odometer; if (odometer > 0 && unit && odounit && unit.toLowerCase().charAt(0) != odounit.toLowerCase().charAt(0)) { if (unit.toLowerCase().startsWith("m")) value = odometer * 0.6213712; else value = odometer / 0.6213712; } return Math.round(value); } var selectedassetsctrl = undefined; function setNewSelectedAseets(assets) { var newassets = []; for (var i = 0; i < assets.length; i++) { var a = assets[i].Values; if (!a.Selected) continue; var item = {}; item.AssetId = a.Id; item.Selected = false; item.VIN = a.VIN; item.Name = a.Name; item.MakeName = a.MakeName; item.ModelName = a.ModelName; item.EngineHours = a.EngineHours; item.StartHours = a.EngineHours; item.Odometer = convertOdometer(a.Odometer, a.OdometerUnits); item.StartOdometer = item.Odometer; item.OdometerUnits = a.OdometerUnits; item.StartDateString = currentdate; item.StartIntervalValue = ""; item.Enabled = true; if (scheduletype == "HM" || scheduletype == "RDM") { var value = 0; if (scheduletype == "HM") value = item.StartHours; else value = item.StartOdometer; item.TempIntervals = getIntervalValues(value); item.TempIntervals.splice(0, 0, ""); } else { item.TempIntervals = []; item.TempIntervals.push(""); if (allintervals) { for (var j = 0; j < allintervals.length; j++) item.TempIntervals.push(allintervals[j]); } } newassets.push(item); } if (newassets.length == 0) { showmaskbg(false); return; } $('#dialog_selectedassets') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_machinegroup').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_machinegroup').width()) / 2 }).showDialog(); selectedassetsctrl.setData(newassets); } function OnSetAssetsDialogOK() { for (var i = 0; i < selectedassetsctrl.vue.source.length; i++) { var asset = selectedassetsctrl.vue.source[i]; asset.unSaved = true; _ScheduleAssets.push(asset); } getMatchSelectedMachines(); showmaskbg(false); $('#dialog_selectedassets').hideDialog(); } function OnRemoveAssets() { _SelectedUnSavedMachines = []; var assets = []; var assetwillalerts = ""; for (var i = 0; i < _ScheduleAssets.length; i++) { var asset = _ScheduleAssets[i]; if (asset.unSaved && !asset.Selected) _SelectedUnSavedMachines.push(asset); if (asset.Selected) { assets.push(asset.AssetId); if (asset.UnMaintainedAlert && asset.UnMaintainedAlert > 0) { if (assetwillalerts == "") assetwillalerts = asset.Name; else assetwillalerts += ", " + asset.Name; } } } if (assets.length == 0) return; var item = { 'ScheduleID': iid, 'Assets': assets }; var msg = GetTextByKey("P_PM_DOYOUWANTTOREMOVEHESELECTEDASSETSFROMTHISSCHEDULE", "Do you want to remove the selected assets from this schedule?"); if (assetwillalerts != "") { var msg = GetTextByKey("P_PM_DELETEUNASSIGNEDPMALERTSFORTHEFOLLOWINGASSETSTIPS", "Select OK below will result in the deletion of existing unassigned PM alerts for the following assets: "); msg += assetwillalerts + ".
"; msg += GetTextByKey("P_PM_DELTEALERTSYESORNOTIPS", "If you do not want those alerts deleted, select CANCEL and assign appropriate alerts to a maintenance record or work order in asset health prior to deletion/removal."); } showConfirm(msg, GetTextByKey("P_PM_REMOVEASSETS", 'Remove Assets'), function (e) { pmquery('RemovePMAssets', JSON.stringify(item), function (data) { if (!data || data.length == 0) { showAlert(GetTextByKey("P_PM_ASSETSREMOVEDSUCCESSFULLY", 'Assets removed successfully.')); GetSelectedMachines(); } else { showAlert(GetTextByKey("P_PM_FAILEDTOREMOVEASSETS", 'Failed to remove assets.') + "\n" + data); } }); }); }