apiready = function() { var ctrl = { logId: null, init: {}, //初始化 bind: {}, //事件绑定 toast: {}, //弹出提示框 getInspectLogDetail: {}, //获取巡检日志详情 renderInspectLogDetail: {}, //渲染巡检日志详情 type: { common: 1, // 一般 recheck: 3, // 复检 burst: 2 // 突发 } } ctrl.init = function() { // 适配安卓状态栏 CommonModel.fitInStatusBar(); this.logId = api.pageParam.id; this.cus = $api.getStorage('cus'); ctrl.bind(); ctrl.getInspectLogDetail(); var pr = $api.getStorage('powerRoom'); $("#pr-name").text(pr.prName); $("#power-name").text(pr.prName); } ctrl.bind = function() { //点击返回按钮 $api.addEvt($api.dom("#back"), "touchend", function() { api.closeWin(); }) $("#inspect-con").on("touchend", ".more", function() { $(this).parent().parent().parent().parent().find("tbody").toggle(); $(this).toggleClass("close") }) //点击有问题的巡检项 $("#inspect-con").on("touchend", "tr", function(e) { e.stopPropagation(); var status = $(this).data("status"); if (status != 2) { return false; } var logId = ctrl.logId; var type = $(this).data("type"); var itemId = $(this).data("id"); api.openWin({ name: 'inspectBug', url: 'widget://html/feature/logQuery/inspectBug.html', pageParam: { logId: logId, type: type, itemId: itemId, } }); }) } /** * 弹出提示框 */ ctrl.toast = function(msg) { api.toast({ msg: msg, duration: 3000, locaiton: 'top' }); } ctrl.getInspectLogDetail = function() { var url = '/ems/rest/common/xj/log/detail'; var data = { "taskId": this.logId }; $api.get(url, data, function(res, err) { if (err) { ctrl.toast("网络请求失败"); } else { if (res.code === 200) { ctrl.renderInspectLogDetail(res); } else if (res.code == 404) { var messageId = api.pageParam.messageId; var msg = ""; if (messageId) { msg = "日志不存在"; ctrl.toast(msg); api.sendEvent({ name: 'removeMessage', extra: { messageId: messageId } }); window.setTimeout(function() { api.closeWin(); }, 2000); }else { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } } else { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } } }); } // 处理数据 ctrl.handleData = function() { ctrl.dailyLogs = []; ctrl.weekLogs = []; ctrl.monthLogs = []; ctrl.ycLogs = []; if (!ctrl.log.routineLogs) { return; } var logs = ctrl.log.routineLogs.concat(ctrl.log.tfLogs, ctrl.log.fjLogs); for (var i = 0; i < logs.length; i++) { var item = logs[i]; if (item.checkType === 1) { ctrl.dailyLogs.push(item); } if (item.checkType === 2) { ctrl.weekLogs.push(item); } if (item.checkType === 3) { ctrl.monthLogs.push(item); } if (item.status === 2) { ctrl.ycLogs.push(item); } } ctrl.log.dailyCount = ctrl.dailyLogs.length; ctrl.log.weekCount = ctrl.weekLogs.length; ctrl.log.monthCount = ctrl.monthLogs.length; ctrl.log.reviewCount = ctrl.log.fjLogs.length; ctrl.log.burstCount = ctrl.log.tfLogs.length; ctrl.log.bugCount = ctrl.ycLogs.length; } ctrl.getItem = function(title, logs, type) { //巡检详情 var statusContent = ['
正常
', '
异常已解决
', '
异常已汇报
' ]; var length = logs.length; var str = ''; if (length > 0) { str += ''; str += ''; str += ""; for (var i = 0; i < length; i++) { if (ctrl.cus) { logs[i].checkItem = logs[i].checkItem.replace($api.guestKeysPattern, $api.guestName); } str += ''; } str += ""; str += "
' + title + '
' + (i + 1) + '' + logs[i].checkItem + '' + statusContent[logs[i].status] + '
"; } return str; } ctrl.renderInspectLogDetail = function(res) { var dateUtil = new DateUtils(); ctrl.log = res.body; ctrl.handleData(); var log = ctrl.log; $api.text($api.dom('#xjDate'), log.xjDate); dateUtil.setDate(log.startTime); $api.text($api.dom('#start-time'), dateUtil.getFormattedDate('yyyy-MM-dd hh:mm')); dateUtil.setDate(log.endTime); $api.text($api.dom('#complete-time'), dateUtil.getFormattedDate('yyyy-MM-dd hh:mm')); $api.text($api.dom('#inspector'), log.employeeName); $api.text($api.dom('#dailyCount'), log.dailyCount); $api.text($api.dom('#weekCount'), log.weekCount); $api.text($api.dom('#monthCount'), log.monthCount); $api.text($api.dom('#ycCount'), log.bugCount); $api.text($api.dom('#reviewCount'), log.reviewCount); $api.text($api.dom('#burstCount'), log.burstCount); var dailyLogs = ctrl.dailyLogs; //日常巡检 var weekLogs = ctrl.weekLogs; //周检 var monthLogs = ctrl.monthLogs; //月检 var reviewLogs = log.fjLogs; //复检 var burstLogs = log.tfLogs; //突发 var con = ""; con += ctrl.getItem('日常巡检', dailyLogs, ctrl.type.common); con += ctrl.getItem('周检', weekLogs, ctrl.type.common); con += ctrl.getItem('月检', monthLogs, ctrl.type.common); con += ctrl.getItem('复检项目', reviewLogs, ctrl.type.recheck); con += ctrl.getItem('突发项目', burstLogs, ctrl.type.burst); $api.html($api.dom('#inspect-con'), con); } ctrl.init(); }