// 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; // 搜索框 var $searchbar = $('.searchbar'), // 搜索输入框 $searchbarInput = $('.searchbar .search-input'), // 搜索取消按钮 $searchCancelBtn = $('.searchbar-cancel'), // 搜索框下面悬浮的搜索提示 $searchSuggest = $('#search_suggest_text'), // 搜索结果展示容器 $searchtResult = $('#search_result'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'), // 患者分组列表 $patiList = $('#pati_list'), // 所选团队的团队名称显示位置 $selectedTeamName = $('.demo-comtop h1'), // 当医生是当前所选团队的团队长时,如果有居民未分配健管师则显示顶部信息提示 $topMsgBar = $('#top_msg_bar'), // 居民未分配健管师数量显示位置 $unassignedNum = $('#unassigned_num'), // 页面顶部分类标签列表(四个列表项) $groupLabelList = $('#group_label_list'), // 居民未分配健管师“点击处理” $handleLink = $('#handle_link'), $wfp = $('.div-wfp'), $qyjm = $('.div-qyjm'), $qbjm = $('.div-qbjm'), $back = $('.mui-action-back'); // 从缓存取出所选团队 var lastTeamId, activeGroupType = ""; var self; var docInfo; var myScroll; function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ scrollX: true, bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); myScroll = mui(".mui-scroll").pullToRefresh({ down: { callback: function() { var self = this; setTimeout(function() { $('.lin-mask').hide(); $('.lin-sel-group').hide(); refreshPage(); self.endPullDownToRefresh(); showTopMsgBar(); }, 1000); } }, scrollLeft: function(){ xScroll = true; } }); } // 获取登录相关信息 var getBaseInfo = function() { // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, teamInfo: JSON.parse(plus.storage.getItem("teamInfo")) } }, // 获取基础环境信息 getBaseEnvPromise = function () { self = plus.webview.currentWebview(); docInfo = JSON.parse(plus.storage.getItem("docInfo")); 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+""); }, // 初始化选择团队 initTeams = function (){ //判断缓存中的团队是否在团队列表中 var isExist = _.some(baseInfo.teamInfo.data,function(t) { return lastTeamId == t.id }); if(!isExist) { updateLastTeamId(baseInfo.teamInfo.data[0].id); } template.helper("setChecked", function(id, i) { if(lastTeamId && lastTeamId==id) return "checked"; return ""; }); $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo)); var $selected; if(!lastTeamId && baseInfo.teamInfo.data && baseInfo.teamInfo.data.length) { updateLastTeamId(baseInfo.teamInfo.data[0].id); setTitle(baseInfo.teamInfo.data[0].name); $selected = $('.lin-sel-group li').eq(0); $selected.addClass("checked"); } else { $selected = $('.lin-sel-group').find("li.checked"); setTitle($selected.attr("data-name")); } getTeamPatientCount(); $qyjm.toggle($selected.attr('data-leadercode') == docInfo.code); // $qbjm.toggle($selected.attr('data-leadercode') == docInfo.code); }, getTeamPatientCount = function(){ sendPost("/doctor/patient_label_info/team_amount", {teamCode: lastTeamId}, null, function(res){ if(res.status == 200){ $('.div-qyjm label').html("("+ res.data.focusAmount +"/"+ res.data.amount+")"); } else { mui.toast("获取居民总数失败!"); } },'POST','',true) }, getTeamDweller = function(){//获取团队签包居民 sendPost("/doctor/patient_label_info/team_amount", {teamCode: lastTeamId}, null, function(res){ if(res.status == 200){ $('.div-qyjm label').html("("+ res.data.focusAmount +"/"+ res.data.amount+")"); } else { mui.toast("获取居民总数失败!"); } },'POST','',true) }, setTitle = function(title){ if(self.type == 1) $selectedTeamName.html(title + "签约居民管理"); else $selectedTeamName.html(title + '签约居民'); }, //显示选中的分组 showGroup = function(type) { if(type){ activeGroupType = type; } }, showGroupSel = function() { if(self.type == 1) return; var isShow = isShow || $('.lin-mask:hidden').length != 0; $('.lin-mask').toggle(isShow); $('.lin-sel-group').toggle(isShow); }, // 初始化画面患者分组列表 initPatientGroupsList = function() { plus.nativeUI.showWaiting(); var url = self.type == 1 ? "/doctor/patient_label_info/label_team_amount" : "doctor/patient_label_info/label_patient_amount"; getReqPromise(url,{labelType: 1, teamCode: lastTeamId},'POST',true) .then(function(res) { if(res.status == 200) { var data = _.filter(res.data,function(o) { 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("tap"); } $noResultWrap.hide(); $searchtResult.show(); } else { $searchtResult.hide(); $noResultWrap.show(); } } plus.nativeUI.closeWaiting(); }).catch(function(e){ plus.nativeUI.closeWaiting(); console && console.error(e) });; }, showLoadMore = function($el) { var amount = $el.attr("data-amount"), loaded = $el.find('ul.n-list li').length, $loadMore = $el.find('.load-more'); if(amount>loaded) { $loadMore.show(); } else { $loadMore.hide(); } }, initPatientListByGroup = function(code) { var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label"; plus.nativeUI.showWaiting(); var $group = $patiList.find('.patient-list[data-group="'+code+'"]'); getReqPromise(url, {labelType:1, teamCode: lastTeamId, labelCode: code, page: 1, pagesize: 50},'POST',true) .then(function(res) { if(res.status == 200) { var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) { o.jsonStr = JSON.stringify(o); return o; })}); $group.find('ul.n-list').empty().append(html); showLoadMore($group); } else { plus.nativeUI.toast(res.msg); } plus.nativeUI.closeWaiting(); }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); }); }, togglePatientListShow = function($el) { var isOpen = $el.hasClass("current"), $list = $el.find('ul.n-list'), $siblings = $el.siblings('.patient-list'); if(isOpen) { $el.removeClass("current"); $list.hide(); $el.find('.load-more').hide(); } else { $el.addClass("current"); showLoadMore($el); $siblings.removeClass('current').find("ul.n-list").hide(); $siblings.find('.load-more').hide(); $list.show(); } return isOpen; }, showTopMsgBar = function() { if(baseEnv.webview.message){//“转发给”功能,需要返回按钮 return false; } var leadCode = $(".lin-sel-group li.checked").attr("data-leaderCode"); $qyjm.toggle(leadCode==docInfo.code); // $qbjm.toggle(leadCode==docInfo.code); if($.trim(leadCode) == $.trim(baseInfo.userAgent.uid)) { getReqPromise("doctor/family_contract/findNoHealthSignFamilyNum",{doctor: leadCode, teamCode: lastTeamId},'POST',true) .then(function(res){ if(res.status == 200) { if(parseInt(res.data.num)) { $('.div-wfp label').html("("+ res.data.num +")"); $wfp.show(); } else { $wfp.hide(); } } }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); }); } else { $wfp.hide(); } }, refreshPage = function(){ baseInfo = getBaseInfo(); lastTeamId = plus.storage.getItem("selectedTeamId"); initPatientGroupsList(); getTeamPatientCount(); }, // 绑定页面事件 bindEvents = function () { $patiList.on('tap','.load-more',function() { plus.nativeUI.showWaiting(); var $wrap = $(this).closest(".patient-list"), code = $wrap.attr("data-group"), page = parseInt($wrap.attr("data-page")); var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : (self.type == 2 ?"doctor/patient_label_info/qianbao_by_label":"doctor/patient_label_info/patients_by_label"); getReqPromise(url,{labelType: 1,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50},'POST',true) .then(function(res) { if(res.status == 200) { var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) { o.jsonStr = JSON.stringify(o); return o; })}); $wrap.find('ul.n-list').append(html); $wrap.attr("data-page",page+1); showLoadMore($wrap); } plus.nativeUI.closeWaiting(); }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); }); return false; }).on('tap','.patient-list',function() { if($(".patient-list.current").length>0 && !$(this).hasClass('current')){ mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,0); } var code = $.trim($(this).attr("data-group")), isOpen = togglePatientListShow($(this)), isEmpty = !$(this).find('ul.n-list li').length; $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"}); code && !isOpen && isEmpty && initPatientListByGroup(code); }).on('tap','li[data-patient-code]',function(e) { var patiInfo = $(this).attr("data-json"); var info = JSON.parse(patiInfo); if(baseEnv.webview.message) { openWebview("../../message/html/p2p.html",{otherCode: info.code,otherName: info.name,otherPhoto: info.photo,otherSex: info.sex}); } else { openWebview("../../huanzhe/html/huanzhexinxi.html",{ teamCode: self.type==1? lastTeamId : undefined, patiInfo: patiInfo, patiCode: info.code }); } return false; }).on('tap','.patient-type-big',function(){ var self = $(this); var groupType = self.attr('data-groupindex'); $('.patient-list').each(function(i,el){ if($(el).attr('data-parent') == groupType){ if(!$(el).hasClass('show')){ $(el).show().addClass('show'); self.addClass('current'); }else{ $(el).hide().removeClass('show'); self.removeClass('current'); } } }) }) $('.demo-comtop h1').on('tap', showGroupSel); $('.lin-mask').on('tap', showGroupSel).on('touchmove',function() { return false; }); $('.lin-sel-group').on('touchmove',function() { // return false; }); $('.lin-sel-group').on('tap', 'li', function(){ updateLastTeamId($(this).attr("data-code")); setTitle($(this).attr("data-name")); showGroupSel(undefined, false); if(!$(this).hasClass('checked')){ $(this).addClass('checked').siblings().removeClass('checked'); } showTopMsgBar(); getTeamPatientCount(); refreshPage(); }); $topMsgBar.on('tap','.close-btn',function(){ $topMsgBar.hide(); }); $groupLabelList.on('tap',"li.group-item",function() { openWebview("../../huanzhe/html/huanzhe-by-type.html",{ type: self.type, accessData: { labelType: $(this).attr("data-type"), typeName: $(this).find(".item-label").text() }, message: baseEnv.webview.message}); }) $groupLabelList.on('tap',"li.group-qytx",function() { openWebview("../../huanzhe/html/huanzhe-tijian.html",{ type: self.type, accessData: { labelType: $(this).attr("data-type"), typeName: $(this).find(".item-label").text() }, message: baseEnv.webview.message}); }) $searchbarInput.on('tap',function() { var searchPage = plus.webview.getWebviewById('searchhuanzhe'); if(searchPage){ mui.fire(searchPage, "initSearch", { msgForward: "", type: self.type }) } if(self.type == 1){ mui.openWindow({ id: "searchhuanzhe2", url: "../../huanzhe/html/searchhuanzhe.html", extras: { msgForward: "", type: 1 } }) }else{ mui.openWindow({ id: "searchhuanzhe", url: "../../huanzhe/html/searchhuanzhe.html", extras: { msgForward: "", type: self.type } }) } }); $handleLink.on('click',function() { openWebview("../../tuandui/html/xuanzezhuanyijumin.html",{ docCode: baseInfo.userAgent.uid, teamCode: lastTeamId, type: "dfp" }); }); $wfp.on('tap', function(){ mui.openWindow({ id: "zhuanyijumin", url: "../../search/html/zhuanyijumin.html", extras: { type: "分配", teamCode: lastTeamId, } }); return; openWebview("../../tuandui/html/fp-xuanzejumin.html",{ docCode: "", teamCode: lastTeamId, type: "dfp" }); }) $qyjm.on('tap', function(){ var $team = $('.lin-sel-group li.checked'); mui.openWindow("huanzhe.html", "quanbu-huanzhe", { extras: { type: 1, teamName: $team.attr('data-name') } }) }) $qbjm.on('tap', function(){ var $team = $('.lin-sel-group li.checked'); mui.openWindow("huanzhe.html", "quanbu-huanzhe", { extras: { type: 2, teamName: '团队服务包' } }) }) /*刷新事件*/ window.addEventListener("refresh", function refresh(e) { $('.lin-mask').hide(); $('.lin-sel-group').hide(); refreshPage(); }); window.addEventListener("refreshWfp", function refresh(e) { showTopMsgBar(); }); 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": 9999}); } 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() { mui('.mui-scroll-wrapper').scroll() initScroller(); // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; if(self.type == 1){ $back.show(); setTitle(self.teamName); }else if(self.type == 2){ $groupLabelList.hide(); setTitle(self.teamName); } $('.mid-bar').toggle(!self.type); }).then(function() { // 获取登录基本信息 baseInfo = getBaseInfo(); lastTeamId = plus.storage.getItem("selectedTeamId"); // 绑定页面事件 bindEvents(); initTeams(); showTopMsgBar(); initPatientGroupsList(); if(baseEnv.webview.message){//“转发给”功能,需要返回按钮 $(".mui-action-back").show(); } }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });