apiready = function() { var ctrl = { init: {}, bind: {}, employeeId: null, roleId: null, prList: null, inspectionId: null, xjDate: null, jieDanRenId: null, status: null, // status:0 未接单,1 未开始,2 巡检中,3 已完成 tabType: 'content', // 当前激活的 tab prefix: 'https://cdyfile.saas.dianwutong.com/', problemType: 0, // 设备缺陷类型 hasUnfinishedPr: false, // 当前巡检任务下,是否存在未完成巡检的配电室,默认不存在 }; ctrl.init = function() { // 适配安卓状态栏 CommonModel.fitInStatusBar(); ctrl.inspectionId = api.pageParam.inspectionid; // status:1 未开始,2 巡检中,3 已完成 ctrl.status = api.pageParam.status; if (ctrl.status == 1) { $('#start-inspect-btn').show(); $('#finish-inspect-btn').hide(); } else if (ctrl.status == 2) { $('#start-inspect-btn').hide(); $('#finish-inspect-btn').show(); } else if (ctrl.status == 3) { $('#start-inspect-btn').hide(); $('#finish-inspect-btn').hide(); } ctrl.employeeId = $api.getStorage('employeeId'); ctrl.roleId = $api.getStorage('roleId'); ctrl.prList = $("#prList"); ctrl.contentEmptyTips = $("#content-empty-tips"); ctrl.problemEmptyTips = $("#problem-empty-tips"); ctrl.title = $('#title'); ctrl.xjDateDome = $('#xjDate'); ctrl.prCountDom = $('#prCount'); //巡检任务信息发生变化 api.addEventListener({ name: 'inspectionPrChanged' }, ctrl.inspectionPrChanged); ctrl.bind(); ctrl.initInspectContentTab() }; ctrl.bind = function() { // 点击返回按钮 $api.addEvt($api.dom("#back"), "touchend", function() { api.closeWin(); }); //点击 “巡检内容” tab按钮 $api.addEvt($api.dom("#content-tab"), "touchend", function () { if (ctrl.tabType == 'content') { return } $api.addCls(this, "active"); $api.removeCls($api.dom("#problem-tab"), "active"); $api.css($api.dom("#content-panel"), 'display:block'); $api.css($api.dom("#problem-panel"), 'display:none'); $api.css($api.dom('#content-empty-tips'), "display:none"); ctrl.tabType = 'content' // 初始化 巡检内容 tab ctrl.initInspectContentTab(); }, false); //点击 “设备缺陷” tab按钮 $api.addEvt($api.dom("#problem-tab"), "touchend", function () { if (ctrl.tabType == 'problem') { return } $api.addCls(this, "active"); $api.removeCls($api.dom("#content-tab"), "active"); $api.css($api.dom("#problem-panel"), 'display:block'); $api.css($api.dom("#content-panel"), 'display:none'); $api.css($api.dom('#problem-empty-tips'), "display:none"); ctrl.tabType = 'problem'; // 初始化 设备缺陷 tab ctrl.initInspectProblemTab(); }, false); // 点击“未处理” btn $("#btn-unhandle").on("touchend", function() { ctrl.problemType = 0; $(this).siblings('.bg-touch').removeClass('bg-yellow'); $(this).addClass('bg-yellow'); ctrl.initInspectProblemTab(); }); // 点击“处理中” btn $("#btn-handling").on("touchend", function() { ctrl.problemType = 1; $(this).siblings('.bg-touch').removeClass('bg-yellow'); $(this).addClass('bg-yellow'); ctrl.initInspectProblemTab(); }); // 点击图片预览 $("#problem-list-container").on("touchend", ".problem-pic-item", function (e) { e.stopPropagation(); var src = $(this).attr('src'); $('#pic-review img').attr('src', src); $('#pic-review').css('display', 'block'); }); // 点击预览图片 关闭预览 $('#pic-review').on("touchend", function () { $(this).css('display', 'none'); }); // 点击配电室 跳转到对应配电室巡检详情页 $('#prList').on("touchend", ".pr", function(e) { e.stopPropagation(); // 只有巡检中的单子才能跳转到配电室详情页 if (ctrl.status == 0 || ctrl.status == 1) { ctrl.toast('开始巡检后才能查看'); return; }; var id = $(this).data('id'); var prId = $(this).data('prid'); var prName = $(this).data('prname'); var status = $(this).data('status'); if (status == '2') { // 已完成 巡检的配电室禁止跳转 ctrl.toast('已完成巡检,无法查看'); return; }; api.openWin({ name: 'inspectionPrDetail', url: './inspectionPrDetail.html', pageParam: { id: id, prid: prId, prname: prName } }); }); // 点击 "开始巡检" 按钮 $('#start-inspect-btn').on("touchend", function(e) { e.stopPropagation(); api.confirm({ title: '', msg: '确定要开始吗', buttons: ['确定', '取消'] }, function(ret, err) { var index = ret.buttonIndex; if (index == 1) { // 确定 ctrl.startInspect(); } }); }); // 点击 “巡检完成” 按钮 $('#finish-inspect-btn').on("touchend", function(e) { e.stopPropagation(); api.confirm({ title: '', msg: '确定所有配电室巡检完成了吗', buttons: ['确定', '取消'] }, function(ret, err) { var index = ret.buttonIndex; if (index == 1) { // 确定 if (ctrl.hasUnfinishedPr) { ctrl.toast('存在未巡检完成的配电室!'); } else { ctrl.finishInspect(); }; } }); }); }; /** * 弹出提示框 */ ctrl.toast = function(msg) { api.toast({ msg: msg, duration: 3000, locaiton: 'top' }); }; // 初始化 巡检内容 tab ctrl.initInspectContentTab = function() { ctrl.getInspectDetail(); }; // 初始化 设备缺陷 tab ctrl.initInspectProblemTab = function() { ctrl.getProblemList(); }; // 获取设备缺陷 列表 ctrl.getProblemList = function() { api.showProgress(); var url = '/test/xun-jian-dan/queryProblemById/' + ctrl.inspectionId + '/' + ctrl.problemType; $api.get(url, function(res, err) { if (err) { ctrl.toast("网络请求失败"); api.hideProgress(); } else { if (!res.code || res.code != "200") { ctrl.toast("服务器响应错误"); api.hideProgress(); } else { ctrl.renderProblemList(res.data); } } }); }; // 清空设备缺陷 列表 ctrl.clearProblemList = function() { $("#problem-list-container").empty(); }; // 渲染设备缺陷 列表 ctrl.renderProblemList = function(data) { var length = data.length; ctrl.clearProblemList(); if (length > 0) { ctrl.problemEmptyTips.hide(); for (var i = 0; i < length; i++) { var dataItem = data[i]; ctrl.createProblemDom(i + 1, dataItem); }; } else { ctrl.problemEmptyTips.show(); }; api.hideProgress(); }; // 创建 设备缺陷 DOM ctrl.createProblemDom = function(index, problemItem) { var tpl = ''; var status = ''; var colorClass = ''; var problemDesc = problemItem.problemDesc; var pics = []; if (problemItem.picture) { pics = problemItem.picture.split(','); }; var picsLength = pics.length; if (problemItem.status == 0) { status = '未处理'; colorClass = 'text-red'; } else if (problemItem.status == 1) { status = '处理中'; colorClass = 'text-yellow'; }; tpl += '