apiready = function () { //默认显示对比分页tab-panel 即 ctrl.mode = ctrl.modes.COMPARE; //默认时间粒度是日数据 即 ctrl.dimension = ctrl.dimensions.DAY; //默认时间是当前月 //当收到侧栏页的 “energySelectedNumber”的消息,也就是侧栏页选中了调度号,同时在消息体里把调度号传回主页 调用获取数据的方法 getData //getData方法调用各个获取数据的具体方法 // getTimeData() // getCompareData() //获取到数据之后 保存在对用的数据对象里 // compareAChartData // compareATableData // timeAChartData // timeBChartData // timeCChartData // 然后调用分别在各个获取数据的方法里调用对应的render方法来渲染表格或者图表 //当切换了“分时分析”和“对比分析”panel 调用对应的render方法,不在调用getData(); //当点击“选择回路”按钮 弹出侧栏 选中调度号后 点击确定 主页收到“energySelectedNumber”消息 重新调用getData()方法,重复上述步骤 //当选择了“日数据”或“月数据”按钮, 重新调用getData()方法 //重新选择了日期之后, 重新调用getData()方法 var ctrl = { init: {}, bind: {}, backCallback: {}, // 当前展示的tab 页类型,msg:配电室资料 inspection:巡检日志 repair:抢修日志 tabType: 'msg', prId: null, prName: '', baseUrl: '', currentPage: 1, pageSize: 20, repairCurrentPage: 1, repairPageSize: 20, flag: 2, // 处理完(日志) } ctrl.init = function () { // 适配安卓状态栏 CommonModel.fitInStatusBar(); ctrl.bind(); api.showProgress({ title: '载入中...', text: '请稍后', modal: false }); ctrl.prId = api.pageParam.prid; ctrl.prName = api.pageParam.prname; ctrl.taskId = api.pageParam.taskid; ctrl.initPrMsgTab() } ctrl.bind = function () { var $startTime = $('#startTime-select'); var $endTime = $('#endTime-select'); var $lbStartTime = $('#lbStartTime'); var $lbEndTime = $('#lbEndTime'); var $repairStartTime = $('#repair-startTime-select'); var $repairEndTime = $('#repair-endTime-select'); var $repairLbStartTime = $('#repair-lbStartTime'); var $repairLbEndTime = $('#repair-lbEndTime'); var _this = this; var height = $(window).height() - $("header").height() - $(".tabs").height(); $(".content-container").css("height", height); //绑定返回按钮 $api.addEvt($api.dom("#back"), "touchend", function () { ctrl.backCallback(); }) //点击系统返回按钮 api.addEventListener({ name: 'keyback' }, function (ret, err) { ctrl.backCallback(); }); //点击开始巡检按钮 $api.addEvt($api.dom("#start-inspect-btn"), "touchend", function () { ctrl.handleStartInspect() }) //点击配电室资料tab按钮 $api.addEvt($api.dom("#pr-msg-tab"), "touchend", function () { if (ctrl.tabType == 'msg') { return } $api.addCls(this, "active"); $api.removeCls($api.dom("#inspection-log-tab"), "active"); $api.removeCls($api.dom("#repair-log-tab"), "active"); $api.css($api.dom("#pr-msg-panel"), 'display:block'); $api.css($api.dom("#inspection-log-panel"), 'display:none'); $api.css($api.dom("#repair-log-panel"), 'display:none'); ctrl.tabType = 'msg' ctrl.initPrMsgTab() }, false); //点击巡检日志tab按钮 $api.addEvt($api.dom("#inspection-log-tab"), "touchend", function () { if (ctrl.tabType == 'inspection') { return } $api.addCls(this, "active"); $api.removeCls($api.dom("#pr-msg-tab"), "active"); $api.removeCls($api.dom("#repair-log-tab"), "active"); $api.css($api.dom("#inspection-log-panel"), 'display:block'); $api.css($api.dom("#pr-msg-panel"), 'display:none'); $api.css($api.dom("#repair-log-panel"), 'display:none'); ctrl.tabType = 'inspection' // 初始化巡检日志 tab ctrl.getInspectLog(); }, false); //点击抢修日志tab按钮 $api.addEvt($api.dom("#repair-log-tab"), "touchend", function () { if (ctrl.tabType == 'repair') { return } $api.addCls(this, "active"); $api.removeCls($api.dom("#pr-msg-tab"), "active"); $api.removeCls($api.dom("#inspection-log-tab"), "active"); $api.css($api.dom("#repair-log-panel"), 'display:block'); $api.css($api.dom("#pr-msg-panel"), 'display:none'); $api.css($api.dom("#inspection-log-panel"), 'display:none'); ctrl.tabType = 'repair' ctrl.getRepairLogs(); }, false); /* ====================配电室资料 tab 相关事件==================== */ // 点击配电室资料列表 ,在线浏览 pdf $("#pr-msg-list").on("touchend", ".pr-msg-list-item", function () { var url = ctrl.baseUrl + $(this).data("url"); api.download({ url: url, // 填写要下载文档的url report: true, cache: true, allowResume: true }, function (ret, err) { if (ret.state == 1) { //下载成功 var superFile = api.require('superFile'); superFile.open({ path: ret.savePath, }) } }); }) /* ====================巡检日志 tab 中相关事件==================== */ $startTime.on('change', function () { var startTimeValue = $startTime.val(); var endTimeValue = $endTime.val(); if (startTimeValue) { $lbStartTime.html(startTimeValue); } else { $lbStartTime.html("开始日期"); } }) $endTime.on('change', function () { var startTimeValue = $startTime.val(); var endTimeValue = $endTime.val(); if (endTimeValue) { $lbEndTime.html(endTimeValue); } else { $lbEndTime.html("结束日期"); } }) // 点击巡检日志跳转到详情页 $("#inspect-logs").on("touchend", ".item", function () { var id = $(this).data('id'); var name = $(this).data('name'); api.openWin({ name: 'inspectionLogDetail', url: './inspectionLogDetail.html', pageParam: { id: id, name: name } }); }) //点击查询巡检日志 $api.addEvt($api.dom("#query"), "touchend", function () { $api.html($api.dom('#inspect-logs'), ''); _this.currentPage = 1; _this.getInspectLog(); }); /* =======================抢修日志 tab 相关事件====================== */ $repairStartTime.on('change', function () { var startTimeValue = $repairStartTime.val(); if (startTimeValue) { $repairLbStartTime.html(startTimeValue); } else { $repairLbStartTime.html("开始日期"); } }) $repairEndTime.on('change', function () { var endTimeValue = $repairEndTime.val(); if (endTimeValue) { $repairLbEndTime.html(endTimeValue); } else { $repairLbEndTime.html("结束日期"); } }) $api.addEvt($api.dom("#repair-query"), "touchend", function () { $api.html($api.dom('#repair-logs'), ''); ctrl.repairCurrentPage = 1; ctrl.getRepairLogs(); }); //跳转到抢修日志详情页 $("#repair-logs").on("touchend", ".item", function () { var id = $(this).data('id'); var name = $(this).data('name'); api.openWin({ name: 'repairDetail', url: './repairLogDetail.html', pageParam: { id: id, name: name } }); }) // 查询抢修日志 $api.addEvt($api.dom("#repair-query"), "touchend", function () { $api.html($api.dom('#repair-logs'), ''); ctrl.repairCurrentPage = 1; ctrl.getRepairLogs(); }); } /** * 弹出提示框 */ ctrl.toast = function (msg) { api.toast({ msg: msg, duration: 3000, locaiton: 'top' }); } ctrl.backCallback = function () { //关闭首页正在加载的提示框 api.execScript({ name: 'index', frameName: 'featureFrame', script: "api.hideProgress();" }); api.setScreenOrientation({ orientation: 'auto_portrait' }); api.setFullScreen({ fullScreen: false }); api.closeWin({}); } //上拉加载 api.addEventListener({ name: 'scrolltobottom' }, function (ret, err) { if (ctrl.tabType == 'inspection') { ctrl.currentPage++; if (ctrl.currentPage > ctrl.totalPages) { ctrl.toast("没有更多了"); return; } ctrl.getInspectionLog(); } else if (ctrl.tabType == 'repair') { ctrl.repairCurrentPage++; if (ctrl.repairCurrentPage > ctrl.repairTotalPages) { ctrl.toast("没有更多了"); return; } ctrl.getRepairLogs(); } }); //下拉刷新 api.setRefreshHeaderInfo({ loadingImg: 'widget://image/refresh.png', bgColor: '#ccc', textColor: '#fff', textDown: '下拉刷新...', textUp: '松开刷新...' }, function (ret, err) { if (ctrl.tabType == 'msg') { ctrl.initPrMsgTab() } else if (ctrl.tabType == 'inspection') { $startTime.val(''); $endTime.val(''); $lbStartTime.html("开始日期"); $lbEndTime.html("结束日期"); _this.currentPage = 1; _this.getInspectLog(); } else if (ctrl.tabType == 'repair') { $repairStartTime.val(''); $repairEndTime.val(''); $repairLbStartTime.html("开始日期"); $repairLbEndTime.html("结束日期"); ctrl.repairCurrentPage = 1; ctrl.getRepairLogs(); } api.refreshHeaderLoadDone(); }); /* ====================配电室资料 tab 相关=================== */ // 初始化 配电室资料 tab ctrl.initPrMsgTab = function () { ctrl.getPrMsg() ctrl.getPrMsgList() } // 获取配电室信息 ctrl.getPrMsg = function () { api.showProgress({ title: '载入中...', text: '请稍后', modal: false }); var url = "/ems/rest/power/room/detail"; var data = { prId: ctrl.prId, } $api.get(url, data, function (res, err) { api.hideProgress(); if (err) { ctrl.toast("网络请求失败"); } else { if (res.code == 200) { ctrl.renderPrMsg(res.body); } else { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } } }) } // 渲染配电室信息panel ctrl.renderPrMsg = function (data) { $('#pr-msg').empty(); var tpl = ''; tpl += '
配电室联系人:{{people}}
'; tpl += '联系人电话:{{tel}}
'; tpl += '配电室位置:{{province}} {{city}} {{address}}
'; var dom = tpl.replace('{{people}}', data.lxr1) .replace('{{tel}}', data.lxr1Mobile) .replace('{{province}}', data.province) .replace('{{city}}', data.city) .replace('{{address}}', data.address) $api.html($api.dom('#pr-msg'), dom); } // 获取配电室资料列表 ctrl.getPrMsgList = function () { var url = "/ems/rest/pr/file/list"; var data = { prId: ctrl.prId, } $api.get(url, data, function (res, err) { if (err) { ctrl.toast("网络请求失败"); } else { if (res.code == 200 && res.body) { var length = res.body.length; ctrl.baseUrl = res.prefix; $('#pr-msg-list').empty(); for (var i = 0; i < length; i++) { var listItem = res.body[i] $api.append($api.dom('#pr-msg-list'), ctrl.getPrMsgListDOM(listItem)); } } else { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } } }) } // 渲染配电室信息列表 ctrl.getPrMsgListDOM = function (listItem) { var tpl = ''; tpl += '