apiready = function() { var ctrl = { currentPage: 1, flag: 2, // 处理完(日志) init: {}, //初始化 bind: {}, //事件绑定 toast: {}, //弹出提示框 getRepairLogs: {}, //获取抢修日志 renderRepairLogs: {}, //渲染抢修日志 getLogDom: {} } ctrl.init = function() { ctrl.bind(); ctrl.getRepairLogs(); } //判断是不是在体验模式 ctrl.isCus = function() { if ($api.getStorage('cus')) { return true; } else { return false; } } // 弹出提示框 ctrl.toast = function(msg) { api.toast({ msg: msg, duration: 3000, locaiton: 'top' }); } ctrl.bind = function() { var $startTime = $('#startTime-select'); var $endTime = $('#endTime-select'); var $lbStartTime = $('#lbStartTime'); var $lbEndTime = $('#lbEndTime'); $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("结束日期"); } }) $api.addEvt($api.dom("#query"), "touchend", function() { $api.html($api.dom('#repair-logs'), ''); ctrl.currentPage = 1; ctrl.getRepairLogs(); }); //下拉刷新 api.setRefreshHeaderInfo({ loadingImg: 'widget://image/refresh.png', bgColor: '#ccc', textColor: '#fff', textDown: '下拉刷新...', textUp: '松开刷新...' }, function(ret, err) { $startTime.val(''); $endTime.val(''); $lbStartTime.html("开始日期"); $lbEndTime.html("结束日期"); ctrl.currentPage = 1; ctrl.getRepairLogs(); api.refreshHeaderLoadDone(); }); //上拉加载 api.addEventListener({ name: 'scrolltobottom' }, function(ret, err) { ctrl.currentPage++; if (ctrl.currentPage > ctrl.totalPages) { ctrl.toast("没有更多了"); return; } ctrl.getRepairLogs(); }); //跳转到详情页 $("#repair-logs").on("touchend", ".item", function() { var id = $(this).data('id'); api.openWin({ name: 'repairDetail', url: './repairLogDetail.html', pageParam: { id: id } }); }) } ctrl.getRepairLogs = function() { var $startTime = $('#startTime-select'); var $endTime = $('#endTime-select'); //显示载入动画 api.showProgress({ title: '载入中...', text: '请稍后', modal: false }); var powerRoom = $api.getStorage('powerRoom'); if (powerRoom) { var prId = powerRoom.prId; } else { return; } var dateUtil = new DateUtils(); var pageSize = 20; var startDate = $startTime.val(); if (startDate) { dateUtil.setDate(startDate); startDate = dateUtil.getMillisecond(); } var endDate = $endTime.val(); if (endDate) { dateUtil.setDate(endDate); endDate = dateUtil.getMillisecond(); } // 如果开始时间大于结束时间 交换 startDate && endDate && (startDate > endDate) && (startDate = [endDate,endDate = startDate][0]); var url = '/ems/rest/qx/order/page'; var data = { "page": ctrl.currentPage, "pageSize": pageSize, "prId": prId, "startDate": startDate || null, "endDate": endDate || null, "cusId": $api.getStorage('cusId'), "flag": ctrl.flag // 处理完(日志) }; $api.get(url, data, function(res, err) { if (err) { //隐藏载入动画 api.hideProgress(); ctrl.toast("网络请求失败"); } else { if (!res.code || res.code != 200) { //隐藏载入动画 api.hideProgress(); ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } else { ctrl.renderRepairLogs(res); } } }); } ctrl.renderRepairLogs = function(res) { var logList = res.body.records; if (ctrl.currentPage == 1) { $api.html($api.dom('#repair-logs'), ''); } ctrl.totalPages = res.body.totalPages; if (ctrl.totalPages == 0) { // 隐藏载入动画 api.hideProgress(); api.refreshHeaderLoadDone(); $api.css($api.dom('#repair-logs'), "display:none"); $api.css($api.dom('#repair-log-empty-tips'), "display:block"); } else { var length = logList.length; for (var i = 0; i < length; i++) { $api.append($api.dom('#repair-logs'), ctrl.getLogDom(logList[i])); } //隐藏载入动画 api.hideProgress(); $api.css($api.dom('#repair-logs'), "display:block"); $api.css($api.dom('#repair-log-empty-tips'), "display:none"); } } ctrl.getLogDom = function(item) { var tpl = ''; tpl += '