var baseInfo = null, baseEnv = null; var $searchtResult = $('#search_result'), $container = $('.container'), $noResultWrap = $('#no_result_wrap'), // 搜索无结果时显示 $patiList = $('#pati_list'),// 患者分组列表 $selectedTeamName = $('#selected_team_name'),// 所选团队的团队名称显示 $searchBtn = $('#search_btn'),//搜索输入 $searchList = $('.xz-search'),//搜索结果展示 $searchUl = $('#search_ul'), $sendCount = $("#sendCount"),//发送数量 $hisSearList = $('#his_sear_list'), $history = $(".xz-history"),//历史记录 $navInput = $('.xz-sel-list');//搜索输入和选中结果展示 var lastTeamId, docInfo, tagTitle = 1,//头部切换 search_keyword='',//搜索关键字 activeGroupType = "", typeId = 1, //记录排列的值 sendCount = 0, //记录发送的数量 historyData=[],//历史数据 historyStr, sendPatiId = []; //记录发送的用户id列表 var origin = '',//搜索来源位置 sPage = 1, sPagesize = 30, 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; }, updateTypeId = function(id){ typeId = id; } // 初始化选择团队 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{ mui.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; } plus.nativeUI.showWaiting(); getReqPromise("doctor/patient_label_info/label_patient_amount",{labelType: typeId, teamCode: lastTeamId}) .then(function(res) { plus.nativeUI.closeWaiting(); 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) { if(tagTitle == 2){ var html = template("pati_group_tmpl_2", {list: data}); }else{ 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(); } $container.show() } }).catch(function(e){ plus.nativeUI.closeWaiting();console && console.error(e) }); }, initPatientListByGroup = function(code) { var url = "doctor/patient_label_info/patients_by_label"; plus.nativeUI.showWaiting(); var $group = $patiList.find('.patient-list[data-group="'+code+'"]'); getReqPromise(url, {labelType:typeId, teamCode: lastTeamId, labelCode: code, page: 1, pagesize: 30,isFollowWeChat:true},'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); checkIsSelect() } else { plus.nativeUI.toast(res.msg); } plus.nativeUI.closeWaiting(); }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); }); }, 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(); } }, checkIsSelect = function(){ var selectStr = sendPatiId.join(',') var $ul = $container.find('.n-list-link') $ul.map(function(i){ var code = $ul.eq(i).attr('data-patient-code') if(selectStr.indexOf(code)>-1){ $ul.eq(i).addClass('checked') $ul.eq(i).find('.check-img').attr('src','../images/checked_all.png'); }else{ $ul.eq(i).removeClass('checked') $ul.eq(i).find('.check-img').attr('src','../images/unchecked.png'); } }) }, checkIsSelect2 = function(){ var selectStr = sendPatiId.join(',') var $ul = $searchUl.find('.n-list-link') $ul.map(function(i){ var code = $ul.eq(i).attr('data-patient-code') if(selectStr.indexOf(code)>-1){ $ul.eq(i).addClass('checked') $ul.eq(i).find('.check-img').attr('src','../images/checked_all.png'); }else{ $ul.eq(i).removeClass('checked') $ul.eq(i).find('.check-img').attr('src','../images/unchecked.png'); } }) }, 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"); // $siblings.removeClass('current').find("ul.n-list").hide(); // $siblings.find('.load-more').hide(); $list.show(); showLoadMore($el); } return isOpen; }, // 分页查询列表 searchByPaging = function () { search_keyword = $searchBtn.val(); if(!$.trim(search_keyword)) { return ; } plus.nativeUI.showWaiting(); // page: 分页索引,filter:搜素关键字,pagesize:每页条数 var url = "/doctor/patient_label_info/getPatientByParams", params = { page:sPage, filter: search_keyword, pagesize:sPagesize, teamCode:lastTeamId,isFollowWeChat:true}; getReqPromise(url,params,'get').then(function(res){ if(res.status == 200) { if(res.data.length == 0 && sPage==1) { $searchList.hide(); $noResultWrap.show(); }else{ if(sPage==1){ if(res.data.length < sPagesize) { $('#sload').hide() $('#sfinish').hide() }else{ $('#sload').show() $('#sfinish').hide() } }else{ if(res.data.length < sPagesize){ $('#sload').hide() $('#sfinish').show() }else{ $('#sload').show() $('#sfinish').hide() } } $noResultWrap.hide(); $searchList.show(); initPatientViewList(res.data,search_keyword); } } else { mui.toast('搜索失败') } plus.nativeUI.closeWaiting(); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e) }); }, // 搜索视图列表 initPatientViewList = function(data,keyword) { var html = template("pati_list_tmpl", {list: _.map(data,function(o) { o.jsonStr = JSON.stringify(o); return o; })}) $searchUl.append(html); ellipsisText($searchUl.find('li'),keyword); checkIsSelect2() }, ellipsisText = function ($elements, searchText) { _.each($elements,function(el) { var $textEl = $(el).find(".j-text-ellipsis"); _.each($textEl, function(t){ highlineKeyword($(t),searchText); }); }); }, highlineKeyword = function ($el,searchText) { var text = $.trim($el.attr('data-text')), length = text.length, kws = $.trim(searchText).replace(/\s+/g," ").split(" "); $el.html(replaceAll(text, kws)); }, replaceAll = function (text, arr) { var html = text; _.each(arr,function(kw) { var reg = new RegExp(kw+"(?!>)","gi"); html = html.replace(reg,''+kw+''); }); return html; }, historyList = function(){ getSaveHisData() var html = template('his_list_tmpl',{list:historyData}); $hisSearList.html(''); $hisSearList.append(html); }, refreshPage = function(){ baseInfo = getBaseInfo(); sendPatiId = [] $('.xz-sel-one').empty() initPatientGroupsList(); }, saveHisData = function(){ //保存历史数据20个 var value = $searchBtn.val().trim(); if(value){ if(historyData.length>19){ historyData.pop(); } if(historyData.indexOf(value)>-1){ historyData = _.filter(historyData, function(o){ return o != value; }); } historyData.unshift(value); var str = JSON.stringify(historyData) plus.storage.setItem("jianjiaoSearchHis"+docInfo.code,str); historyList(); } }, getSaveHisData = function(){ historyStr = plus.storage.getItem("jianjiaoSearchHis"+docInfo.code); if(historyStr){ historyStr = JSON.parse(historyStr).join(','); historyData = historyStr.split(','); }else{ historyData = []; } }, countHeight = function(){ if($navInput.css('display')=='none'){ $container.css('top',$('.topTitle').outerHeight()+89) $container.css('bottom',59) }else{ $container.css('top',$('.topTitle').outerHeight()+89+$navInput.outerHeight()) $searchList.css('top',$('.topTitle').outerHeight()+89+$navInput.outerHeight()) $container.css('bottom',87) } }, countWidth = function(){ $searchBtn.css('width',$('.xz-sel-list').width() - $('.xz-sel-one').outerWidth()) $('.xz-sel-one').scrollLeft( $('.xz-sel-one')[0].scrollWidth) }, //添加选中 addSelectLi = function(one){ var jsons = JSON.parse(one.attr('data-json')) sendPatiId.push(jsons.code); $('.xz-sel-one').append('
  • '+jsons.name+'
  • ') sendCount++ countWidth() }, //删除选中 removeSelectLi = function(one){ var jsons = JSON.parse(one.attr('data-json')) sendPatiId = _.without(sendPatiId,jsons.code); var $li = $('.xz-sel-one').find('li'); for(var i=0;i<$li.length;i++){ if($li.eq(i).text() == jsons.name){ $li.eq(i).remove() sendCount-- countWidth() return } } }, // 绑定页面事件 bindEvents = function () { //切换批量与单独 $('.xz-nav-one').on('click',function(){ var $this = $(this) if(!$this.hasClass('active')){ $this.addClass('active').siblings().removeClass('active') tagTitle = $this.attr('data-id') initPatientGroupsList(); if(tagTitle == 2){ $navInput.css('display','-webkit-box') $('#warn-notice').show() $('#control').show() }else{ $('#warn-notice').hide() $navInput.hide() $('#control').hide() } $container.show() $('.xz-sel-btn').hide() $noResultWrap.hide() $history.hide() $searchList.hide() $searchUl.empty() $searchBtn.val('') sPage = 1 countHeight() countWidth() sendCount = 0; sendPatiId = [] $sendCount.text(sendCount); $('.xz-sel-one').empty() } }) //批量 $patiList.on('click','.patient-list.label-sel',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); }) //单独 点击展开显示居民 $patiList.on('click','.patient-list.showName',function(e) { e.stopPropagation(); var code = $.trim($(this).attr("data-group")), isOpen = togglePatientListShow($(this)), isEmpty = !$(this).find('ul.n-list li').length; code && !isOpen && isEmpty && initPatientListByGroup(code); }) $patiList.on('click','li[data-patient-code]',function(e) { e.stopPropagation(); var that = $(this) if(that.hasClass('checked')){ that.find('.check-img').attr('src','../images/unchecked.png'); that.removeClass('checked') if(tagTitle == 2){removeSelectLi(that);} $sendCount.text(sendCount); checkIsSelect() }else{ if(sendCount == 200){ mui.toast('选择居民不能超过200个') return }else{ that.find('.check-img').attr('src','../images/checked_all.png'); that.addClass('checked') if(tagTitle == 2){addSelectLi(that);} $sendCount.text(sendCount); checkIsSelect() } } return false; }) //加载更多 $patiList.on('click','.load-more',function(e) { e.stopPropagation(); plus.nativeUI.showWaiting(); var $wrap = $(this).closest(".patient-list"), code = $wrap.attr("data-group"), page = parseInt($wrap.attr("data-page")); var url = "doctor/patient_label_info/patients_by_label"; getReqPromise(url,{labelType: typeId,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize:30,isFollowWeChat:true},'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); checkIsSelect() } plus.nativeUI.closeWaiting(); }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); }); return false; }) //搜索功能 $searchBtn.on('click',function(){ historyList() $container.hide() $('.xz-sel-btn').show() $noResultWrap.hide() $searchList.hide() $history.show() $searchUl.empty() sPage = 1 }) $searchBtn.on('keydown',function(e) { if (e.which === 13) { $searchUl.empty() $history.hide() searchByPaging(); saveHisData() } }) //加载更多 $searchList.on('click','#sload',function(){ sPage++ searchByPaging(); }) //点击搜索结果 $searchUl.on('click','li[data-patient-code]',function(e) { e.stopPropagation(); var that = $(this) if(that.hasClass('checked')){ that.find('.check-img').attr('src','../images/unchecked.png'); that.removeClass('checked') if(tagTitle == 2){removeSelectLi(that);} }else{ that.find('.check-img').attr('src','../images/checked_all.png'); that.addClass('checked') if(tagTitle == 2){addSelectLi(that);} } $sendCount.text(sendCount); checkIsSelect() }); $hisSearList.on('click','li',function(){ var $that = $(this); page = 1; $history.hide(); $searchBtn.val($that.text()) searchByPaging(); }) $('#clear_his_data').on('click', function(){ plus.storage.removeItem("jianjiaoSearchHis"+docInfo.code); historyList(); }) //取消 $('.xz-sel-btn').on('click',function(){ $container.show() $searchBtn.val('') $('.xz-sel-btn').hide() $noResultWrap.hide() $searchList.hide() $history.hide() }) 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(); }); $("#sendBtn").on('click',function(){ var groupList=[]; var patientList=[]; var amount = 0; if(tagTitle == 2){ amount = sendPatiId.length successNext() }else{ $(".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); } }) //请求发送数量 var param = { articleId:article, group:groupList.join(","), labelType:typeId, teamCode:lastTeamId } plus.nativeUI.showWaiting(); sendGet('doctor/jkEdu/article/doctorPushArticleConfirm',param,function(){ plus.nativeUI.closeWaiting(); mui.toast('请求失败') },function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200){ amount = res.data.num successNext() }else{ mui.toast('获取发送人数失败') return } }) } function successNext(){ if(amount > 0){ //健康教育模块 if(origin == 'jiaoyu'){ dialog({ title: '
    发送给
    '+amount+'人
    ', content: '
    《'+articleTitle+'》
    ', okValue: '立即发送', cancelValue: '我再看看', cancel: function () { return; }, ok: function() { var params = {}; if(tagTitle == 2){ params.articleId =article; params.patient=sendPatiId.join(","); params.teamCode=lastTeamId; params.leaveWords = $.trim($('#messageInput').val()); }else{ params.articleId =article; // params.patient=patientList.join(","); params.group=groupList.join(","); params.labelType = typeId; params.teamCode = lastTeamId; params.leaveWords = $.trim($('#messageInput').val()); } var docInfo = JSON.parse(plus.storage.getItem('docInfo')); params.currentUserRole = docInfo.hospital; params.currentUserRoleLevel = 4; plus.nativeUI.showWaiting(); // sendPost("/doctor/health/edu/send",params,sendError,sendSuccess,'POST',2400000); 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==10000){ 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"); } var opener = plus.webview.currentWebview().opener(); if(opener && (opener.id != 'jiankangjiaoyu') && (opener.id != 'article')){ mui.fire(opener, 'refresh'); } mui.back(); }else{ sendError(res); } }; } }).showModal() } }else{ mui.toast("发送人数为0"); } } }) /*刷新事件*/ window.addEventListener("refresh", function refresh(e) { refreshPage(); }); }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { mui.plusReady(function() { resolve(true); }) }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录基本信息 baseInfo = getBaseInfo(); docInfo = JSON.parse(plus.storage.getItem("docInfo")); lastTeamId = docInfo.adminTeamCode; //历史记录 getSaveHisData() // 绑定页面事件 bindEvents(); initTeams(); initPatientGroupsList(); countHeight() }); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); })