123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- 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; i<len; i++){
- if(baseInfo.userAgent.uid == teams[i].leaderCode){
- lastTeamId = teams[i].id;
- }
- }
- }
- $('#sortName').text($('#sortList').find('li').eq(typeId-1).find('a').text());//排列初始值
- $('.notice-tip').text('服务类型分组仅支持'+type+'2017年签约居民,如需为2016年签约居民进行操作,请使用健康情况、疾病类型、团队标签或所属居委会分组,或搜索居民单独'+type)
-
- },
- // 初始化画面患者分组列表
- initPatientGroupsList = function() {
- if(!lastTeamId){ return; }
- plus.nativeUI.showWaiting();
- var url = type == "分配" ? 'doctor/family_contract/findNoHealthSignFamilyHealthNum' : '/doctor/family_contract/getPatientLables' ;
- getReqPromise(url,{labelType: typeId, teamCode: lastTeamId,oldDoctorCode:docCode,level:level})
- .then(function(res) {
- if(res.status == 200) {
- console.log(res)
- allGroupMember = []
- allCount= 0;
- groupData = res.data.patients;//储存分组的数据
- if(groupData){
- _.map(groupData,function(item){
- allGroupData.push(item.label);
- allGroupCode.push(item.labelCode);
- if(item.ps.length>0){
- 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);
- })
|