// 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; // 搜索输入框 var $searchbarInput = $('.search-input'), // 搜索结果展示容器 $searchtResult = $('#search_result'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'), // 所选团队的团队名称显示 $selectedTeamName = $('#selected_team_name'), // 患者分组列表 $patiList = $('#pati_list'), $recordBtn = $('#recordBtn'); var lastTeamId, activeGroupType = "", typeId = "1"; //记录排列的值 var origin,//搜索来源位置 chooseDate, follow_type = 0; //记录随访方式 1-新增随访,2-临时随访 // 获取登录相关信息 var getBaseInfo = function() { var userAgent = JSON.parse(plus.storage.getItem("userAgent")); follow_type = baseEnv.webview.follow_type; var self = plus.webview.currentWebview(); origin = self.origin; chooseDate = self.chooseDate; 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');; } }, //显示选中的分组 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) });; }, 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) { plus.nativeUI.showWaiting(); var $group = $patiList.find('.patient-list[data-group="'+code+'"]'); getReqPromise("doctor/patient_label_info/patients_by_label",{labelType: typeId,labelCode: code, teamCode: lastTeamId, page: 1, pagesize: 50}) .then(function(res) { if(res.status == 200) { //判断父类组是否以选中 console.log(res.data) var groupChecked = $group.find(".check-img").hasClass("checked"); var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) { o.groupChecked = groupChecked; 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(); 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(); //判断是否选中,选中则将所有子元素的选择框选中 var isChecked = $el.find(".check-img").hasClass('checked'); if(isChecked){ $list.find('.n-list-checked').addClass('checked'); } } return isOpen; }, refreshPage = function(){ baseInfo = getBaseInfo(); lastTypeId = plus.storage.getItem("selectedTypeId"); initPatientGroupsList(); }, // 绑定页面事件 bindEvents = function () { $patiList.on('touchstart','.load-more',function() { plus.nativeUI.showWaiting(); var $wrap = $(this).closest(".patient-list"), code = $wrap.attr("data-group"), page = parseInt($wrap.attr("data-page")); getReqPromise("doctor/patient_label_info/patients_by_label",{labelType: typeId,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50}) .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('click','.patient-list',function() { 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('click','.n-list li[data-patient-code]',function(e) { var patiInfo = $(this).attr("data-json"); e.stopPropagation(); patiInfo = JSON.parse(patiInfo); if(origin == 'wdyy'){ openWebview("../../wdyy/html/appointment-register.html",{patient:patiInfo.code}); return false; } if(origin == 'suifang'){ if(follow_type == 1){ openWebview("../../suifang/html/add_plan.html",{patientInfo: patiInfo,chooseDate:chooseDate}); return false; } if(follow_type == 2){ openWebview("../../suifang/html/follow_way.html",{patientInfo: patiInfo}); return false; } } }); $('#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(); }); $('.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 == 'suifang'){ openWebviewExtras("sousuojumin_one.html",{follow_type:follow_type,origin:origin,chooseDate:chooseDate}); }else{ openWebviewExtras("sousuojumin_one.html",{origin:origin}); } }); $recordBtn.on('click',function() { openWebviewExtras("../../wdyy/html/doctor-appointment.html"); }); /*刷新事件*/ 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"); typeId = plus.storage.getItem("selectedTypeId"); if(typeId == null){ typeId = "1"; } if(origin=="wdyy") { $recordBtn.show(); } // 绑定页面事件 bindEvents(); initTeams(); initPatientGroupsList(); }); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });