123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- mui.init();
- var scroller1 = null,
- page = 0,
- pagesize = 10;
- var type = null; //医生收藏过来为1,全部为0
- var isAdmin; //判断是否是新的接口
- var patient = null;
- var patientName = "";
- var isSent,
- firstCatId,
- pCodes,
- referrer;
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- isAdmin = self.isAdmin;
- type = self.type;
- patient = self.patient;
- patientName = self.patientName;
- isSent = self.isSent;
- firstCatId = self.firstCatId;
- pCodes = self.pCodes,
- referrer = self.referrer;
- loaded();
- initKeyboardAndroid();
- openSoftKeyboard();
- $('#searchPut').focus();
- initLatestSearch();
- initHotSearch();
- bindEvents();
- });
- function bindEvents() {
- $('#cancel').on('click', function() {
- plus.webview.currentWebview().close();
- mui.later(function() {
- $('#wrapper').hide();
- $('#no_result_wrap').hide();
- $('#searchValWrap').hide();
- $('#searchPut').val("");
- }, 500)
- });
- $('#searchPut').on('input', function() {
- var html = $(this).val();
- var reg = new RegExp("<" + "(?!>)", "gi");
- html = html.replace(reg, '<');
- var reg = new RegExp(">" + "(?!>)", "gi");
- html = html.replace(reg, '>');
- $('#searchVal').html(html);
- $(".searchbar-clear").toggle($(this).val() != "");
- $('#searchValWrap').toggle($(this).val() != "");
- $("#preSearchPanel").hide();
- $('#wrapper').hide();
- $("#no_result_wrap").hide();
- });
- $('#searchValWrap').on('tap', function() {
- $(this).hide();
- var val = $('#searchPut').val();
- searchArticle(true, val);
- });
- $(".searchbar-clear").on('click', function() {
- $('#searchPut').val("");
- $('#searchVal').html("");
- $('#searchValWrap').hide();
- $('#wrapper').hide();
- $("#preSearchPanel").show();
- return false;
- });
- $('#articleList').on('tap', 'li', function() {
- var code = $(this).attr("data-code");
- if(isAdmin){
- openWebviewExtras("../../home/html/jianjiaotuisong-xiangqing.html",{articleId:code});
- }else{
- openWebview("article-info.html", {
- articleId:code,
- patient: patient,
- patientName: patientName,
- pCodes: pCodes,
- showHandleBar: true,
- referrer: referrer
- });
- }
- });
- $("#preSearchPanel").on('tap', 'span', function() {
- var searchValue = $(this).html();
- $('#searchVal').html(searchValue);
- $('#searchPut').val(searchValue);
- searchArticle(true, searchValue);
- });
-
- template.helper("setKeyword", function(str, kw){
- var reg = new RegExp(kw + "(?!>)", "gi");
- str = str.replace(reg, '<em>' + kw + '</em>');
- return str;
- });
-
- template.helper("setContent", function(str){
- var reg=/<[^<>]+>/g;
- str = str.replace(reg, '');
- return str;
- });
-
- template.helper("formatDate", function(str){
- if(str){
- return str.substr(0,19)
- }else{
- return "";
- }
- })
- }
- function searchArticle(isInit, filter) {
- if(isInit){
- page = 0;
- }
- var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
- var url = '/doctor/jkEdu/article/PC/queryArticlePcList'
- params = {
- articleTitle: filter,
- currentUserRole: docInfo.hospital,
- currentUserRoleLevel: 4,
- iDisplayStart: page * pagesize,
- iDisplayLength: pagesize,
- isAuthentication: 1, //已认证过的文章
- roleType: isAdmin ? 2 : 1 //1、普通医生,2、管理员
- };
- if(isSent){
- url = 'doctor/jkEdu/article/PC/pushArticleList';
- params.sendType = isAdmin ? 2 : 1 //1、普通医生,2、管理员
- params.currentRoleCode = docInfo.hospital;
- }else{
- params.firstLevelCategoryId = firstCatId;
- }
-
- if(patient){
- params.patient = patient;
- }
- if(isAdmin){
- var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
- params.currentUserRole = selectedRole.code;
- params.currentUserRoleLevel = selectedRole.level;
- }
-
- sendGet(url, params, queryFails, function(res) {
- if(res.status == 200) {
- var list = res.data.aaData;
- updatePullUpText(scroller1, list);
- if(isSent){
- var html = template("articleLi2", {list: list, kw: filter});
- }else{
- var html = template("articleLi", {list: list, kw: filter});
- }
- var $articleList = $("#articleList");
- if(isInit) {
- $articleList.empty().append(html);
- if(list.length == 0) {
- $("#no_result_wrap").show();
- }
- } else {
- $articleList.append(html);
- }
- // ellipsisText($articleList.find('.c-content-warp'), filter);
- page += 1;
- $('#wrapper').show();
- $("#preSearchPanel").hide();
- scroller1.refresh();
- } else {
- queryFails(res);
- }
- }, true)
- }
- function queryFails(res) {
- if(res.msg) {
- plus.nativeUI.toast(res.msg);
- } else {
- plus.nativeUI.toast("搜索历史加载失败!");
- }
- }
- function querySuccess(res) {
- if(res.status == 200) {
- } else {
- queryFails(res);
- }
- }
- function loaded() {
- scroller1 = $("#wrapper").initScroll({
- pullDownAction: function() {
- page = 0,
- pagesize = 10;
- var val = $('#searchPut').val();
- searchArticle(true, val);
- },
- pullUpAction: function() {
- var val = $('#searchPut').val();
- searchArticle(false, val);
- }
- });
- }
- document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
- function initLatestSearch() {
- plus.nativeUI.showWaiting();
- var params = {};
- params.type = 2;
- params.page = 0;
- params.pagesize = 10;
- sendPost("/doctor/health/edu/listLabel", params, function(res) {
- initLableFail(res);
- }, function(res) {
- plus.nativeUI.closeWaiting();
- if(res.status == 200) {
- var html = "";
- for(var j in res.list) {
- var data = res.list[j];
- html += "<span>" + data.keyword + "</span>"
- }
- $("#latestSearch").html(html);
- } else {
- initLableFail(res);
- }
- })
- }
- function initHotSearch() {
- plus.nativeUI.showWaiting();
- var params = {};
- params.type = 1;
- params.page = 0;
- params.pagesize = 30;
- sendPost("/doctor/health/edu/listLabel", params, function(res) {
- initLableFail(res);
- }, function(res) {
- plus.nativeUI.closeWaiting();
- if(res.status == 200) {
- var html = "";
- for(var j in res.list) {
- var data = res.list[j];
- html += "<span>" + data.keyword + "</span>"
- }
- $("#hotSearch").html(html);
- } else {
- initLableFail(res);
- }
- })
- }
- function initLableFail(res) {
- plus.nativeUI.closeWaiting();
- if(res.msg) {
- plus.nativeUI.toast(res.msg);
- } else {
- plus.nativeUI.toast("搜索历史加载失败!");
- }
- }
- var updatePullUpText = function(scroller, list) {
- var $wrap = $(scroller.wrapper),
- $pullupLabel = $wrap.find('.pullUpLabel');
- $(".pullUp").removeClass("loading");
- if(!list) {
- $pullupLabel.text('没有更多');
- } else if(list.length < 10) {
- $(".pullUp").hide();
- } else {
- $pullupLabel.text('上拉加载更多');
- }
- scroller.on('refresh', function() {
- if(!list) {
- $pullupLabel.text('没有更多');
- } else if(list.length < 10) {
- $(".pullUp").hide();
- } else {
- $pullupLabel.text('上拉加载更多');
- }
- });
- },
- getRowProps = function($el) {
- var $textEllipsis = $el.find('.j-text-ellipsis'),
- $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.find('.j-text-ellipsis'),
- // 目标文本
- text = $target.attr('data-text').trim(),
- length = text.length,
- // 关键字数组
- kws = searchText.trim().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) {
- //$el.ellipsis({ row: 2});
- _.each($elements, function(el) {
- highlineKeyword($(el), searchText)
- });
- };
|