choose-patient.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. var page = 1,
  2. pageSize = 10,
  3. myScroller,
  4. keyword = "",
  5. key, //记录前一个页面中需要绑定的键值
  6. snCode,
  7. docInfo,
  8. isManage,
  9. choosedPatient = [];
  10. mui.init();
  11. mui.plusReady(function(){
  12. var self = plus.webview.currentWebview();
  13. key = self.key;
  14. snCode = self.sn;
  15. isManage = self.isManage;
  16. choosedPatient = self.choosed;
  17. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  18. initScroller();
  19. getPatientList(true);
  20. bindEvents();
  21. templateHelper();
  22. })
  23. function getPatientList(isInit){
  24. plus.nativeUI.showWaiting();
  25. if(isInit){
  26. page = 1;
  27. }
  28. var url = "doctor/patient/getPatientSignByNameOrIdCard",
  29. params = {
  30. keyWord: $.trim($(".search-input").val()),
  31. deviceSn: snCode,
  32. page: page,
  33. pageSize: pageSize
  34. };
  35. if(isManage){
  36. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  37. var level = selectedRole.code == CITY_CODE ? 4 : selectedRole.code.length==6 ? 3 : 2;
  38. params.isManage = 1;
  39. params.level = level;
  40. params.area = selectedRole.code;
  41. }else{
  42. params.isManage = 0;
  43. params.area = docInfo.hospital;
  44. }
  45. sendPost(url, params, null, function(res){
  46. plus.nativeUI.closeWaiting();
  47. if(res.status == 200){
  48. $(".mui-scroll-wrapper").show();
  49. var list = res.data;
  50. if(list.length == 0){
  51. if(isInit){
  52. $("#patientList").hide();
  53. $("#no_result_wrap").show();
  54. keyword = "";
  55. }else{
  56. myScroller.endPullupToRefresh(true);
  57. }
  58. }else{
  59. page ++;
  60. $("#patientList").show();
  61. $("#no_result_wrap").hide();
  62. var list2 = _.map(list, function(o){
  63. if(choosedPatient.indexOf(o.code) > -1){
  64. o.choosed = 1;
  65. }else{
  66. o.choosed = 0;
  67. }
  68. return o;
  69. })
  70. var html = template("list-tmp", {list: list2});
  71. if(isInit){
  72. $("#patientList").empty().append(html);
  73. }else{
  74. $("#patientList").append(html);
  75. }
  76. if(list.length < pageSize){
  77. myScroller.endPullupToRefresh(true);
  78. }else{
  79. myScroller.endPullupToRefresh(false);
  80. }
  81. }
  82. }else{
  83. mui.toast(res.msg)
  84. }
  85. }, 'post', '', true);
  86. }
  87. function initScroller(){
  88. var deceleration = mui.os.ios?0.003:0.0009;
  89. mui('.mui-scroll-wrapper').scroll({
  90. scrollX: true,
  91. bounce: false,
  92. indicators: true, //是否显示滚动条
  93. deceleration:deceleration
  94. });
  95. myScroller = mui(".mui-scroll-wrapper").pullRefresh({
  96. down: {
  97. callback: function() {
  98. var self = this;
  99. setTimeout(function() {
  100. getPatientList(true);
  101. self.endPulldownToRefresh();
  102. }, 1000);
  103. }
  104. },
  105. up: {
  106. callback: function(){
  107. var self = this;
  108. setTimeout(function(){
  109. getPatientList(false);
  110. }, 1000)
  111. }
  112. }
  113. });
  114. }
  115. function bindEvents(){
  116. $(".search-input").on("input", function(e){
  117. var $this = $(this);
  118. setTimeout(function(){
  119. if($this.prop("comstart")){
  120. return false;
  121. }
  122. var text = $.trim($this.val());
  123. if(text.length > 0){
  124. $("#search_suggest_text").show();
  125. $(".mui-scroll-wrapper").hide();
  126. $("#search_suggest_text").text("搜索:"+text);
  127. }else{
  128. $("#search_suggest_text").hide();
  129. getPatientList(true);
  130. }
  131. }, 0);
  132. }).on('compositionstart', function(){
  133. $(this).prop('comstart', true);
  134. //console.log('中文输入:开始');
  135. }).on('compositionend', function(){
  136. $(this).prop('comstart', false);
  137. // console.log('中文输入:结束');
  138. })
  139. $("#search_suggest_text").on('click', function(){
  140. $(this).hide();
  141. getPatientList(true);
  142. })
  143. $(".cancel-btn").on('click', function(){
  144. var value = $.trim($(".search-input").val());
  145. if(value.length > 0){
  146. $(".search-input").val("");
  147. $("#search_suggest_text").hide();
  148. getPatientList(true);
  149. }
  150. })
  151. $("#patientList").on('tap', ".choose-btn", function(){
  152. var $this = $(this),
  153. jsonStr = $this.attr("data-json");
  154. if($this.hasClass("bind")){
  155. return false;
  156. }
  157. if(jsonStr){
  158. jsonStr = JSON.parse(jsonStr);
  159. }else{
  160. jsonStr = {};
  161. }
  162. var self = plus.webview.currentWebview(),
  163. opener = self.opener();
  164. mui.fire(opener, "setPatientInfo", {key: key, obj: jsonStr});
  165. mui.later(function(){
  166. mui.back();
  167. }, 300)
  168. })
  169. }
  170. function templateHelper(){
  171. template.helper("highlightKeyword", function(str){
  172. var kw = $(".search-input").val(),
  173. reg = new RegExp(kw+"(?!>)","gi"),
  174. html = str;
  175. if(kw){
  176. html = str.replace(reg,'<em>'+kw+'</em>');
  177. }
  178. return html;
  179. });
  180. template.helper("getJsonStr", function(obj){
  181. if(obj){
  182. return JSON.stringify(obj);
  183. }else{
  184. return "";
  185. }
  186. })
  187. }