var baseInfo = null,// 基本信息(包括userAgent) baseEnv = null, // 基础环境信息(包括当前webview) self, $searchbarInput = $('.icon-sousuo-btn'),// 搜索输入框 $sendCount = $("#sendCount");//发送数量 var lastTeamId, typeId = 1, //记录排列的值 sendCount = 0, //记录发送的数量 groupId = 0,//记录分组的值 groupName = '',//记录分组的名字 groupData = '',//记录分组的所有数据 type,//转移或分配 docCode,//医生code level,//2全科 3健管 allCount,//所有人数 allGroupData=[],//所有组的数据信息 allGroupCode=[],//所有组的数据code allGroupMember=[],//所有组的成员 allPatient,//所有成员的patint groupIdFornum; // 获取登录相关信息 var getBaseInfo = function() { var userAgent = JSON.parse(plus.storage.getItem("userAgent")); self = plus.webview.currentWebview(); docCode = self.docCode; level = self.level; type = self.type; return { userAgent: userAgent, teamInfo: JSON.parse(plus.storage.getItem("teamInfo")) } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // 初始化选择团队 initTeams = function (){ // lastTeamId = self.teamCode; //从消息列表过来的处理是没有团队code,能够分配健管师的只能是团队长 20171110 rl update if(self.teamCode){ lastTeamId = self.teamCode; }else{ var teams = baseInfo.teamInfo.data, len = teams.length; for(i=0; i0){ allGroupMember = allGroupMember.concat(item.ps); } }) allGroupCode = _.uniq(allGroupCode); console.log(allGroupMember.length) allPatient = allGroupMember.map(function(v){ //将所有的重复的paitent取出来 return v.patient }).filter(function(v,i,arr){ return arr.indexOf(v) === i //过滤掉相同的paitent }).map(function(v){ return { use:false, patient:v //增加use属性准备对象去重 } }) console.log(allPatient); var filterArr = []; allGroupMember.filter(function(value,index,arr){ allPatient.map(function(v,i,arr){ if(value.patient == v.patient && v.use ==false){ // if(value.photo && value.photo.indexOf('../') == -1){ value.photo = getImgUrl(value.photo); } if(value.age <=0){ value.age ='<1' } filterArr.push(value); allPatient[i].use =true; } }) }); allGroupMember = filterArr; allCount+=allGroupMember.length; // allCount = allGroupCode.length; } if(typeId = 3){ var other = _.find(groupData, function(v) { return v.label == "其他疾病" }); var arr = _.filter(groupData, function(v) { return v.label != "其他疾病" }) || []; other && arr.push(other); groupData = arr; } var html = template("groups_tmpl", {list: groupData}); $('#groupList').empty().append(html); countHeight(groupData); changeGroupNum($('#groupList').find('li').eq(0)); // mui('#scrol1').scroll({ // bounce: false //是否启用回弹 // }).scrollTo(0,0,100); mui('#scrol2').scroll({ bounce: false //是否启用回弹 }).scrollTo(0,0,100); plus.nativeUI.closeWaiting(); } if(res.status == -1){ plus.nativeUI.closeWaiting(); mui.toast('数据获取失败'); } }).catch(function(e){ console && console.error(e) });; }, countHeight = function(data){ var num = data.length; if(num>5){ $('#sheet3_area').css('height','276px'); }else{ $('#sheet3_area').css('height',46*(num+1)); } }, changeGroupNum = function(obj){ var groupNum,perGroup, groupId = obj.data('id');//储存组的位置 groupIdFornum = groupId; $('#groupName').text(obj.find('a').text()); //groupId=0为全部分组 if(groupId>0){ groupNum = groupData[groupId-1].ps.length; groupName = groupData[groupId-1].label; perGroup = groupData[groupId-1].ps; allGroupMember = allGroupMember.map(function(value){ //过滤掉其他组的 needHide=true var needHide =true; perGroup = perGroup.map(function(v){ if(v.patient == value.patient){ v.isCheck =value.isCheck needHide = false } return v }) value.needHide =needHide; return value }) }else{ allGroupMember = allGroupMember.map(function(v){ v.needHide = false; return v }) groupNum = allCount; groupName = ''; perGroup = allGroupMember; } refreshCount(); var html = template("num_tmpl",{data:groupNum}); $('#numList').empty().append(html); $('#peopleNum').text($('#numList').find('li').eq(0).find('a').text()); var isAllCheck = (groupNum == sendCount); var html2 = template("members_tmpl",{data:{data:perGroup,allChecked:isAllCheck}}); $('#memberList').empty().append(html2); mui('.mui-scroll-wrapper').scroll({ deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006 }); }, changePeopleNum = function(obj){ $('#peopleNum').text(obj.find('a').text()); var filterNumber = obj.data('num'); if(groupIdFornum>0){ perGroup = groupData[groupIdFornum-1].ps; perGroup = perGroup.map(function(v){ allGroupMember.map(function(value){ if(v.patient == value.patient){ v.isCheck =value.isCheck; inAllGroup =true; v.needHide= value.needHide; } }) return v }) }else{ perGroup = allGroupMember; } perGroup = perGroup.map(function(v,i,arr){ if(i+1 >filterNumber){ v.needHide = true } else{ v.needHide = false } return v }) allGroupMember = allGroupMember.map(function(value){ perGroup.map(function(v,i,arr){ if(v.patient == value.patient){ value.needHide = v.needHide; } }) return value }) refreshCount(); var isAllCheck = (filterNumber == sendCount); var html2 = template("members_tmpl",{data:{data:perGroup,allChecked:isAllCheck}}); $('#memberList').empty().append(html2); mui('.mui-scroll-wrapper').scroll({ deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006 }); if(sendCount>0){ $('#sendBtn').addClass('active');//变色 }else{ $('#sendBtn').removeClass('active'); } }, refreshCount =function (){ sendCount = allGroupMember.filter(function (v){ return v.isCheck && !v.needHide }).length $sendCount.text(sendCount);//发送人数 }, // 绑定页面事件 bindEvents = function () { $('#sortList').on('click','.j-choose-name',function(){ var $this = $(this); $('#sortName').text($this.find('a').text()); typeId = $this.data('type'); mui('#sheet2').popover('toggle'); initPatientGroupsList(); $sendCount.text(0); sendCount=0; groupId = 0; allGroupData=[];//所有组的数据信息 allGroupCode=[]; }) $('#groupList').on('click','.j-choose-name',function(){ var $this = $(this); changeGroupNum($this); mui('#sheet3').popover('toggle'); }) $('#numList').on('click','.j-choose-name',function(){ var $this = $(this); changePeopleNum($this); mui('#sheet4').popover('toggle'); }) $('#memberList').on('click','.memberClick',function(){ var $this = $(this), memberObj = $('.memberClick'); memberId = $this.data('id'),//储存组的位置 value = $this.find('input').prop('checked'), patient =$this.data('code'); if(memberId>0){ allGroupMember = allGroupMember.map(function(v){ if(v.patient == patient){ if(value){ v.isCheck =true } else{ v.isCheck=null } } return v }) } else{ $("input[name='memberList']:checkbox").each(function() { $(this).prop("checked", value); }); allGroupMember = allGroupMember.map(function(v){ if(value){ v.isCheck =true } else{ v.isCheck=null } return v }) } refreshCount(); }) $searchbarInput.on('click',function() { mui.openWindow({ id: "zhuanyijumin_search", url: "zhuanyijumin_search.html", extras: { type:type, docCode:docCode, level:level, lastTeamId:lastTeamId, } }); }) $("#sendBtn").on('click',function(){ if(sendCount<=0){ mui.toast('请至少选一个居民!'); return; } plus.nativeUI.showWaiting(); //取居民code var pCode=[], patientArr=[]; allGroupMember.map(function(v){ if(v.isCheck && !v.needHide){ pCode.push(v.patient) } }) pCode = pCode.join(','); if(type == '转移'){ sendPost("/doctor/consult/getConsultByPatientAndDoctor", {patientCode: pCode, doctor: docCode},null, function(res){ var tem = {}; console.log(res) if(res.length==0){ to_next(pCode); } else if(res.length == sendCount){ console.log(res) plus.nativeUI.closeWaiting(); mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){}) return; } else if(res.length <= 3 ){ tem = getCanTrans(pCode, res); console.log(tem); plus.nativeUI.closeWaiting(); mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){ if(e.index == 0){ to_next(tem.canPati); cancleSel(res); } }) } else if(res.length < sendCount){ tem = getCanTransByCode(pCode, res); plus.nativeUI.closeWaiting(); mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){ if(e.index == 0){ to_next(tem.canPati); cancleSel(res); } }) } },'POST',300000) }else{ to_next(pCode) return; } }) function getCanTrans(pCode, notCodes){ var canPati = []; var names = []; var allCode = pCode.split(','); $.each(allCode, function(i, v) { var has = false; $.each(notCodes, function(n, m) { if(v == m){ has = true; var obj = _.find(allGroupMember, function(o){ return o.patient== m; }); names.push(obj.name); } }); if(!has){ canPati.push(v); } }); return {canPati: canPati.join(","), names: names.join(",")} } function getCanTransByCode(pCode, notCodes){ var canPati = []; var allCode = pCode.split(','); $.each(allCode, function(i, v) { var has = false; $.each(notCodes, function(n, m) { if(v == m){ has = true; } }); if(!has){ canPati.push(v); } }); return {canPati: canPati.join(",")} } function cancleSel(notCodes){ sendCount = sendCount*1 - (notCodes.length)*1 } function to_next(pCode){ mui.openWindow({ id: "choose_doctor.html", url: "../../tuandui/html/choose_doctor.html", extras: { teamCode: lastTeamId, sendCount:sendCount, patients:pCode, level: level, docCode:docCode, type:type } }) } }; // 处理流程开始 new Promise(function(resolve, reject) { mui.plusReady(function() { resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录基本信息 baseInfo = getBaseInfo(); // 绑定页面事件 bindEvents(); initTeams(); initPatientGroupsList(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); })