apiready = function() { var ctrl = { alarmId: null, websocket: null, alarm: null, init: {}, bind: {}, getAlarm: {}, renderAlarm: {}, initWebsocket: {}, renderFilter: {} //渲染报警列表前的拦截器,用于处理体验账号模式下的数据 } //初始化 ctrl.init = function() { // 适配安卓状态栏 CommonModel.fitInStatusBar(); this.alarmId = api.pageParam.id; ctrl.employeeId = $api.getStorage('employeeId'); this.bind(); this.getAlarm(); } //事件绑定 ctrl.bind = function() { //点击返回按钮 $api.addEvt($api.dom("#back"), 'touchend', function() { api.closeWin(); // if(ctrl.websocket){ // ctrl.websocket.close(); // } }, false); //退出app 关闭socket api.addEventListener({ name: 'pause' }, function(ret, err) { // ctrl.websocket.close(); }); //应用恢复 打开websocket api.addEventListener({ name: 'resume' }, function(ret, err) { // ctrl.initWebsocket(ctrl.alarm.serverIp, ctrl.alarm.varType, ctrl.alarm.varIndex); }); // “生成工单” 按钮 点击 $api.addEvt($api.dom("#create-order-btn"), 'touchend', function() { api.confirm({ title: '', msg: '确定要生成工单吗', buttons: ['确定', '取消'] }, function(ret, err) { var index = ret.buttonIndex; if (index == 1) { // 确定 ctrl.createOrder(); } }); }) } ctrl.getAlarm = function() { var data = { alarmId: this.alarmId } var url = "/ems/rest/alarm"; $api.get(url, data, function(ret, err) { if (!err && ret && ret.code === 200) { $api.css($api.dom("#content"), 'display:block'); $api.css($api.dom("#empty-tips"), 'display:none'); ctrl.renderAlarm(ret.body); if (ret.body.handleStatus == 0) { $api.css($api.dom("#create-order-btn"), 'display:block'); } ctrl.alarm = ret.body; } else { $api.css($api.dom("#content"), 'display:none'); $api.css($api.dom("#empty-tips"), 'display:block'); } }); } //渲染报警列表前的拦截器,用于处理体验账号模式下的数据 ctrl.renderFilter = function(alarm) { if ($api.getStorage('cus') && alarm.prName) { alarm.prName = $api.guestPrName; } } ctrl.renderAlarm = function(alarm) { //渲染报警列表前的拦截器,用于处理体验账号模式下的数据 ctrl.renderFilter(alarm); $api.text($api.dom("#pr-name"), alarm.prName); var unit = alarm.unit ? alarm.unit : ''; var content = '