apiready = function() { var ctrl = { init: {}, bind: {}, employeeId: null, roleId: null, prList: null, inspectionId: null, xjDate: null, jieDanRenId: null, // inspectionMsg: { // xjDate: '2023-11-21', // inspector: '张三', // workTime: '08:00', // prCount: '10', // prList: [{ // prName: '敦豪配电室', // prId: 1, // count: 1 // }, { // prName: '敦豪配电室1', // prId: 2, // count: 2 // }, { // prName: '敦豪配电室2', // prId: 3, // count: 3 // }] // } } /** * 弹出提示框 */ ctrl.toast = function(msg) { api.toast({ msg: msg, duration: 3000, locaiton: 'top' }); } /** * 显示右侧边栏 */ ctrl.showRightPanel = function() { api.openDrawerPane({ type: 'right', pageParam: { id: 123 }, }); } /** * 新建 保存巡检配电室 */ ctrl.saveCreateInspectPrList = function(inspectionId) { api.showProgress(); var url = '/test/xun-jian-pr/inserts'; var data = []; var PrDomList = $('#prList .pr'); var len = PrDomList.length; if (len) { for (var i = 0; i < len; i++) { var prDom = PrDomList[i]; var prId = $(prDom).data('prid'); var prName = $(prDom).data('prname'); var inspectType = $(prDom).data('inspecttype'); var dataItem = { xunJianDanId: inspectionId, prId: prId, prName: prName, employeeId: ctrl.employeeId, xunJianLeiXing: inspectType } data.push(dataItem) } } $api.post(url, data, function(res, err) { api.hideProgress(); if (err) { ctrl.toast("网络请求失败"); } else { if (!res.code || res.code != "200") { ctrl.toast("服务器响应错误"); } else { // 返回巡检安排列表页 并触发巡检安排页面定义的 inspectionCreateChanged 事件 api.sendEvent({ name: 'inspectionCreateChanged' }); toast("保存成功"); // 关闭当前页,返回到巡检任务列表页 api.closeWin(); } } }); } /** * 编辑 保存巡检配电室 */ ctrl.saveEditInspectPrList = function() { api.showProgress(); var url = '/test/xun-jian-pr/inserts'; var data = []; var PrDomList = $('#prList .pr'); var len = PrDomList.length; if (len) { for (var i = 0; i < len; i++) { var prDom = PrDomList[i]; // var id = $(prDom).data('id'); var prId = $(prDom).data('prid'); var prName = $(prDom).data('prname'); var inspectType = $(prDom).data('inspecttype'); var dataItem = { // id: id, xunJianDanId: ctrl.inspectionId, prId: prId, prName: prName, employeeId: ctrl.employeeId, xunJianLeiXing: inspectType } data.push(dataItem) } } $api.post(url, data, function(res, err) { api.hideProgress(); if (err) { ctrl.toast("网络请求失败"); } else { if (!res.code || res.code != "200") { ctrl.toast("服务器响应错误"); } else { ctrl.toast("修改成功"); // 返回巡检安排列表页 并触发巡检安排页面定义的 inspectionCreateChanged 事件 api.sendEvent({ name: 'inspectionCreateChanged' }); // 关闭当前页,返回到巡检任务列表页 api.closeWin(); } } }); } /** * 新建 保存巡检单 */ ctrl.saveCreateInspect = function() { api.showProgress(); var url = '/test/xun-jian-dan/insert'; var data = { xunJianShiJian: ctrl.xjDate, employeeId: ctrl.employeeId, roleId: ctrl.roleId }; (ctrl.jieDanRenId != '') && (data.jieDanRenId = ctrl.jieDanRenId) $api.post(url, data, function(res, err) { if (err) { ctrl.toast("网络请求失败"); api.hideProgress(); } else { if (!res.code || res.code != "200") { ctrl.toast("服务器响应错误"); api.hideProgress(); } else { ctrl.saveCreateInspectPrList(res.data); } } }); } /** * 编辑 保存巡检单 */ ctrl.saveEditInspect = function() { api.showProgress(); var url = '/test/xun-jian-dan/insert'; var data = { id: ctrl.inspectionId, xunJianShiJian: ctrl.xjDate, employeeId: ctrl.employeeId, roleId: ctrl.roleId }; (ctrl.jieDanRenId != '') && (data.jieDanRenId = ctrl.jieDanRenId) $api.post(url, data, function(res, err) { if (err) { ctrl.toast("网络请求失败"); api.hideProgress(); } else { if (!res.code || res.code != "200") { ctrl.toast("服务器响应错误"); api.hideProgress(); } else { ctrl.saveEditInspectPrList(); } } }); } /** * 保存 */ ctrl.save = function() { api.showProgress({ title: '保存中...', text: '请稍后', modal: false }); // 需要区分“新建”和“修改” if (ctrl.inspectionId != null) { // 修改 ctrl.saveEditInspect() } else { // 新建 ctrl.saveCreateInspect() } } /** * 清空配电室列表 */ ctrl.clearPrList = function() { $("#prList").empty(); } /** * 创建一个配电室DOM */ ctrl.createPrDom = function(prName, prId, inspectType, id) { var type = '例行巡检'; switch (inspectType) { case 1: type = '例行巡检'; break; case 2: type = '特殊巡检'; break; case 3: type = '会诊巡检'; break; case 4: type = '熄灯巡检'; break; }; var template = '' template +='