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('