123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- // 基本信息(包括userAgent)
- var baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
-
- var // 搜索
- $searchbar = $('.searchbar'),
- // 搜索取消按钮
- $searchCancelBtn = $('.searchbar-cancel'),
- // 搜索框下面悬浮的搜索提示
- $searchSuggest = $('#search_suggest_text'),
- // 搜索结果展示容器
- $searchtResult = $('#search_result'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap'),
- // 患者分组列表
- $patiList = $('#pati_list'),
- // 居民未分配健管师“点击处理”
- $handleLink = $('#handle_link');
- // 从缓存取出所选团队
- var lastTeamId,
- activeGroupType = "";
- var self;
- var docInfo;
- var labelType = 7;// 标签类型 1:服务类型 2:健康情况 3:疾病类型 4:自定义,5.周月标签 6.老年人标识 7.专病类型,8.健康情况
- var judgeIndex = 0;// 用于判断所选列表
- var assisantHtml = []
- var myScroll,
- startScrollX,
- scrollXd,
- $scrollDom;
- function initScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('#wrapper1').scroll({
- scrollX: true,
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- mui('#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();
- }, 1000);
- }
- },
- scrollLeft: function(){
- xScroll = true;
- }
- });
- }
- /*刷新事件*/
- window.addEventListener("refresh", function refresh(e) {
- $('.lin-mask').hide();
- $('.lin-sel-group').hide();
- getBaseEnvPromise();
- refreshPage();
- getNoTapNumber();
- });
- // 获取登录相关信息
- 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"));
- // 获取医生下未分配标签数目
- getNoTapNumber();
- 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);
- }
- getSpecailType();
- },
- // 滚动框数据渲染
- setListData = function($ele, $noele, html) {
- $ele.empty().append(html);
- if(activeGroupType) {
- $ele.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("tap");
- }
- $noele.hide();
- $ele.show();
- },
- setUnListData = function($ele, $noele) {
- $ele.empty();
- $noele.show();
- $ele.hide();
- },
- // 获取未分配居民数目
- getNoTapNumber = function() {
- var url = "/doctor/specialist/findSpecialistPatientRelationCout";
-
- plus.nativeUI.showWaiting();
- getReqPromise(url, {doctor: docInfo.code},'GET',true)
- .then(function(res) {
- if(res.status == 200) {
- if(!res.data) {
- $(".no-manage-tap").hide();
- $(".setNotapHeight").css({
- 'height':$(window).height()-85
- })
- $("#wrapper").css({
- 'top': '91px',
- 'height': $(window).height()-91
- })
- } else {
- $(".no-manage-tap").show();
- $(".setNotapHeight").css({
- 'height':$(window).height()-150
- })
- $("#wrapper").css({
- 'top': '155px',
- 'height': $(window).height()-155
- })
- $("#no_tap").html(res.data)
- }
- } else {
- plus.nativeUI.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
- },
- // 获取labelType下的label列表
- getSpecailType = function(){
- plus.nativeUI.showWaiting();
- sendPost("/doctor/specialist/findLabelAndPatientCount", {doctor: docInfo.code, type: labelType, teamCode: lastTeamId}, null, function(res){
- plus.nativeUI.closeWaiting();
- if(res.status == 200){
- var data = _.filter(res.data,function(o) {
- return o.label!= 0 || (o.label==0 && o.count > 0);
- });
- if(data && data.length) {
- var html = template("pati_group_tmpl", {list: data});
- setListData($patiList, $noResultWrap, html)
- } else {
- setUnListData($patiList, $noResultWrap)
- }
- } else {
- mui.toast(res.msg || "加载失败!");
- }
- },'GET','',true)
- },
- // 获取未分配计管师居民
- getUnAssistantPat = function(boolean, ele) {// boolean->true 表示只获取列表
- plus.nativeUI.showWaiting();
- var $group;
- if(boolean) {
- $group = ele.find('.patient-list[data-noassisant="'+docInfo.code+'"]')
- }
- sendPost("/doctor/specialist/findPatientNoAssistant", {doctor: docInfo.code, page: 1, size: 50}, null, function(res){
- plus.nativeUI.closeWaiting();
- if(res.status == 200){
- if (boolean) {
- var html = template("pati_list_tmpl", {list: _.map(res.data.detailModelList, function(o) {
- o.jsonStr = JSON.stringify(o);
- return o;
- })});
- $group.find('ul.n-list').empty().append(html);
- showLoadMore($group);
- } else {
- assisantHtml = []
- var obj = {name: "我", doctor: docInfo.code, count: res.data.totalCount}
- assisantHtml.push(obj)
- getPowerList()
- }
- } else {
- mui.toast(res.msg || "加载失败!");
- }
- },'GET','',true)
- },
- // 有权限的获取计管师列表
- getPowerList = function() {
- plus.nativeUI.showWaiting();
- sendPost("/doctor/specialist/findHealthAssistantPatientCount", {doctor: docInfo.code}, null, function(res){
- plus.nativeUI.closeWaiting();
- if(res.status == 200){
- var data = _.filter(res.data,function(o) {
- return o.label != 0 || (o.label==0 && o.count > 0);
- });
- if(data && data.length) {
- var list = assisantHtml.concat(data)
- var html = template("pati_group_tmpl", {list: list});
- setListData($patiList, $noResultWrap, html)
- } else {
- setUnListData($patiList, $noResultWrap)
- }
- } else {
- mui.toast(res.msg || "加载失败!");
- }
- },'GET','',true)
- },
- //显示选中的分组
- 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);
- },
- 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();
- }
- },
- // label下居民列表
- initPatientListByGroup = function(code, ele) {
- var url = "/doctor/specialist/getPatientByLabel";
-
- plus.nativeUI.showWaiting();
- var $group = ele.find('.patient-list[data-group="'+code+'"]');
- getReqPromise(url, {doctor: docInfo.code, labelType: labelType, labelCode: code, page: 1, size: 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(); });
- },
- initSpecailPatientListByGroup = function(assistant, ele) {
- var url = "/doctor/specialist/findPatientRelatioByAssistant";
-
- plus.nativeUI.showWaiting();
- var $group = ele.find('.patient-list[data-code="'+assistant+'"]');
- getReqPromise(url, {assistant: assistant, doctor: docInfo.code, page: 1, size: 50},'GET',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);
- o.healthAssistant = assistant;
- 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;
- },
- refreshPage = function(){
- baseInfo = getBaseInfo();
- lastTeamId = plus.storage.getItem("selectedTeamId");
- if(judgeIndex == 3) {
- getUnAssistantPat()
- } else {
- getSpecailType();
- }
- },
- bindEventFunction = function(ele) {
- ele.on('tap','.load-more',function() {
- plus.nativeUI.showWaiting();
- var $wrap = $(this).closest(".patient-list"),
- code = $wrap.attr("data-group"),
- assistant = $wrap.attr("data-code"),
- page = parseInt($wrap.attr("data-page"));
- var url = code ? "/doctor/specialist/getPatientByLabel" : "/doctor/specialist/findPatientRelatioByAssistant";
- if(code) {
- getReqPromise(url,{doctor: docInfo.code, labelType: labelType, labelCode: code, 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(); });
- } else if(assistant) {
- getReqPromise(url,{assistant: assistant, 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(); });
- } else {
- getReqPromise("/doctor/specialist/findPatientNoAssistant",{doctor: docInfo.code, 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('#wrapper').scroll().scrollTo(0,0,0);
- }
- var code = $.trim($(this).attr("data-group")),
- isOpen = togglePatientListShow($(this)),
- isEmpty = !$(this).find('ul.n-list li').length,
- assistant = $.trim($(this).attr("data-code"));
- ele.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
- code && !isOpen && isEmpty && initPatientListByGroup(code, ele);
- assistant && !isOpen && isEmpty && initSpecailPatientListByGroup(assistant, ele);
- !code && !assistant && !isOpen && isEmpty && getUnAssistantPat(true, ele);
- }).on('tap','li[data-patient-code]',function(e) {
- var patiInfo = $(this).attr("data-json");
- var info = JSON.parse(patiInfo);
- openWebview("../../kfgl/html/denizen.html",{
- patiCode: info.code || info.patient
- })
- 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');
- }
- }
- })
- })
- },
- // 绑定页面事件
- bindEvents = function () {
- $("#con_tit div").on("tap", function() {
- var $this = $(this),
- index = $this.index();
- if($this.hasClass("active")){
- return false;
- }
-
- $this.siblings().removeClass("active");
- $this.addClass("active");
-
- if(index == 0) {
- judgeIndex = 0;
- labelType = 7;
- getSpecailType();
- };
- if(index == 1) {
- judgeIndex = 1;
- labelType = 8;
- getSpecailType();
- };
- if(index == 2) {
- judgeIndex = 2;
- labelType = 4;
- getSpecailType();
- };
- if(index == 3) {
- judgeIndex = 3;
- getUnAssistantPat();
- // getPowerList()
- };
- })
-
-
- bindEventFunction($patiList);
-
- $('.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"));
- showGroupSel(undefined, false);
- if(!$(this).hasClass('checked')){
- $(this).addClass('checked').siblings().removeClass('checked');
- }
- getTeamPatientCount();
- refreshPage();
- });
-
- $searchbar.on('tap',function() {
- var searchPage = plus.webview.getWebviewById('searchPatSpecail');
- if(searchPage){
- mui.fire(searchPage, "initSearch")
- } else {
- mui.openWindow({
- id: "searchPatSpecail",
- url: "../../huanzhe/html/searchPatSpecail.html"
- })
- }
- });
-
- // 跳转分配标签页面
- $(".no-manage-tap").on("tap", function() {
- mui.openWindow({
- url: "../../zhuanbing/html/dingyibiaoqian.html",
- id: "dingyibiaoqian"
- })
- })
-
- $(".list").on("tap", ".operate", function(e) {
- e.preventDefault();
- e.stopPropagation();
- openWebview("../../zhuanbing/html/fenpeijianguanshi.html",{
- patiCode: $(this).attr("data-patient"),
- healthAssistant: $(this).attr("data-healthAssistant")
- })
- }).on('touchstart', '.n-list-link', function(e){ //左滑动作开始
- e.preventDefault();
- startScrollX = e.originalEvent.targetTouches[0].screenX;
- })
- .on('touchmove', '.n-list-link', function(e){ //左滑动作移动
- e.preventDefault();
- scrollXd = e.originalEvent.targetTouches[0].screenX - startScrollX;
- var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
- if(scrollXd<0 && scrollXd >= offLeft)
- $(e.currentTarget).css('left', scrollXd + 'px');
- })
- .on('touchend', '.n-list-link', function(e){ //左滑动作结束
- e.preventDefault();
- if(scrollXd<-50){
- $scrollDom = $(e.currentTarget);
- var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
- $scrollDom.animate({left: offLeft}, "fast");
- } else{
- startScrollX = undefined;
- $scrollDom = undefined;
- $(e.currentTarget).animate({left: '0px'}, "fast");
- }
- scrollXd = undefined;
- xScroll = false;
- myScroll.options.isLeftScroll = false;
- })
-
-
-
- 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('#wrapper1').scroll()
- initScroller();
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- $('.mid-bar').toggle(self.type!=1);
-
- }).then(function() {
- // 获取登录基本信息
- baseInfo = getBaseInfo();
- lastTeamId = plus.storage.getItem("selectedTeamId");
- // 绑定页面事件
- bindEvents();
- initTeams();
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
|