var page = 1, pageSize = 10, myScroller, keyword = "", key, //记录前一个页面中需要绑定的键值 snCode, docInfo, isManage, choosedPatient = []; mui.init(); mui.plusReady(function(){ var self = plus.webview.currentWebview(); key = self.key; snCode = self.sn; isManage = self.isManage; choosedPatient = self.choosed; docInfo = JSON.parse(plus.storage.getItem("docInfo")); initScroller(); getPatientList(true); bindEvents(); templateHelper(); }) function getPatientList(isInit){ plus.nativeUI.showWaiting(); if(isInit){ page = 1; } var url = "doctor/patient/getPatientSignByNameOrIdCard", params = { keyWord: $.trim($(".search-input").val()), deviceSn: snCode, page: page, pageSize: pageSize }; if(isManage){ var selectedRole = JSON.parse(plus.storage.getItem("selectedRole")); var level = selectedRole.code == CITY_CODE ? 4 : selectedRole.code.length==6 ? 3 : 2; params.isManage = 1; params.level = level; params.area = selectedRole.code; }else{ params.isManage = 0; params.area = docInfo.hospital; } sendPost(url, params, null, function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200){ $(".mui-scroll-wrapper").show(); var list = res.data; if(list.length == 0){ if(isInit){ $("#patientList").hide(); $("#no_result_wrap").show(); keyword = ""; }else{ myScroller.endPullupToRefresh(true); } }else{ page ++; $("#patientList").show(); $("#no_result_wrap").hide(); var list2 = _.map(list, function(o){ if(choosedPatient.indexOf(o.code) > -1){ o.choosed = 1; }else{ o.choosed = 0; } return o; }) var html = template("list-tmp", {list: list2}); if(isInit){ $("#patientList").empty().append(html); }else{ $("#patientList").append(html); } if(list.length < pageSize){ myScroller.endPullupToRefresh(true); }else{ myScroller.endPullupToRefresh(false); } } }else{ mui.toast(res.msg) } }, 'post', '', true); } function initScroller(){ var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ scrollX: true, bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); myScroller = mui(".mui-scroll-wrapper").pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getPatientList(true); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function(){ var self = this; setTimeout(function(){ getPatientList(false); }, 1000) } } }); } function bindEvents(){ $(".search-input").on("input", function(e){ var $this = $(this); setTimeout(function(){ if($this.prop("comstart")){ return false; } var text = $.trim($this.val()); if(text.length > 0){ $("#search_suggest_text").show(); $(".mui-scroll-wrapper").hide(); $("#search_suggest_text").text("搜索:"+text); }else{ $("#search_suggest_text").hide(); getPatientList(true); } }, 0); }).on('compositionstart', function(){ $(this).prop('comstart', true); //console.log('中文输入:开始'); }).on('compositionend', function(){ $(this).prop('comstart', false); // console.log('中文输入:结束'); }) $("#search_suggest_text").on('click', function(){ $(this).hide(); getPatientList(true); }) $(".cancel-btn").on('click', function(){ var value = $.trim($(".search-input").val()); if(value.length > 0){ $(".search-input").val(""); $("#search_suggest_text").hide(); getPatientList(true); } }) $("#patientList").on('tap', ".choose-btn", function(){ var $this = $(this), jsonStr = $this.attr("data-json"); if($this.hasClass("bind")){ return false; } if(jsonStr){ jsonStr = JSON.parse(jsonStr); }else{ jsonStr = {}; } var self = plus.webview.currentWebview(), opener = self.opener(); mui.fire(opener, "setPatientInfo", {key: key, obj: jsonStr}); mui.later(function(){ mui.back(); }, 300) }) } function templateHelper(){ template.helper("highlightKeyword", function(str){ var kw = $(".search-input").val(), reg = new RegExp(kw+"(?!>)","gi"), html = str; if(kw){ html = str.replace(reg,''+kw+''); } return html; }); template.helper("getJsonStr", function(obj){ if(obj){ return JSON.stringify(obj); }else{ return ""; } }) }