xzjm-searchmore.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. var self;
  2. var docInfo;
  3. var checkeds = {}, num = 0;
  4. var teamCode;
  5. var searchRs;
  6. mui.plusReady(function(){
  7. self = plus.webview.currentWebview();
  8. docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  9. searchRs = self.searchRs;
  10. teamCode = self.teamCode;
  11. num = self.num;
  12. checkeds = self.checkeds;
  13. showPatients();
  14. })
  15. template.helper('isChecked', function(v){
  16. return checkeds[v]? 'checked' : '';
  17. })
  18. template.helper('toInfo', function(v){
  19. return JSON.stringify(v);
  20. })
  21. template.helper("setPhoto", function(p) {
  22. return getImgUrl(p);
  23. });
  24. function showPatients(){
  25. plus.nativeUI.showWaiting();
  26. showNum();
  27. var data;
  28. if(self.searchType == 'sa'){
  29. data = searchRs.address;
  30. } else
  31. data = searchRs.name;
  32. $('#pati_list').html(template('pati_tmpl', {list: data}));
  33. plus.nativeUI.closeWaiting();
  34. mui(document).imageLazyload({
  35. placeholder: '../../../images/p-female.png'
  36. });
  37. }
  38. var $list = $('#listDiv');
  39. $('.content').on('tap', '.rs-checkbox.l-checkbox', function(){
  40. //选择、取消居民
  41. var $li = $(this).parent();
  42. var code = $li.attr('data-code');
  43. var info = JSON.parse($li.attr('data-info'));
  44. var isChecked = !$li.hasClass('checked');
  45. $li.toggleClass('checked');
  46. toggleChecked(code, isChecked, info);
  47. showNum();
  48. //通知父窗口修改状态
  49. updateParent([code], isChecked);
  50. return false;
  51. })
  52. $('#allSel').on('tap', function(){
  53. var checked = !$('#allSel').hasClass('checked');
  54. var codes = [], code;
  55. if(checked){
  56. $('#allSel').addClass("checked").next().html("取消全选");
  57. $.each($('#listDiv .n-list-link[class!="checked"]'), function(i, v) {
  58. code = $(v).attr('data-code');
  59. codes.push(code);
  60. $(v).addClass('checked');
  61. addChecked(code, JSON.parse($(v).attr('data-info')));
  62. });
  63. } else{
  64. $('#allSel').removeClass("checked").next().html("全选");
  65. var $lis = $('#listDiv .n-list-link.checked');
  66. $.each($('#listDiv .n-list-link.checked'), function(i, v) {
  67. code = $(v).attr('data-code');
  68. codes.push(code);
  69. $(v).removeClass('checked');
  70. removeChecked($(v).attr('data-code'), JSON.parse($(v).attr('data-info')));
  71. });
  72. }
  73. showNum();
  74. updateParent(codes, checked);
  75. })
  76. function updateParent(codes, isChecked){
  77. mui.fire(self.opener(), 'updateChecked', {codes: codes, isChecked: isChecked})
  78. }
  79. function showNum(){
  80. $('.checked-num label').html(num);
  81. }
  82. function toggleChecked(code, isCheck, info){
  83. if(isCheck)
  84. addChecked(code, info);
  85. else
  86. removeChecked(code);
  87. }
  88. function addChecked(code, info){
  89. if(!checkeds[code]){
  90. num++;
  91. checkeds[code] = info;
  92. }
  93. }
  94. function removeChecked(code){
  95. if(checkeds[code]){
  96. num--;
  97. delete checkeds[code];
  98. }
  99. }
  100. /**
  101. * 下一步操作
  102. */
  103. function submit(){
  104. if(num<=0)
  105. return;
  106. plus.nativeUI.showWaiting();
  107. var patients = [], patiCodes = [];
  108. for(var k in checkeds){
  109. patiCodes.push(k);
  110. patients.push(checkeds[k]);
  111. }
  112. if(self.type=='分配'){
  113. to_next(patients);
  114. return;
  115. }
  116. sendPost("/doctor/consult/getConsultByPatientAndDoctor",
  117. {patientCode: patiCodes.join(","), doctor: self.docCode}, null,
  118. function(res){
  119. var tem = {};
  120. if(res.length==0){
  121. to_next(patients);
  122. } else if(patients.length == res.length){
  123. plus.nativeUI.closeWaiting();
  124. mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){
  125. })
  126. return;
  127. } else if(res.length <= 3 ){
  128. tem = getCanTrans(patients, res);
  129. mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  130. if(e.index == 0){
  131. to_next(tem.canPati);
  132. cancleSel(res);
  133. }
  134. })
  135. } else if(res.length < patients.length){
  136. tem = getCanTrans(patients, res);
  137. mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  138. if(e.index == 0){
  139. to_next(tem.canPati);
  140. cancleSel(res);
  141. }
  142. })
  143. } else{
  144. }
  145. plus.nativeUI.closeWaiting();
  146. })
  147. }
  148. function getCanTrans(patients, notCodes){
  149. var canPati = [];
  150. var names = [];
  151. $.each(patients, function(i, v) {
  152. var has = false;
  153. $.each(notCodes, function(n, m) {
  154. if(v.code == m){
  155. has = true;
  156. names.push(v.name);
  157. }
  158. });
  159. if(!has){
  160. canPati.push(v);
  161. }
  162. });
  163. return {canPati: canPati, names: names.join(",")}
  164. }
  165. function cancleSel(notCodes){
  166. var $ul, $prev, len;
  167. $.each(notCodes, function(i, c) {
  168. var $lis = $('#listDiv .n-list-link[data-code="'+ c +'"]');
  169. $.each($lis, function(i, v) {
  170. $(v).removeClass('checked');
  171. $ul = $(v).closest('ul');
  172. $prev = $ul.prev();
  173. len = $(v).closest('ul').find('li.checked').length;
  174. if(len==0)
  175. $prev.removeClass('checked').removeClass('incomplete');
  176. else if(len==$ul.parent().attr('data-amount'))
  177. $prev.removeClass('incomplete').addClass('checked');
  178. else
  179. $prev.removeClass('checked').addClass('incomplete');
  180. });
  181. removeChecked(c);
  182. });
  183. showNum();
  184. }
  185. function to_next(patients){
  186. mui.openWindow({
  187. id: "xuanzejieshouyisheng.html",
  188. url: "xuanzejieshouyisheng.html",
  189. extras: {
  190. patients: patients,
  191. docCode: self.docCode,
  192. teamCode: teamCode,
  193. type: self.type,
  194. level: self.level
  195. }
  196. });
  197. }