123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- var self, iscroll, type, tagInfo, teamCode, hasPati, checkeds = {}, num = 0;
- mui.plusReady(function(){
- self = plus.webview.currentWebview();
- type = self.type;
- tagInfo = self.tagInfo;
- teamCode = self.teamCode;
- iscroll = $('#scroller').lscroll({top: 46});
-
- init();
- })
-
- var old_back = mui.back;
- mui.back = function(data) {
- if(!$('.link').hasClass('c-ccc')){
- mui.confirm("您有未保存的变动,是否保存?", "提示", ["不了", "保存"], function(e) {
- if(e.index == 0) {
- old_back();
- } else {
- save(1);
- }
- })
- }else{
- old_back();
- }
- }
-
- function init(){
- if(type==1){//编辑
- $('#title').html("编辑新标签");
- $('#name').val(tagInfo.name);
- if(tagInfo.code==1 || tagInfo.code==2){
- $('.header-link').hide();
- $('#name').attr('readOnly', true);
- $('#memo').show().prev().hide();
- }
- $('#bjArea').show();
- } else{
- $('#title').html("添加新标签");
- $('#tjArea').show();
- }
- }
-
- function addMembers(data){
- var d = [];
- for(var k in data){
- d.push(data[k]);
- }
- var html = template('members_tmpl', {data: d});
- $('.lin-g-member .member').remove();
- $('#addBtn').before(html);
- iscroll.refresh();
- }
- function editMembers(type, dataBack){
- openWebview("bq-xinzengchengyuan.html", {
- type: type,
- teamCode: teamCode,
- tagInfo: tagInfo,
- dataBack: dataBack,
- checkeds: checkeds,
- num: num
- });
- }
-
- /**
- * 删除标签
- */
- function delTag(){
- sendPost("/doctor/patient_label/delete", {
- labelCode: tagInfo.code
- }, null, function(res){
- if(res.status == 200){
- mui.fire(self.opener(), "deleteTag", {code: tagInfo.code});
- mui.toast("删除标签成功!");
- self.close();
- } else
- mui.toast(res.msg);
- })
- }
-
- /**
- * 保存
- */
- function save(){
- var name = $.trim($('#name').val());
- if(type==1){
- sendPost("/doctor/patient_label/modify", {
- labelCode: tagInfo.code,
- newName: name
- }, null, function(res){
- if(res.status == 200){
- mui.toast("修改标签成功!");
- mui.fire(self.opener(), "refresh");
- old_back();
- } else
- mui.toast(res.msg);
- })
- return;
- }
-
- var patients = [];
- $.each($('.lin-g-member .member'), function(i, v) {
- patients.push($(v).attr('data-code'));
- });
-
- sendPost("/doctor/patient_label_info/label_and_patients_add", {
- labelName: name,
- teamCode: teamCode,
- patients: patients.join(",")
- }, null, function(res){
- if(res.status==200){
- mui.toast("保存成功!");
- mui.fire(self.opener(), "refresh");
- old_back();
- } else
- mui.toast(res.msg);
- })
- }
-
- $('#name').on('input', function(){
- var val = $.trim($(this).val());
- $('.link').toggleClass("c-ccc", val=="" || val==tagInfo.name);
- })
-
- /**
- * 删除标签按钮
- */
- $('.delButton').on('tap', function(){
- plus.nativeUI.showWaiting();
- sendPost("/doctor/patient_label_info/patients_by_label", {
- labelCode: tagInfo.code,
- labelType: "4",
- teamCode: teamCode,
- page: 1,
- pagesize: 1
- }, null, function(res){
- if(res.status == 200){
- plus.nativeUI.closeWaiting();
- if(res.data && res.data.length>0)
- mui.confirm("删除标签后,所有居民不再有该标签,是否确认删除该标签?", "提示", ["不了,谢谢", "确认删除"], function(e) {
- if(e.index == 1){
- delTag();
- }
- });
- else
- delTag();
- } else {
- plus.nativeUI.showWaiting();
- mui.toast("验证是否有居民出错!");
- }
- })
- })
-
- /**
- * 点击添加事件
- */
- $('#addBtn').on('tap', function(){
- editMembers("add", true);
- })
-
- /**
- * 删除事件
- */
- $('.lin-g-member').on('tap', '.del', function(){
- $(this).parent().remove();
- delete checkeds[$(this).parent().attr('data-code')];
- --num;
- iscroll.refresh();
- })
-
- /**
- * 删除成员跟新增成员按钮
- */
- $('#bjArea .button').on('tap', function(){
- editMembers($(this).attr('data-type'));
- })
-
- /**
- * 更新团队成员
- */
- window.addEventListener("updateTeamMember", function(e){
- num = e.detail.num;
- checkeds = e.detail.data;
- addMembers(e.detail.data);
- })
|