var self; var docInfo; var checkeds = {}, num = 0; var teamCode; var searchRs; mui.plusReady(function(){ self = plus.webview.currentWebview(); docInfo = JSON.parse(plus.storage.getItem('docInfo')); searchRs = self.searchRs; teamCode = self.teamCode; num = self.num; checkeds = self.checkeds; showPatients(); }) template.helper('isChecked', function(v){ return checkeds[v]? 'checked' : ''; }) template.helper('toInfo', function(v){ return JSON.stringify(v); }) template.helper("setPhoto", function(p) { return getImgUrl(p); }); function showPatients(){ plus.nativeUI.showWaiting(); showNum(); var data; if(self.searchType == 'sa'){ data = searchRs.address; } else data = searchRs.name; $('#pati_list').html(template('pati_tmpl', {list: data})); plus.nativeUI.closeWaiting(); mui(document).imageLazyload({ placeholder: '../../../images/p-female.png' }); } var $list = $('#listDiv'); $('.content').on('tap', '.rs-checkbox.l-checkbox', function(){ //选择、取消居民 var $li = $(this).parent(); var code = $li.attr('data-code'); var info = JSON.parse($li.attr('data-info')); var isChecked = !$li.hasClass('checked'); $li.toggleClass('checked'); toggleChecked(code, isChecked, info); showNum(); //通知父窗口修改状态 updateParent([code], isChecked); return false; }) $('#allSel').on('tap', function(){ var checked = !$('#allSel').hasClass('checked'); var codes = [], code; if(checked){ $('#allSel').addClass("checked").next().html("取消全选"); $.each($('#listDiv .n-list-link[class!="checked"]'), function(i, v) { code = $(v).attr('data-code'); codes.push(code); $(v).addClass('checked'); addChecked(code, JSON.parse($(v).attr('data-info'))); }); } else{ $('#allSel').removeClass("checked").next().html("全选"); var $lis = $('#listDiv .n-list-link.checked'); $.each($('#listDiv .n-list-link.checked'), function(i, v) { code = $(v).attr('data-code'); codes.push(code); $(v).removeClass('checked'); removeChecked($(v).attr('data-code'), JSON.parse($(v).attr('data-info'))); }); } showNum(); updateParent(codes, checked); }) function updateParent(codes, isChecked){ mui.fire(self.opener(), 'updateChecked', {codes: codes, isChecked: isChecked}) } function showNum(){ $('.checked-num label').html(num); } function toggleChecked(code, isCheck, info){ if(isCheck) addChecked(code, info); else removeChecked(code); } function addChecked(code, info){ if(!checkeds[code]){ num++; checkeds[code] = info; } } function removeChecked(code){ if(checkeds[code]){ num--; delete checkeds[code]; } } /** * 下一步操作 */ function submit(){ if(num<=0) return; plus.nativeUI.showWaiting(); var patients = [], patiCodes = []; for(var k in checkeds){ patiCodes.push(k); patients.push(checkeds[k]); } if(self.type=='分配'){ to_next(patients); return; } sendPost("/doctor/consult/getConsultByPatientAndDoctor", {patientCode: patiCodes.join(","), doctor: self.docCode}, null, function(res){ var tem = {}; if(res.length==0){ to_next(patients); } else if(patients.length == res.length){ plus.nativeUI.closeWaiting(); mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){ }) return; } else if(res.length <= 3 ){ tem = getCanTrans(patients, res); mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){ if(e.index == 0){ to_next(tem.canPati); cancleSel(res); } }) } else if(res.length < patients.length){ tem = getCanTrans(patients, res); mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){ if(e.index == 0){ to_next(tem.canPati); cancleSel(res); } }) } else{ } plus.nativeUI.closeWaiting(); }) } function getCanTrans(patients, notCodes){ var canPati = []; var names = []; $.each(patients, function(i, v) { var has = false; $.each(notCodes, function(n, m) { if(v.code == m){ has = true; names.push(v.name); } }); if(!has){ canPati.push(v); } }); return {canPati: canPati, names: names.join(",")} } function cancleSel(notCodes){ var $ul, $prev, len; $.each(notCodes, function(i, c) { var $lis = $('#listDiv .n-list-link[data-code="'+ c +'"]'); $.each($lis, function(i, v) { $(v).removeClass('checked'); $ul = $(v).closest('ul'); $prev = $ul.prev(); len = $(v).closest('ul').find('li.checked').length; if(len==0) $prev.removeClass('checked').removeClass('incomplete'); else if(len==$ul.parent().attr('data-amount')) $prev.removeClass('incomplete').addClass('checked'); else $prev.removeClass('checked').addClass('incomplete'); }); removeChecked(c); }); showNum(); } function to_next(patients){ mui.openWindow({ id: "xuanzejieshouyisheng.html", url: "xuanzejieshouyisheng.html", extras: { patients: patients, docCode: self.docCode, teamCode: teamCode, type: self.type, level: self.level } }); }