choose-patient.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. var page = 0,//原本为1,现改为0
  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 = 0;
  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. var url = "doctor/concern/getConcernPatients", //获取关注该医生的用户列表
  36. params = {
  37. patientName: $.trim($(".search-input").val()),
  38. doctor:docInfo.code,
  39. page: page,
  40. pageSize: pageSize
  41. };
  42. if(isManage){
  43. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  44. var level = selectedRole.code == '350200' ? 4 : selectedRole.code.length==6 ? 3 : 2;
  45. // params.isManage = 1; //原本代码
  46. // params.level = level;
  47. params.area = selectedRole.code;
  48. }else{
  49. // params.isManage = 0; //原本代码
  50. // params.area = docInfo.hospital;
  51. }
  52. // sendPost(url, params, null, function(res){//原本代码
  53. sendGet(url, params, null, function(res){
  54. plus.nativeUI.closeWaiting();
  55. if(res.status == 200){
  56. $(".mui-scroll-wrapper").show();
  57. var list = res.data;
  58. if(list.length == 0){
  59. if(isInit){
  60. $("#patientList").hide();
  61. $("#no_result_wrap").show();
  62. keyword = "";
  63. }else{
  64. myScroller.endPullupToRefresh(true);
  65. }
  66. }else{
  67. page ++;
  68. $("#patientList").show();
  69. $("#no_result_wrap").hide();
  70. var list2 = _.map(list, function(o){
  71. if(choosedPatient.indexOf(o.code) > -1){
  72. o.choosed = 1;
  73. }else{
  74. o.choosed = 0;
  75. }
  76. return o;
  77. })
  78. var html = template("list-tmp", {list: list2});
  79. if(isInit){
  80. $("#patientList").empty().append(html);
  81. }else{
  82. $("#patientList").append(html);
  83. }
  84. if(list.length < pageSize){
  85. myScroller.endPullupToRefresh(true);
  86. }else{
  87. myScroller.endPullupToRefresh(false);
  88. }
  89. }
  90. }else{
  91. mui.toast(res.msg)
  92. }
  93. }, 'post', '', true);
  94. }
  95. function initScroller(){
  96. var deceleration = mui.os.ios?0.003:0.0009;
  97. mui('.mui-scroll-wrapper').scroll({
  98. scrollX: true,
  99. bounce: false,
  100. indicators: true, //是否显示滚动条
  101. deceleration:deceleration
  102. });
  103. myScroller = mui(".mui-scroll-wrapper").pullRefresh({
  104. down: {
  105. callback: function() {
  106. var self = this;
  107. setTimeout(function() {
  108. getPatientList(true);
  109. self.endPulldownToRefresh();
  110. }, 1000);
  111. }
  112. },
  113. up: {
  114. callback: function(){
  115. var self = this;
  116. setTimeout(function(){
  117. getPatientList(false);
  118. }, 1000)
  119. }
  120. }
  121. });
  122. }
  123. function bindEvents(){
  124. $(".search-input").on("input", function(e){
  125. var $this = $(this);
  126. setTimeout(function(){
  127. if($this.prop("comstart")){
  128. return false;
  129. }
  130. var text = $.trim($this.val());
  131. if(text.length > 0){
  132. $("#search_suggest_text").show();
  133. $(".mui-scroll-wrapper").hide();
  134. $("#search_suggest_text").text("搜索:"+text);
  135. }else{
  136. $("#search_suggest_text").hide();
  137. getPatientList(true);
  138. }
  139. }, 0);
  140. }).on('compositionstart', function(){
  141. $(this).prop('comstart', true);
  142. //console.log('中文输入:开始');
  143. }).on('compositionend', function(){
  144. $(this).prop('comstart', false);
  145. // console.log('中文输入:结束');
  146. })
  147. $("#search_suggest_text").on('click', function(){
  148. $(this).hide();
  149. getPatientList(true);
  150. })
  151. $(".cancel-btn").on('click', function(){
  152. var value = $.trim($(".search-input").val());
  153. if(value.length > 0){
  154. $(".search-input").val("");
  155. $("#search_suggest_text").hide();
  156. getPatientList(true);
  157. }
  158. })
  159. $("#patientList").on('tap', ".choose-btn", function(){
  160. var $this = $(this),
  161. jsonStr = $this.attr("data-json");
  162. if($this.hasClass("bind")){
  163. return false;
  164. }
  165. if(jsonStr){
  166. jsonStr = JSON.parse(jsonStr);
  167. }else{
  168. jsonStr = {};
  169. }
  170. var self = plus.webview.currentWebview(),
  171. opener = self.opener();
  172. mui.fire(opener, "setPatientInfo", {key: key, obj: jsonStr});
  173. mui.later(function(){
  174. mui.back();
  175. }, 300)
  176. })
  177. }
  178. function templateHelper(){
  179. template.helper("highlightKeyword", function(str){
  180. var kw = $(".search-input").val(),
  181. reg = new RegExp(kw+"(?!>)","gi"),
  182. html = str;
  183. if(kw){
  184. html = str.replace(reg,'<em>'+kw+'</em>');
  185. }
  186. return html;
  187. });
  188. template.helper("getJsonStr", function(obj){
  189. if(obj){
  190. return JSON.stringify(obj);
  191. }else{
  192. return "";
  193. }
  194. })
  195. }