123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- // 基本信息(包括userAgent)
- var baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
-
- // 搜索框
- var $searchbar = $('.searchbar'),
- // 搜索输入框
- $searchbarInput = $('.lin-search-ipt input'),
- // 搜索取消按钮
- $searchCancelBtn = $('.searchbar-cancel'),
- // 搜索框下面悬浮的搜索提示
- $searchSuggest = $('#search_suggest_text'),
- // 搜索结果展示容器
- $searchtResult = $('#search_result'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap'),
- $patiList = $('#pati_list'),
- // 分页查询最后一页
- $history = $('#history_search'),//历史搜索
- $hisSearList = $('#his_sear_list');
- var page = 1,
- search_keyword = "", //记录搜索框的内容
- lastTeamId,// 从缓存取出所选团队
- pagesize = 15,
- historyData=[],//历史数据
- historyStr;
- var self;
- var startScrollX,
- scrollXd,
- $scrollDom;
- mui.plusReady(function() {
- // initKeyboardAndroid();
- docInfo = JSON.parse(plus.storage.getItem("docInfo"));
- historyStr = plus.storage.getItem("juminSearchHis"+docInfo.code);
- if(historyStr){
- historyStr = JSON.parse(historyStr).join(',');
- historyData = historyStr.split(',');
- }else{
- historyData = [];
- }
- })
- window.addEventListener("initSearch", function(e){
- // openSoftKeyboard();
- baseInfo = getBaseInfo();
- $("#searchAll").show();
- setTimeout(function(){
- $("#searchPut").focus();
- },100)
- if(historyData.length){
- $history.show();
- }
- lastTeamId = plus.storage.getItem("selectedTeamId");
- })
- // 获取登录相关信息
- var getBaseInfo = function() {
- // 登录的相关信息
- var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
- var env = {
- webview: plus.webview.currentWebview()
- }
- return Promise.resolve().then(function(res) {
- return env;
- })
- },
- historyList = function(){
- historyStr = plus.storage.getItem("juminSearchHis"+docInfo.code);
- if(historyStr){
- historyStr = JSON.parse(historyStr).join(',');
- historyData = historyStr.split(',');
- }else{
- historyData = [];
- }
- var html = template('his_list_tmpl',{list:historyData});
- $hisSearList.html('');
- $hisSearList.append(html);
- },
- // 初始化“患者”视图列表
- initPatientViewList = function(data,keyword,isAppend) {
- var html = template("pati_list_tmpl", {list: _.map(data,function(o) {
- o.jsonStr = JSON.stringify(o);
- return o;
- })});
- searchText = $searchbarInput.val().trim();
- if(isAppend == true){
- $patiList.append(html)
- }else{
- mui('#jumin_wrapper').pullRefresh().scrollTo(0,0)
- $patiList.empty().append(html)
- mui('#jumin_wrapper').pullRefresh().refresh(true);//重置
- }
- ellipsisText($patiList.find('li'),searchText);
- },
- // $el: $('.c-content-warp')
- getRowProps = function ($el) {
- var $textEllipsis = $el,
- $text = $textEllipsis.eq(0),
- $chart = $text.text('a'),
- enWidth = $chart.width(),
- $chart = $text.text('中'),
- zhWidth = $chart.width(),
- lineHeight = parseFloat($chart.css("lineHeight"), 10),
- rowHeight = $chart.height();
- $chart.text('');
- return {
- chartWidth: {
- zh: zhWidth,
- en: enWidth
- },
- rowHeight: Math.max(rowHeight, lineHeight),
- rowWidth: $el.width()
- };
- },
- replaceAll = function (text, arr) {
- var html = text;
- _.each(arr,function(kw) {
- var reg = new RegExp(kw+"(?!>)","gi");
- html = html.replace(reg,'<em>'+kw+'</em>');
- });
- return html;
- },
- highlineKeyword = function ($el,searchText) {
- var props = getRowProps($el),
- chartWidth = props.chartWidth,
- rowHeight = props.rowHeight,
- rowWidth = props.rowWidth,
- // 每行显示字符数(以中文字符为标准计算)
- chartNum = Math.floor(rowWidth / chartWidth.zh),
- // 排除指定数量字符所占宽度
- exceptNum = 0,
- // 行数
- rowNum = 1,
- // 预计显示总字符数
- expectedNum = chartNum * rowNum - exceptNum,
- $target = $el,
- // 目标文本
- text = $.trim($target.attr('data-text')),
- length = text.length,
- // 关键字数组
- kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
- var fidx = 0,preFidx,diff = 0;
- $target.html(replaceAll(text, kws));
- if(Math.floor($target.height() / rowHeight) <= rowNum) {
- return ;
- }
- if(text.length > expectedNum) {
- fidx = text.indexOf(kws[0])+kws[0].length-1;
- diff = fidx - expectedNum + 1;
- preFidx = fidx;
- diff = (diff<0)?0:diff;
- var preChar = (diff>0)?"...":"";
- $target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"...");
- while((Math.floor($target.height() / rowHeight) <= rowNum) && (preFidx < length)) {
- preFidx++;
- $target.html(preChar+replaceAll(text.slice(diff,preFidx+1), kws)+"...");
- }
- if(preFidx == length && (Math.floor($target.height() / rowHeight) <= rowNum)) {
- diff = diff>0?(diff - 1):0;
- $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws));
- } else if((Math.floor($target.height() / rowHeight) > rowNum)) {
- $target.html(preChar+replaceAll(text.slice(diff,preFidx), kws)+"...");
- }
- }
- },
- ellipsisText = function ($elements, searchText) {
- _.each($elements,function(el) {
- var $textEl = $(el).find(".j-text-ellipsis");
- _.each($textEl, function(t){
- highlineKeyword($(t),searchText)
- })
- });
- },
- // 控制搜索关键字悬浮提示的显示
- showSearchSuggest = function(text) {
- var suggestText = '搜索“'+text+'”';
- // 如果text不为空,则显示;否则隐藏
- if(text&&text.trim().length) {
- $searchSuggest.text(suggestText);
- $searchSuggest.show();
- } else {
- $searchSuggest.text('');
- $searchSuggest.hide();
- }
- },
- // 分页查询列表
- searchByPaging = function (isAppend,fun) {
- $history.hide();
- $("#searchPut").blur();
- search_keyword = $searchbarInput.val();
- if(!$.trim(search_keyword)) {
- return ;
- }
- plus.nativeUI.showWaiting();
- var url = "/doctor/specialist/getDoctorPatientByName";
- var params = { page:page, doctor: docInfo.code, nameKey: search_keyword, size:pagesize};
- getReqPromise(url,params, "GET").then(function(res){
- if(res.status == 200) {
- if((page==1 && !res.data) || (page==1 && !res.data.length)) {
- $searchtResult.hide();
- $noResultWrap.show();
- } else {
- $noResultWrap.hide();
- $searchtResult.show();
- initPatientViewList(res.data,search_keyword,isAppend);
- if(res.data.length < pagesize){
- fun&&fun.call(this,true)
- }else{
- fun&&fun.call(this,false)
- }
- }
- }else{
- mui.toast("搜索失败");
- }
- plus.nativeUI.closeWaiting();
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e)
- })
- },
- // 绑定页面事件
- bindEvents = function (){
- mui.init({
- pullRefresh : {
- container:'#jumin_wrapper',
- up : {
- height:50,
- contentinit: '',
- contentdown: '',
- contentrefresh : "正在加载...",
- contentnomore:'没有更多数据了',
- callback: function() {
- var self = this;
- page++;
- searchByPaging(true,function(value){
- setTimeout(function(){
- self.endPullupToRefresh(value);
- },500)
- })
- }
- }
- }
- })
-
- $('#his_scroll').css({
- 'height':$(window).height()-132
- })
- mui('#his_scroll').scroll({
- bounce: true, //是否启用回弹
- })
-
- $patiList.on('tap','.patient-list',function() {
- var code = $.trim($(this).attr("data-group")),
- isOpen = togglePatientListShow($(this));
- code && !isOpen && initPatientListByGroup(code);
- }).on('tap','li[data-patient-code]',function() {
- alert($(this).attr("data-patient-code"))
- openWebview("../../kfgl/html/denizen.html",{
- patiCode: $(this).attr("data-patient-code")
- });
- });
-
- $searchbarInput.on('input', function() {
- var text = $(this).val().trim();
- $searchtResult.hide();
- $('#no_result_wrap').hide();
- if(text.length > 0){
- $("#searchAll").hide();
- $history.hide();
- }else{
- $("#searchAll").show();
- $history.show();
- }
- showSearchSuggest(text);
- }).on('keydown',function(e) {
- if (e.which === 13) {
- page = 1;
- $searchSuggest.hide();
- searchByPaging(false);
- //保存历史数据20个
- saveHisData();
- }
- });
-
- $('#clear_his_data').on('tap', function(){
- plus.storage.removeItem("juminSearchHis"+docInfo.code);
- historyList();
- $history.hide();
- })
-
- $hisSearList.on('click','.his-list',function(){
- var $that = $(this);
- page = 1;
- $("#searchAll").hide();
- $searchSuggest.hide();
- $history.hide();
- $searchbarInput.val($that.text())
- searchByPaging(false);
- })
-
- $('.lin-search-ipt a').on('tap', function(){
- plus.webview.currentWebview().hide();
- mui.later(function(){
- $('#search_result').hide();
- $('#no_result_wrap').hide();
- $('#searchPut').val("");
- $("#search_suggest_text").html("").hide();
- $("#searchPut").blur();
- }, 50)
- })
-
- $searchSuggest.on('click',function() {
- page = 1;
- $searchSuggest.hide();
- searchByPaging(false);
-
- //保存历史数据20个
- saveHisData()
- });
-
- function saveHisData(){
- //保存历史数据20个
- var value = $searchbarInput.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("juminSearchHis"+docInfo.code,str);
- historyList();
- }
- }
-
- $searchCancelBtn.on('click',function() {
- mui.back()
- })
-
- //搜索全部居民的绑定事件
- $("#searchAll").on('click', function(){
- openWebview("search_all.html");
- });
-
- $(".c-list").on("tap", ".operate", function(e) {
- e.preventDefault();
- e.stopPropagation();
- openWebview("../../zhuanbing/html/fenpeijianguanshi.html",{
- patiCode: $(this).attr("data-patient")
- })
- }).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;
- })
-
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- mui.plusReady(function() {
- resolve(true);
- })
- }).then(function() {
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录基本信息
- baseInfo = getBaseInfo();
- lastTeamId = plus.storage.getItem("selectedTeamId");
- self = plus.webview.currentWebview();
- $searchbar.searchBar();
- // openSoftKeyboard();
- $searchbarInput.focus();
- historyList();
- if(historyData.length){
- $history.show();
- }
- // 绑定页面事件
- bindEvents();
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
|