| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |     // 基本信息(包括userAgent)var baseInfo = null,    // 基础环境信息(包括当前webview)    baseEnv = null;    // 搜索输入框var $searchbarInput = $('.search-input'),    // 搜索结果展示容器    $searchtResult = $('#search_result'),    // 搜索无结果时显示    $noResultWrap = $('#no_result_wrap'),    // 患者分组列表    $patiList = $('#pati_list'),    // 所选团队的团队名称显示	$selectedTeamName = $('#selected_team_name'),       //发送数量    $sendCount = '';var lastTeamId,    activeGroupType = "",    typeId = 1, //记录排列的值    sendCount = 0, //记录发送的数量    sendPatiId = []; //记录发送的用户id列表    var origin = '',//搜索来源位置	article=null,//健康文章code	articleTitle = "";//健康文章标题var timeOut,timeOut1;// 获取登录相关信息var getBaseInfo = function() {    var userAgent = JSON.parse(plus.storage.getItem("userAgent"));    var self = plus.webview.currentWebview();        article = self.article;        articleTitle = self.articleTitle;        origin = self.origin;     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;    });},updateLastTeamId = function(id) {    lastTeamId = id;    plus.storage.setItem("selectedTeamId",lastTeamId+"");},updateTypeId = function(id){    typeId = id;    plus.storage.setItem("selectedTypeId",typeId+"");}// 初始化选择团队initTeams = function (){        // 判断缓存中的团队是否在团队列表中    var isExist = _.some(baseInfo.teamInfo.data,function(t) {        return lastTeamId == t.id    });        if(!isExist) {    	if(baseInfo.teamInfo.data.length>0){       	 updateLastTeamId(baseInfo.teamInfo.data[0].id);       }else{       		plus.nativeUI.toast("您还没有任何团队!");       		return;       }    }        template.helper("setChecked", function(id, i) {        if(lastTeamId && lastTeamId==id)            return "checked";        return "";    })        $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo));	if(!lastTeamId && baseInfo.teamInfo.data && baseInfo.teamInfo.data.length) {		updateLastTeamId(baseInfo.teamInfo.data[0].id);		$selectedTeamName.text(baseInfo.teamInfo.data[0].name);		$('.lin-sel-group li').eq(0).addClass("checked");	} else {		var $selected = $('.lin-sel-group').find("li.checked");		$selectedTeamName.text($selected.attr("data-name"));	}        if(typeId){        $(".sel-group li[data-type="+typeId+"]").eq(0).addClass("checked").find("img").attr("src",'../images/checked_all.png');;    }        //切换底部信息footer    var html = template("footer_tmpl", {origin:origin});        $('#patiFooter').append(html);        $sendCount = $("#sendCount");       },//显示选中的分组showGroup = function(type) {    if(type){        activeGroupType = type;    } },showGroupSel = function() {    var isShow = isShow || $('.lin-sel-group:hidden').length != 0;    $('.lin-mask').toggle(isShow);    if($(".sel-group:hidden").length == 0 && isShow){        $('.sel-group').toggle(!isShow);    }    $('.lin-sel-group').toggle(isShow);},showGroupType = function() {    var isShow = isShow || $('.sel-group:hidden').length != 0;    $('.lin-mask').toggle(isShow);    if($(".lin-sel-group:hidden").length == 0 && isShow){        $('.lin-sel-group').toggle(!isShow);    }    $('.sel-group').toggle(isShow);},hideMask = function(){    var isShow = isShow || $('.lin-mask:hidden').length != 0,        isTeamShow = $('.lin-sel-group:hidden').length != 0,        isTypeShow = $('.sel-group:hidden').length != 0;            $('.lin-mask').toggle(isShow);    if(!isTeamShow){        $('.lin-sel-group').toggle(isShow);    }    if(!isTypeShow){        $('.sel-group').toggle(isShow);    }},// 初始化画面患者分组列表initPatientGroupsList = function() {	if(!lastTeamId){		return;	}    getReqPromise("doctor/patient_label_info/label_patient_amount",{labelType: typeId, teamCode: lastTeamId})    .then(function(res) {        if(res.status == 200) {            var data = _.filter(res.data,function(o) {                //过滤团队标签中分组人数为0的数据                if(typeId == 4 && o.amount == 0){                    return false;                }                return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);            });            if(data && data.length) {                var html = template("pati_group_tmpl", {list: data});                $patiList.empty().append(html);                if(activeGroupType) {                    $patiList.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("click");                }                $noResultWrap.hide();                $searchtResult.show();             } else {                $searchtResult.hide();                $noResultWrap.show();            }        }    }).catch(function(e){ console && console.error(e) });;},refreshPage = function(){    baseInfo = getBaseInfo();    lastTypeId = plus.storage.getItem("selectedTypeId");    initPatientGroupsList();},// 绑定页面事件bindEvents = function () {		$patiList.on('click','.patient-list',function(e) {		e.stopPropagation();		var $this = $(this).find('.check-img'),			value = $this.hasClass('checked'),			groupAmount = $this.closest('.patient-list').attr('data-amount');		if(value){		    $this.removeClass('checked');			$this.attr('src','../images/unchecked.png');			$this.closest('.patient-list').find(".n-list-checked").removeClass('checked');		    sendCount -= parseInt(groupAmount);		}else{		    $this.addClass('checked');		 	$this.attr('src','../images/checked_all.png');			$this.closest('.patient-list').find(".n-list-checked").addClass('checked');		    sendCount = sendCount + parseInt(groupAmount);		}		$sendCount.text(sendCount);	})	    function againLoad(){		timeOut1=setTimeout(function(){		    plus.nativeUI.closeWaiting();		    dialog({			    content: '<div class="c-f16 c-323232">后台正在处理</div>',			    okValue: '继续等待',			    cancelValue: '返回首页',			    cancel: function () {					backArticle();			    },			    ok: function() {			    	plus.nativeUI.showWaiting();			    	againLoad()				}			}).showModal();		},30000)	}        function backArticle(){		var view  = plus.webview.getWebviewById("jiankangjiaoyu");		if(view){			mui.fire(view,"refresh");		}		view=plus.webview.getWebviewById("article");		if(view){			mui.fire(view,"refresh");		}		mui.back();    }             $('#sort').on('click', showGroupType);        $('.lin-mask').on('touchstart',function(e){         e.preventDefault();         hideMask();    })    //排列选项    $('.sel-group').on('click', 'li.group-item', function(){        updateTypeId($(this).attr("data-type"));        hideMask();        if(!$(this).hasClass('checked')){            $(this).addClass('checked');            $(this).find('img').attr("src",'../images/checked_all.png');            $(this).siblings().removeClass('checked');            $(this).siblings().find('img').attr('src', '');        }        refreshPage();        $sendCount.text(0);        sendCount=0;    });        $('.demo-comtop h1').on('click', showGroupSel);	$('.lin-mask').on('click', showGroupSel);	$('.lin-sel-group').on('click', 'li', function(){		updateLastTeamId($(this).attr("data-code"));		$selectedTeamName.text($(this).attr("data-name"));		showGroupSel(undefined, false);		if(!$(this).hasClass('checked')){			$(this).addClass('checked').siblings().removeClass('checked');		}		refreshPage();	});        $searchbarInput.on('click',function() {    	if(origin == 'jiaoyu'){        	openWebviewExtras("sousuojumin_more.html",{article:article,origin:origin,articleTitle:articleTitle});        }    });        $("#patiFooter").on('click','#sendBtn',function(){    	var groupList=[];    	var patientList=[];    	var amount = 0;        $(".patient-list").each(function(){        	var groupimg = $(this).find("img.check-img");        	if(groupimg.hasClass("checked")){        		var code = $.trim($(this).attr("data-group"));        		groupList.push(code);        		amount += parseInt($.trim($(this).attr('data-amount')));        	}	        })                if(amount > 0){        	//健康教育模块        	if(origin == 'jiaoyu'){        		dialog({					title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+amount+'人</div></div>',				    content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+articleTitle+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',				    okValue: '立即发送',				    cancelValue: '我再看看',				    cancel: function () {						return;				    },				    ok: function() {				    	var params = {};				        params.code =article;				        params.patient=patientList.join(",");				        params.group=groupList.join(",");				        params.labelType = typeId;				        params.teamCode = lastTeamId;		    			params.attachedContent = $.trim($('#messageInput').val());				        plus.nativeUI.showWaiting();				        sendPost("/doctor/jkEdu/article/doctorSendArticleToPatients",params,sendError,sendSuccess,'POST',2400000);				        				        timeOut=setTimeout(function(){						    plus.nativeUI.closeWaiting();						    dialog({							    content: '<div class="c-f16 c-323232">后台正在处理您的请求,结束后将自动跳转,您可先处理其他事宜</div>',							    okValue: '继续等待',							    cancelValue: '返回首页',							    cancel: function () {									backArticle();							    },							    ok: function() {							    	plus.nativeUI.showWaiting();							    	againLoad();								}							}).showModal();						},30000);										        function sendError(res){							plus.nativeUI.closeWaiting();							window.clearTimeout(timeOut);							window.clearTimeout(timeOut1);							if(res && res.msg){								mui.toast(res.msg);							}else{								mui.toast("发送失败!");							}  							};												function sendSuccess(res){							plus.nativeUI.closeWaiting();							window.clearTimeout(timeOut);							window.clearTimeout(timeOut1);							if(res.status==200){								plus.nativeUI.closeWaiting();						    	mui.toast("发送成功!");								var view  = plus.webview.getWebviewById("jiankangjiaoyu");								if(view){									mui.fire(view,"refresh");								}								view=plus.webview.getWebviewById("article");								if(view){									mui.fire(view,"refresh");								}								mui.back();							}else{								sendError(res);							}						};										    }				}).showModal()		        	}        }else{        	mui.toast("发送人数为0");        }             })           /*刷新事件*/    window.addEventListener("refresh", function refresh(e) {        refreshPage();    });        window.onscroll = function() {        var scrollTop = document.body.scrollTop,            $current = $('.patient-list.current',$patiList).eq(0),            top = $current.length && $current.offset().top;        if($current.length) {            if(scrollTop >= top - 50) {                $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 2});            } else {                $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});            }        }       }};// 页面业务处理流程开始new Promise(function(resolve, reject) {    // TODO 临时放开    //resolve(true);    mui.plusReady(function() {        // hrefhrefplus已经准备好,可以往下执行        resolve(true);    });}).then(function() {      // 获取基础环境信息    return getBaseEnvPromise().then(function(env) {        baseEnv = env;    }).then(function() {        // 获取登录基本信息        baseInfo = getBaseInfo();        lastTeamId = plus.storage.getItem("selectedTeamId");                // 绑定页面事件        bindEvents();        initTeams();        initPatientGroupsList();    });}).catch(function(e) {    plus.nativeUI.closeWaiting();    console && console.error(e);})
 |