tianjiachengyuan.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. var myScroll, teamCode, hospital, checkedNum = 0, checked = {},
  2. pageSize = 20, searchPage;
  3. mui.plusReady(function(){
  4. hospital = JSON.parse(plus.storage.getItem('userAgent')).hospital;
  5. teamCode = plus.webview.currentWebview().teamCode;
  6. myScroll = $('#scroller').lscroll({pullUpAction: pullUpAction, top: 60});
  7. getDocs(1);
  8. /**
  9. * 预加载查询页面
  10. */
  11. searchPage = mui.preload({
  12. url: "tjcy-search.html",
  13. });
  14. })
  15. template.helper('setInfo', function(v){
  16. return JSON.stringify(v);
  17. })
  18. /**
  19. * 获取同机构下医生列表
  20. */
  21. function getDocs(page){
  22. sendGet("/doctor/admin-teams/"+ teamCode +"/members/excluded",
  23. {org_code: hospital, size: pageSize, page: page}, null,
  24. function(res){
  25. if(res.status==200){
  26. if(!res.data || res.data.length==0){
  27. if(page == 1)
  28. $('#wushuju').show();
  29. else{
  30. myScroll.refresh(true);
  31. }
  32. }
  33. else{
  34. $('.doc-list').append(template('docs_tmpl', res));
  35. myScroll.refresh(false);
  36. }
  37. } else
  38. mui.toast(res.msg);
  39. })
  40. }
  41. /**
  42. * 滚动翻页 (自定义实现此方法)
  43. */
  44. function pullUpAction (g) {
  45. getDocs(g.options.page);
  46. }
  47. /**
  48. * 选择事件
  49. */
  50. $('.doc-list').on('tap', '.doc-item', function(){
  51. var code = $(this).toggleClass('checked').attr('data-code');
  52. var info = JSON.parse($(this).attr('data-info'));
  53. if($(this).hasClass('checked')){
  54. add(code, info);
  55. } else{
  56. remove(code);
  57. }
  58. $('.link').html('确定('+ checkedNum+'人)').toggleClass('c-ccc', checkedNum<=0);
  59. })
  60. function add(code, info){
  61. checked[code] = info;
  62. checkedNum++;
  63. }
  64. function remove(code){
  65. delete checked[code];
  66. checkedNum--;
  67. }
  68. $('.lin-search').on('tap', function(){
  69. mui.fire(searchPage, "initSearch",
  70. {checked: checked, checkedNum: checkedNum, teamCode: teamCode, hospital: hospital,
  71. openerId: plus.webview.currentWebview().opener().id});
  72. searchPage.show();
  73. })
  74. /**
  75. * 提交保存
  76. */
  77. function submit(){
  78. if(checkedNum<=0)
  79. return;
  80. var val = "";
  81. for(var k in checked){
  82. val += "," + k;
  83. }
  84. val = val.substring(1);
  85. plus.nativeUI.showWaiting();
  86. sendPost("/doctor/admin-teams/"+ teamCode +"/members",
  87. {doctor_code: val}, null,
  88. function(res){
  89. if(res.status == 200){
  90. $.each($('.doc-list .doc-item[class*="checked"]'), function(i, v) {
  91. $(v).parent().remove();
  92. });
  93. myScroll.refresh();
  94. checkedNum = 0;
  95. $(".link").addClass("c-ccc");
  96. updateParent();
  97. checked = {};
  98. plus.nativeUI.closeWaiting();
  99. mui.toast("添加成功");
  100. mui.back();
  101. } else {
  102. plus.nativeUI.closeWaiting();
  103. mui.toast(res.msg);
  104. }
  105. });
  106. }
  107. function updateParent(){
  108. var p = {data: checked}
  109. var wv = plus.webview.getWebviewById("tuanduishezhi.html");
  110. if(wv)
  111. mui.fire(wv, 'updateTeamMember', p);
  112. wv = plus.webview.getWebviewById("../../tuandui/html/tuandui.html");
  113. if(wv)
  114. mui.fire(wv, 'updateTeamMember', p);
  115. }