bq-xinzengchengyuan.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. var myScroll, self, isSearch, cachePage, num = 0, checkeds = {},
  2. dataBack, tagInfo, teamCode, type,
  3. searchIscroll;
  4. mui.plusReady(function(){
  5. self = plus.webview.currentWebview();
  6. teamCode = self.teamCode;
  7. type = self.type;
  8. tagInfo = self.tagInfo;
  9. checkeds = self.checkeds;
  10. dataBack = self.dataBack;
  11. num = self.num || 0;
  12. $('.link').toggleClass('c-ccc', num<=0).find('label').html(num);
  13. $('h1').html(type == 'add'? "新增标签成员" : "删除标签成员");
  14. $('.header-link').toggle(type == 'add');
  15. myScroll = $('#tags_scroller').lscroll({
  16. top: 106,
  17. id: "tags_iscroll",
  18. pullUpAction: pullUpAction
  19. });
  20. searchIscroll = $('#search_scroller').lscroll({
  21. style: "top: 106px; display: none;",
  22. id: "search_iscroll",
  23. pullUpAction: pullUpAction
  24. });
  25. pullUpAction({options: {page: 1}})
  26. })
  27. var old_back = mui.back;
  28. mui.back = function(data) {
  29. if(dataBack){
  30. mui.fire(self.opener(), "updateTeamMember", {data: checkeds, num: num});
  31. old_back();
  32. } else if(!$('.link').hasClass('c-ccc')){
  33. mui.confirm("您有未保存的变动,是否保存?", "提示", ["不了", "保存"], function(e) {
  34. if(e.index == 0) {
  35. old_back();
  36. } else {
  37. submit(1);
  38. }
  39. })
  40. }else{
  41. old_back();
  42. }
  43. }
  44. template.helper("setChecked", function(code){
  45. if(checkeds[code])
  46. return "checked";
  47. return "";
  48. })
  49. template.helper("setDiseases", function(d, t){
  50. return setDiseases(d, t);
  51. })
  52. /**
  53. * 滚动翻页 (自定义实现此方法)
  54. */
  55. function pullUpAction (g) {
  56. if(isSearch){
  57. search(g.options.page);
  58. }else if(type == 'add')
  59. getPatiLs(g.options.page);
  60. else if(type == 'del')
  61. getTagPatiLs(g.options.page);
  62. }
  63. function search(page){
  64. var p = {teamCode: teamCode, pagesize: 50, page: page}
  65. p.filter = $.trim($('.search-box input').val());
  66. if(type == 'add' && !dataBack){
  67. p.exLabelCode = tagInfo.code;
  68. p.exLabelType = "4";
  69. }
  70. else if(type == 'del'){
  71. p.labelCode = tagInfo.code;
  72. p.labelType = "4";
  73. }
  74. sendPost("/doctor/patient_label_info/patient_search",
  75. p , null,
  76. function(res){
  77. $('.loading').hide();
  78. if(res.status==200){
  79. if(!res.data || res.data.length==0){
  80. if(page == 1){
  81. $('#wushuju1').show();
  82. $('#seachRs').hide().parent().next().hide();
  83. }
  84. else{
  85. searchIscroll.refresh(true);
  86. }
  87. }
  88. else{
  89. $('#wushuju1').hide();
  90. res.type = type;
  91. var html = template("pati_tmpl", res);
  92. if(page==1)
  93. $('#seachRs').html(html);
  94. else
  95. $('#seachRs').append(html);
  96. $('#seachRs').show().next().show();
  97. searchIscroll.refresh(false);
  98. }
  99. } else
  100. mui.toast(res.msg);
  101. })
  102. }
  103. function getPatiLs(page){
  104. plus.nativeUI.showWaiting();
  105. var p = {teamCode: teamCode, pagesize: 50, page: page}
  106. if(!dataBack){
  107. p.exLabelCode = tagInfo.code,
  108. p.exLabelType = "4"
  109. }
  110. sendPost("/doctor/patient_label_info/patients_by_team",
  111. p , null,
  112. function(res){
  113. if(res.status==200){
  114. if(!res.data || res.data.length==0){
  115. if(page == 1)
  116. $('#wushuju').show();
  117. else{
  118. myScroll.refresh(true);
  119. }
  120. }
  121. else{
  122. res.type = type;
  123. $('#list').append(template("pati_tmpl", res));
  124. myScroll.refresh(false);
  125. }
  126. } else
  127. mui.toast(res.msg);
  128. plus.nativeUI.closeWaiting();
  129. })
  130. }
  131. function getTagPatiLs(page){
  132. plus.nativeUI.showWaiting();
  133. var p = {
  134. teamCode: teamCode, pagesize: 50, page: page,
  135. labelCode: tagInfo.code, labelType: "4"
  136. }
  137. sendPost("/doctor/patient_label_info/patients_by_label",
  138. p , null,
  139. function(res){
  140. if(res.status==200){
  141. if(!res.data || res.data.length==0){
  142. if(page == 1)
  143. $('#wushuju').show();
  144. else{
  145. myScroll.refresh(true);
  146. }
  147. }
  148. else{
  149. res.type = type;
  150. $('#list').append(template("pati_tmpl", res));
  151. myScroll.refresh(false);
  152. }
  153. } else
  154. mui.toast(res.msg);
  155. plus.nativeUI.closeWaiting();
  156. })
  157. }
  158. /**
  159. * 完成
  160. */
  161. function submit(){
  162. if(num<=0)
  163. return;
  164. if(dataBack){
  165. mui.fire(self.opener(), "updateTeamMember", {data: checkeds, num: num});
  166. old_back();
  167. } else{
  168. plus.nativeUI.showWaiting();
  169. var patients = [];
  170. for(var k in checkeds){
  171. patients.push(k);
  172. }
  173. sendPost("/doctor/patient_label_info/patient_label_add", {
  174. labelCode: tagInfo.code,
  175. labelType: "4",
  176. patient: patients.join(",")
  177. }, null, function(res){
  178. if(res.status==200){
  179. mui.toast("保存成功!");
  180. old_back();
  181. } else
  182. mui.toast(res.msg);
  183. plus.nativeUI.closeWaiting();
  184. })
  185. }
  186. }
  187. $('.doc-list').on('tap', '.doc-item', function(){
  188. $(this).toggleClass('checked');
  189. var hasChecked = $(this).hasClass('checked');
  190. if(hasChecked){
  191. checkeds[$(this).attr('data-code')] = JSON.parse($(this).attr('data-info'));
  192. ++num;
  193. } else {
  194. delete checkeds[$(this).attr('data-code')];
  195. --num;
  196. }
  197. $('.link').toggleClass('c-ccc', num<=0).find('label').html(num);
  198. if(isSearch){
  199. var code = $(this).attr('data-code');
  200. $('#tags_iscroll .doc-item[data-code="'+ code +'"]').toggleClass('checked', hasChecked);
  201. }
  202. })
  203. var $tanLi, speed = 200;
  204. $('.doc-list').on('tap', '.lin-del-ico', function(){
  205. if($tanLi){
  206. $tanLi.animate({
  207. left: "0px"
  208. }, speed )
  209. }
  210. $(this).parent().parent().animate({
  211. left: "-70px"
  212. }, {speed: speed, step: function(){
  213. $('.l-scroller').css('left', '0');
  214. }, complete: function(){
  215. $tanLi = $(this);
  216. }})
  217. return false;
  218. })
  219. $('.doc-list').on('tap', '.list-del-box div', function(){
  220. var $li = $(this).closest("li");
  221. var code = $li.find(".doc-item ").attr('data-code');
  222. sendPost("/doctor/patient_label_info/patient_label_delete", {
  223. patient: code,
  224. labelCode: tagInfo.code,
  225. labelType: "4"
  226. }, null, function(res){
  227. if(res.status == 200){
  228. mui.toast("删除成功!");
  229. $li.remove();
  230. if(isSearch){
  231. $('#tags_iscroll .doc-item[data-code="'+ code +'"]').remove();
  232. }
  233. } else {
  234. mui.toast(res.msg);
  235. }
  236. })
  237. return false;
  238. })
  239. $(document).on('tap', function(){
  240. if($tanLi){
  241. $tanLi.animate({
  242. left: "0px"
  243. }, speed )
  244. }
  245. })
  246. $('.search-box input').on('input', function(){
  247. if($(this).val().length==0){
  248. isSearch = false;
  249. $('#tags_iscroll').show();
  250. $('#search_iscroll').hide();
  251. } else {
  252. $('#search_iscroll .pullUpLabel').html("上拉加载更多...").parent()
  253. .addClass('l-pullUp').removeClass('noMoreData');
  254. $('#wushuju1').hide();
  255. isSearch = true;
  256. $('#tags_iscroll').hide();
  257. $('.loading').show();
  258. $('#search_iscroll').show();
  259. searchIscroll.options.page = 1;
  260. pullUpAction({options: {page: 1}});
  261. }
  262. })