apiready = function() { var ctrl = { init: {}, bind: {}, orderData: { pics: [], serverPicUrls: [], uploadPicNum: 0, desc: '', prId: null, }, }; ctrl.init = function() { CommonModel.fitInStatusBar(); ctrl.employeeId = $api.getStorage('employeeId'); ctrl.roleId = $api.getStorage('roleId'); ctrl.prListDom = $('#pr-list'); ctrl.inspectorGroup = $("#inspector-group"); ctrl.bind(); ctrl.initPrList(); } ctrl.bind = function() { //点击返回按钮 $api.addEvt($api.dom("#back"), "touchend", function() { api.closeWin(); }); // 点击 配电室下拉选择框 $api.addEvt($api.dom("#pr-selected"), "touchend", function() { $('.pr-picker-modal').toggleClass('show'); }); // 选择配电室 $("#pr-list").on("touchend", ".pr", function () { ctrl.orderData.prId = $(this).data('prid'); var prName = $(this).data('prname'); $('#pr-name').text(prName); $('.pr-picker-modal').removeClass('show'); }); // 点击 相册选择 添加 设备缺陷图片 $("#pic-add-btn").on("touchend", function () { var picContentDom = $('#pic-content'); var params = { sourceType: 'library', // sourceType: 'camera', // sourceType: 'album', destinationType: 'base64' } api.getPicture(params, function(ret, err){ if (ret && ret.data) { // 创建图片预览dom var picItemDom = '' var dom = picItemDom.replace('{{url}}', ret.data) picContentDom.prepend(dom) // 保存 图片 base64 和 url ctrl.orderData.pics.push({ url: ret.data }); } }) }); // 点击 照相机 拍照添加 设备缺陷图片 $("#camera-btn").on("touchend", function () { var picContentDom = $('#pic-content'); var params = { // sourceType: 'library', sourceType: 'camera', // sourceType: 'album', destinationType: 'base64' } api.getPicture(params, function(ret, err){ if (ret && ret.data) { // 创建图片预览dom var picItemDom = '' var dom = picItemDom.replace('{{url}}', ret.data) picContentDom.prepend(dom) // 保存 图片 base64 和 url ctrl.orderData.pics.push({ url: ret.data }); } }) }); // 点击图片预览 $("#pic-content").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'); }); // 图片 删除按钮 $("#pic-content").on("touchend", "i", function (e) { e.stopPropagation(); var _this = this; api.confirm({ title: '', msg: '确定要删除吗', buttons: ['确定', '取消'] }, function(ret, err) { var index = ret.buttonIndex; if (index == 1) { // 确定 var url = $($(_this).siblings('img')[0]).attr('src'); $(_this).parent('.pic-item').remove(); // 从 ctrl.orderData.pics 中删除对应url ctrl.orderData.pics = ctrl.orderData.pics.filter(function (item) { return item.url != url; }); } }); }); // 点击“保存” $("#save-btn").on("touchend", function () { api.confirm({ title: '', msg: '确定要保存吗', buttons: ['确定', '取消'] }, function(ret, err) { var index = ret.buttonIndex; if (index == 1) { // 确定 ctrl.save(); } }); }); }; // 初始化 prList 下拉框 ctrl.initPrList = function () { ctrl.getPrList(); ctrl.getInspectorList(); }; /** * 获取人员列表 */ ctrl.getInspectorList = function() { // 判断当前登陆的账号是否是自己员工 var isZTZ = $api.getStorage('isZTZ'); var isXJZZ = $api.getStorage('isXJZZ'); var url; var data; var flag; if (isZTZ || isXJZZ) { // ZTZ || XJZZ url = '/ems/rest/xj/schedule/task/employee'; flag = true; } else { // KHZZ || KHZBZ 客户员工 站长 || 值长 url = '/ems/rest/employee/getEmployeeByEmployeeId'; flag = false; } data = { employeeId: $api.getStorage('employeeId') }; api.showProgress({ title: '载入中...', text: '请稍后', modal: false }); $api.get(url, data, function(res, err) { api.hideProgress(); if (err) { ctrl.toast("网络请求失败"); } else { if (!res.code || res.code != "200" || !res.body) { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } else { if (flag) { ctrl.renderInspectorList(res.body) } else { ctrl.renderInspectorList(res.body.records) } } } }); }; /** * 渲染人员列表 */ ctrl.renderInspectorList = function(inspectorlist) { var len = inspectorlist.length; var temp = ''; ctrl.inspectorGroup.empty(); ctrl.inspectorGroup.append(''); for (var i = 0; i < len; i++) { var inspectorItem = inspectorlist[i] var domStr = '' domStr = '' domStr = domStr.replace("{inspector}", inspectorItem.employeeName) .replace("{inspectorId}", inspectorItem.employeeId); temp += domStr; } ctrl.inspectorGroup.append(temp); //为巡检人员绑定事件 ctrl.bindSwitchButtonEvent(ctrl.inspectorGroup.children()); } /** * 人员 选择按钮 点击事件绑定 * @param {zepto object} buttons */ ctrl.bindSwitchButtonEvent = function(buttons) { for (var i = 0; i < buttons.length; i++) { var btn = $(buttons[i]); btn.on('touchend', ctrl.switchButtonClicked); } } /** * 人员 按钮点击 事件处理函数 */ ctrl.switchButtonClicked = function() { var sender = $(this); var brothers = sender.parent().children(); for (var i = 0; i < brothers.length; i++) { var inputElement = $(brothers[i]); inputElement.removeClass("btn-highlight"); } sender.addClass("btn-highlight"); ctrl.inspectorButton_clicked(sender); } // 人员选择 ctrl.inspectorButton_clicked = function(dom) { var employeeId = dom.data('inspectorid'); var employeeName = dom.val(); ctrl.handleEmployeeId = employeeId; ctrl.handleEmployeeName = employeeName; } // 获取配电室列表 ctrl.getPrList = function () { var url = '/ems/rest/power/room/list'; var data = { employeeId: ctrl.employeeId, roleId: ctrl.roleId } api.showProgress({ title: '载入中...', text: '请稍后', modal: false }); $api.get(url, data, function(res, err) { api.hideProgress(); if (err) { ctrl.toast("网络请求失败"); } else { if (!res.code || res.code != "200" || !res.body) { ctrl.toast("服务器响应错误" + (res.code ? (",错误码:" + res.code) : "")); } else { ctrl.renderPrList(res.body); } } }); }; // 渲染配电室下拉框 ctrl.renderPrList = function (data) { var len = data.length; var temp = ''; ctrl.prListDom.empty(); for (var i = 0; i < len; i++) { var prItem = data[i]; var domStr = ''; domStr += '