tianjiabiaoqian.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. openWebview("bq-xinzengchengyuan.html", {
  51. type: type,
  52. teamCode: teamCode,
  53. tagInfo: tagInfo,
  54. dataBack: dataBack,
  55. checkeds: checkeds,
  56. num: num
  57. });
  58. }
  59. /**
  60. * 删除标签
  61. */
  62. function delTag(){
  63. sendPost("/doctor/patient_label/delete", {
  64. labelCode: tagInfo.code
  65. }, null, function(res){
  66. if(res.status == 200){
  67. mui.fire(self.opener(), "deleteTag", {code: tagInfo.code});
  68. mui.toast("删除标签成功!");
  69. self.close();
  70. } else
  71. mui.toast(res.msg);
  72. })
  73. }
  74. /**
  75. * 保存
  76. */
  77. function save(){
  78. var name = $.trim($('#name').val());
  79. if(type==1){
  80. sendPost("/doctor/patient_label/modify", {
  81. labelCode: tagInfo.code,
  82. newName: name
  83. }, null, function(res){
  84. if(res.status == 200){
  85. mui.toast("修改标签成功!");
  86. mui.fire(self.opener(), "refresh");
  87. old_back();
  88. } else
  89. mui.toast(res.msg);
  90. })
  91. return;
  92. }
  93. var patients = [];
  94. $.each($('.lin-g-member .member'), function(i, v) {
  95. patients.push($(v).attr('data-code'));
  96. });
  97. sendPost("/doctor/patient_label_info/label_and_patients_add", {
  98. labelName: name,
  99. teamCode: teamCode,
  100. patients: patients.join(",")
  101. }, null, function(res){
  102. if(res.status==200){
  103. mui.toast("保存成功!");
  104. mui.fire(self.opener(), "refresh");
  105. old_back();
  106. } else
  107. mui.toast(res.msg);
  108. })
  109. }
  110. $('#name').on('input', function(){
  111. var val = $.trim($(this).val());
  112. $('.link').toggleClass("c-ccc", val=="" || val==tagInfo.name);
  113. })
  114. /**
  115. * 删除标签按钮
  116. */
  117. $('.delButton').on('tap', function(){
  118. plus.nativeUI.showWaiting();
  119. sendPost("/doctor/patient_label_info/patients_by_label", {
  120. labelCode: tagInfo.code,
  121. labelType: "4",
  122. teamCode: teamCode,
  123. page: 1,
  124. pagesize: 1
  125. }, null, function(res){
  126. if(res.status == 200){
  127. plus.nativeUI.closeWaiting();
  128. if(res.data && res.data.length>0)
  129. mui.confirm("删除标签后,所有居民不再有该标签,是否确认删除该标签?", "提示", ["不了,谢谢", "确认删除"], function(e) {
  130. if(e.index == 1){
  131. delTag();
  132. }
  133. });
  134. else
  135. delTag();
  136. } else {
  137. plus.nativeUI.showWaiting();
  138. mui.toast("验证是否有居民出错!");
  139. }
  140. })
  141. })
  142. /**
  143. * 点击添加事件
  144. */
  145. $('#addBtn').on('tap', function(){
  146. editMembers("add", true);
  147. })
  148. /**
  149. * 删除事件
  150. */
  151. $('.lin-g-member').on('tap', '.del', function(){
  152. $(this).parent().remove();
  153. delete checkeds[$(this).parent().attr('data-code')];
  154. --num;
  155. iscroll.refresh();
  156. })
  157. /**
  158. * 删除成员跟新增成员按钮
  159. */
  160. $('#bjArea .button').on('tap', function(){
  161. editMembers($(this).attr('data-type'));
  162. })
  163. /**
  164. * 更新团队成员
  165. */
  166. window.addEventListener("updateTeamMember", function(e){
  167. num = e.detail.num;
  168. checkeds = e.detail.data;
  169. addMembers(e.detail.data);
  170. })