// 基本信息(包括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: '