tianjiabiaoqian.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. var self, iscroll, type, tagInfo, teamCode, hasPati, checkeds = {}, num = 0;
  2. mui.plusReady(function(){
  3. self = plus.webview.currentWebview();
  4. type = self.type;
  5. tagInfo = self.tagInfo;
  6. teamCode = self.teamCode;
  7. iscroll = $('#scroller').lscroll({top: 46});
  8. init();
  9. })
  10. var old_back = mui.back;
  11. mui.back = function(data) {
  12. if(!$('.link').hasClass('c-ccc')){
  13. mui.confirm("您有未保存的变动,是否保存?", "提示", ["不了", "保存"], function(e) {
  14. if(e.index == 0) {
  15. old_back();
  16. } else {
  17. save(1);
  18. }
  19. })
  20. }else{
  21. old_back();
  22. }
  23. }
  24. function init(){
  25. if(type==1){//编辑
  26. $('#title').html("编辑新标签");
  27. $('#name').val(tagInfo.name);
  28. if(tagInfo.code==1 || tagInfo.code==2){
  29. $('.header-link').hide();
  30. $('#name').attr('readOnly', true);
  31. $('#memo').show().prev().hide();
  32. }
  33. $('#bjArea').show();
  34. } else{
  35. $('#title').html("添加新标签");
  36. $('#tjArea').show();
  37. }
  38. }
  39. function addMembers(data){
  40. var d = [];
  41. for(var k in data){
  42. d.push(data[k]);
  43. }
  44. var html = template('members_tmpl', {data: d});
  45. $('.lin-g-member .member').remove();
  46. $('#addBtn').before(html);
  47. iscroll.refresh();
  48. }
  49. function editMembers(type, dataBack){
  50. console.log(teamCode);
  51. openWebview("bq-xinzengchengyuan.html", {
  52. type: type,
  53. teamCode: teamCode,
  54. tagInfo: tagInfo,
  55. dataBack: dataBack,
  56. checkeds: checkeds,
  57. num: num
  58. });
  59. }
  60. /**
  61. * 删除标签
  62. */
  63. function delTag(){
  64. sendPost("/doctor/patient_label/delete", {
  65. labelCode: tagInfo.code
  66. }, null, function(res){
  67. if(res.status == 200){
  68. mui.fire(self.opener(), "deleteTag", {code: tagInfo.code});
  69. mui.toast("删除标签成功!");
  70. self.close();
  71. } else
  72. mui.toast(res.msg);
  73. })
  74. }
  75. /**
  76. * 保存
  77. */
  78. function save(){
  79. var name = $.trim($('#name').val());
  80. if(type==1){
  81. sendPost("/doctor/patient_label/modify", {
  82. labelCode: tagInfo.code,
  83. newName: name
  84. }, null, function(res){
  85. if(res.status == 200){
  86. mui.toast("修改标签成功!");
  87. mui.fire(self.opener(), "refresh");
  88. old_back();
  89. } else
  90. mui.toast(res.msg);
  91. })
  92. return;
  93. }
  94. var patients = [];
  95. $.each($('.lin-g-member .member'), function(i, v) {
  96. patients.push($(v).attr('data-code'));
  97. });
  98. sendPost("/doctor/patient_label_info/label_and_patients_add", {
  99. labelName: name,
  100. teamCode: teamCode,
  101. patients: patients.join(",")
  102. }, null, function(res){
  103. if(res.status==200){
  104. mui.toast("保存成功!");
  105. mui.fire(self.opener(), "refresh");
  106. old_back();
  107. } else
  108. mui.toast(res.msg);
  109. })
  110. }
  111. $('#name').on('input', function(){
  112. var val = $.trim($(this).val());
  113. $('.link').toggleClass("c-ccc", val=="" || val==tagInfo.name);
  114. })
  115. /**
  116. * 删除标签按钮
  117. */
  118. $('.delButton').on('tap', function(){
  119. plus.nativeUI.showWaiting();
  120. sendPost("/doctor/patient_label_info/patients_by_label", {
  121. labelCode: tagInfo.code,
  122. labelType: "4",
  123. teamCode: teamCode,
  124. page: 1,
  125. pagesize: 1
  126. }, null, function(res){
  127. if(res.status == 200){
  128. plus.nativeUI.closeWaiting();
  129. if(res.data && res.data.length>0)
  130. mui.confirm("删除标签后,所有居民不再有该标签,是否确认删除该标签?", "提示", ["不了,谢谢", "确认删除"], function(e) {
  131. if(e.index == 1){
  132. delTag();
  133. }
  134. });
  135. else
  136. delTag();
  137. } else {
  138. plus.nativeUI.showWaiting();
  139. mui.toast("验证是否有居民出错!");
  140. }
  141. })
  142. })
  143. /**
  144. * 点击添加事件
  145. */
  146. $('#addBtn').on('tap', function(){
  147. editMembers("add", true);
  148. })
  149. /**
  150. * 删除事件
  151. */
  152. $('.lin-g-member').on('tap', '.del', function(){
  153. $(this).parent().remove();
  154. delete checkeds[$(this).parent().attr('data-code')];
  155. --num;
  156. iscroll.refresh();
  157. })
  158. /**
  159. * 删除成员跟新增成员按钮
  160. */
  161. $('#bjArea .button').on('tap', function(){
  162. editMembers($(this).attr('data-type'));
  163. })
  164. /**
  165. * 更新团队成员
  166. */
  167. window.addEventListener("updateTeamMember", function(e){
  168. num = e.detail.num;
  169. checkeds = e.detail.data;
  170. addMembers(e.detail.data);
  171. })