// 基本信息(包括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: '
后台正在处理
', 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: '
发送给
'+amount+'人
', content: '
《'+articleTitle+'》
', 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: '
后台正在处理您的请求,结束后将自动跳转,您可先处理其他事宜
', 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); })