| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 | 
							- var action,
 
-     code ,
 
-     reference, //标记入口
 
-     patiCode,
 
-     teamList,
 
-     teamId,
 
-     docInfo,
 
-     tName,
 
-     tId,
 
-     is_sys = false,
 
-     content_details,
 
-     uploadImages = [],
 
-     imMsg = '',
 
-     imgUrls = [],
 
-     teams= '';
 
- var $text_count = $("#text_count"),
 
-     text_count = 0,
 
-     $img_count = $("#img_count"),
 
-     img_count = 0,
 
-     $view_btn = $("#view_btn"),
 
-     $teamDown = $('.team-down'),
 
-     $comtop = $('.demo-comtop'),
 
-     $linMask = $('.lin-mask'),
 
-     $linSelGroup = $('.lin-sel-group'),
 
-     $action_btn = $("#action_btn")
 
-     $inTeams = $("#inTeams"),
 
-     $teamNameCon = $('.team-name-con');
 
- mui.init();
 
- mui.plusReady(function(){
 
- 	docInfo = JSON.parse(plus.storage.getItem("docInfo"));
 
-     var self = plus.webview.currentWebview();
 
-     action = self.action;
 
-     reference = self.reference;
 
-     imMsg = self.msg;
 
-     code = self.code;
 
-     teamList = self.teamList;
 
-     patiCode = self.patiCode;
 
-     teamId = self.teamId;
 
-     tName = self.tName;
 
-     tId = self.tId;
 
-     content_details = self.content_details;
 
-     
 
-     if (imMsg) {
 
-     	$("textarea").val(imMsg);
 
-     }
 
-     
 
-     var title = (action == "add") ? "新增" : "编辑";
 
-     $("#title").text(title);
 
-     
 
-     var action_text = "";
 
-     if(reference != "mine"){
 
-         getTeams();
 
-         var text = "是否保存为您的模板";
 
-         $("#save_as_self").find(".c-list-key").text(text);
 
-         $("#save_as_self").show();
 
-         action_text = "发送";
 
-     }else{
 
-         getTeams();
 
-         if(action == "add"){
 
-             plus.nativeUI.showWaiting(); 
 
-             action_text = "新增";
 
-         }else{
 
-             action_text = "保存";
 
-         }
 
-     }
 
-     $action_btn.text(action_text);
 
-     getDetail();
 
-     bindEvents();
 
-     
 
-     
 
-     
 
- });
 
- //获取团队
 
- function getTeams () {
 
- 	sendGet( 'doctor/team/guidance/getDoctorTeams', {}, null, function(res){
 
-         if(res.status == 200){
 
-         	var d = [],
 
-         		html = '';
 
-         	if (teamList) {
 
-         		d = teamList;
 
- 				teams = JSON.stringify(d);
 
-         	} else {
 
- //      		d = res.teamList;
 
- //				teams = JSON.stringify(res.teamList);
 
- 				teams = JSON.stringify([{
 
- 					teamName: tName,
 
- 					teamId: tId
 
- 				}]);
 
-         	}
 
-         	for (var i = 0, len = d.length; i < len; i++) {
 
- 				html += d[i].teamName + ',';
 
-         	}
 
-         	if (action == 'add') {
 
-         		html = tName;
 
-         	} else {
 
-         		html = html.substring( 0, html.length - 1);
 
-         	}
 
-         	$teamNameCon.html(html);
 
- 			template.helper( 'checkData', function (v) {
 
- 				if (teamList) {
 
- 					for (var i = 0,len = teamList.length; i < len; i++) {
 
- 						if (v == teamList[i].teamId) {
 
- 							return 'selected';
 
- 						}
 
- 					}
 
- 				} else {
 
- 					if (v == tId) {
 
- 						return 'selected';
 
- 					}
 
- //					return 'selected';
 
- 				}
 
- 			});
 
- 			$('#demo').html(template( 'seleceTmp', {data: res.teamList}));
 
- 			$('#demo').mobiscroll().select({
 
- 		        theme: 'ios',
 
- 		        display: 'bottom',
 
- 				lang: 'zh',
 
- 				onSelect: function ( valueText, inst) {
 
- 					var vArr = valueText.split(','),
 
- 						idArr = inst._tempValue,
 
- 						t = [];
 
- 					for (var i = 0; i < idArr.length; i++) {
 
- 						t.push({
 
- 							teamName: vArr[i].trim(),
 
- 							teamId: parseInt(idArr[i])
 
- 						})
 
- 					}
 
- 					teams = JSON.stringify(t);
 
- 					$teamNameCon.html(inst._value);
 
- 				}
 
- 		   });
 
-         } else {
 
-         	mui.toast(res.msg);
 
-         }
 
-         plus.nativeUI.closeWaiting();
 
-     }, 'GET', '', true);
 
- }
 
- function getDetail(){
 
-     if(content_details){
 
-         $("#temp_name").val(content_details.title);
 
-         $("textarea").val(content_details.content);
 
-         $("#text_count").text(content_details.content.length);
 
-         imgUrls = content_details.imagesUrl;
 
-         if(imgUrls){ //填充模板中图片
 
-             for(i=0; i<imgUrls.length; i++){
 
-                 fillImage(getImgUrl(imgUrls[i]));
 
-             }
 
-         }else{
 
-             imgUrls = [];
 
-         }
 
-     }
 
- }
 
- function getPhoto(url){
 
-     uploadImages.push(url);
 
-     fillImage(url);
 
- }
 
- function fillImage(url){
 
-     img_count ++;
 
-     $img_count.text(img_count);
 
-     var html = '<div class="c-position-r fl mr15 mt20"><img class="upload_img" src="'+url+'" width="65" height="65">'+
 
-                 '<div class="delete-icon"><img src="../images/delete_icon.png" width="18"></div></div>';
 
-     $("#img_wrap").append(html);
 
- }
 
- //上传图片
 
- var upload_count = 0;
 
- function uploadImg(cb){
 
-     var len = uploadImages.length;
 
-     if(upload_count < len){
 
-         var task = plus.uploader.createUpload(server + "/upload/fastDFSImag", {
 
-             method: "post"
 
-         }, function(t, sta) {
 
-             if(sta == 200) {
 
-                 var msg = t.responseText;
 
-                 var oImg = JSON.parse(msg);
 
- //              var imgUrl = oImg.urls;
 
- //              var re = new RegExp("\\\\", "g");
 
- //              imgUrl = imgUrl.replace(re, "/");
 
- //              imgUrls.push(imgUrl);
 
- //              uploadImg(cb);
 
-                 if(oImg.status == 200){
 
-                     imgUrls.push(oImg.data);
 
-                     upload_count ++;
 
-                     uploadImg(cb);
 
-                 }else{
 
-                     mui.toast("上传图片失败!");
 
-                     plus.nativeUI.closeWaiting();
 
-                 }
 
- //              setTimeout(function () {
 
- //              	uploadImg(cb);
 
- //              },300);
 
-             } else {
 
-                 mui.toast("上传图片失败!");
 
-                 plus.nativeUI.closeWaiting();
 
-             }
 
-         });
 
-         var url = uploadImages[upload_count];
 
- //      upload_count ++;
 
-         task.addFile(url, {key: "file"});
 
-         task.start();
 
-     }else{
 
-         cb();
 
-     }
 
- }
 
- function showGroupSel (e, isShow) {
 
- 	isShow = isShow || $('.lin-mask:hidden').length != 0;
 
- 	$linMask.toggle(isShow);
 
- 	$linSelGroup.toggle(isShow);
 
- }
 
- function bindEvents(){
 
- 	//团队选择
 
- 	$inTeams.on('click', function (){
 
- 		$('#demo').trigger('click');
 
- 	});
 
-     $linMask.on( 'tap', function (e) {
 
- 		showGroupSel(e);
 
- 		var lis = $linSelGroup.find('[class=checked]'),
 
- 			ts = [],
 
- 			html = "";
 
- 		$.each( lis, function () {
 
- 			ts.push({
 
- 				teamName: $(this).attr('data-name'),
 
- 				teamId: $(this).attr('data-id')
 
- 			});
 
-     		html += '<span>' + $(this).attr('data-name') + '</span>';
 
- 		});
 
-     	$teamNameCon.html(html);
 
-     	teams = JSON.stringify(ts);
 
-     });
 
-     
 
-     $linSelGroup.on('tap', 'li', function(){
 
-     	if ($(this).hasClass('checked')) {
 
-     		$(this).removeClass('checked');
 
-     	} else {
 
-     		$(this).addClass('checked');
 
-     	}
 
- 	});
 
- 	
 
- 	
 
- 	
 
-     $("#add").on('click', function(){
 
-         if(img_count < 9){
 
-         	var num = 9 - img_count;
 
-             getAutoRecCompressImageLocalPath( getPhoto, num);
 
-         }else{
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '最多只能上传9张图片',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-         }
 
-     });
 
-     
 
-     //图片删除功能
 
-     $(document).on('tap', '.delete-icon', function(){
 
-         var $this = $(this);
 
-         //获得图片路径
 
-         var url = $this.parent().find(".upload_img").attr("src");
 
-         for(var i=0; i<imgUrls.length; i++) {
 
-             if(url.indexOf(imgUrls[i]) > -1) {
 
-                 imgUrls.splice(i, 1);
 
-                 break;
 
-             }
 
-         }
 
-         for(var j=0; j<uploadImages.length; j++){
 
-             if(uploadImages[j] == url){
 
-                 uploadImages.splice(j, 1);
 
-                 break;
 
-             }
 
-         }
 
-         img_count --;
 
-         $img_count.text(img_count);
 
-         $this.parent().remove();
 
-     });
 
-     
 
-     //文本框
 
-     $("textarea").on('keyup', function(){
 
-         var count = $(this).val().length;
 
-         $text_count.text(count);
 
-     });
 
-     $("textarea").on('change', function(){
 
-         var count = $(this).val().length;
 
-         $text_count.text(count);
 
-     });
 
-     
 
-     //预览功能
 
-     $view_btn.on('tap', function(){
 
-         var content = $("textarea").val(),
 
-             $images_list = $(".upload_img"),
 
-             images = [];
 
-         
 
-         
 
-         for(i=0; i<img_count; i++){
 
-             var item = $images_list[i];
 
-             images.push($(item).attr("src"));
 
-         }
 
-         
 
-         if(content.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '请填先写模板内容!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         
 
-         openWebview("yulantuanduimuban.html",{
 
-             teams: teams, 
 
-             code: code,
 
-             detail:{content: content, images: images, imgUrls: imgUrls, uploadImages: uploadImages, title: $("#temp_name").val()},
 
-             reference: reference,
 
-             patiCode: patiCode,
 
-             checked: $(".mui-switch").hasClass("mui-active"),
 
-             teamId: teamId
 
-         });
 
-     });
 
-     
 
-     
 
- //  $(".mui-switch").on( 'tap', function () {
 
- //  	if ($(this).hasClass("mui-active")) {
 
- //  		$('#mbName').show();
 
- //  	} else {
 
- //  		$('#mbName').hide();
 
- //  	}
 
- //  });   
 
-     
 
-     
 
-     //action 按钮
 
-     $action_btn.on('tap', function(){
 
-         var content = $.trim($("textarea").val()),
 
-         	tArr = JSON.parse(teams);
 
-         var title = $.trim($("#temp_name").val());
 
-         var checked = $(".mui-switch").hasClass("mui-active");
 
-         if(checked && title.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '模板名称不能为空!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         if(content.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '指导内容不能为空!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         if(tArr.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '请选择所属团队!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         
 
-         //IM入口
 
-         var url = "";
 
-         var params = {
 
-             content: $("textarea").val(),
 
-             title: $("#temp_name").val()
 
-         };
 
-         if(reference != "mine"){
 
-             dialog({
 
-                 content: "发出后无法变更,是否确认发送给居民?",
 
-                 okValue: "继续发送",
 
-                 ok: function(){
 
-                     plus.nativeUI.showWaiting();
 
-                     //先将新增的图片上传然后再处理其他业务
 
-                     uploadImg(function(){
 
-                         params.images = imgUrls?imgUrls.join(","):"";
 
-                         params.teamInfo = teams;
 
-                         params.isLeader = docInfo.isLeader;
 
-                         if(checked){
 
-                             //先将内容保存为自己模板
 
-                             params.saveAsGuidance = 1;
 
-                         } else {
 
-                             params.saveAsGuidance = 0;
 
-                         }
 
-                         if(action == "add"){
 
-                             url = "doctor/team/guidance/saveTeamGuidance";
 
-                         }else{
 
-                             //编辑
 
-                             url = "doctor/team/guidance/modifyTeamGuidance";
 
-                             params.guidanceCode = code;
 
-                             params.isLeader = docInfo.isLeader;
 
-                             
 
-                         }
 
-                         
 
-                         var reqInfo = [];
 
-                         
 
-                         if(checked){
 
-                             reqInfo.push({url: url, data: params, reqType: 'POST'});
 
-                         }
 
-                         //团队模板发送时只和医生点击哪个团队中的模板有关,指导绑定的另外的团队没有关系
 
-                         var list = JSON.parse(teams);
 
-                         var chooseTeam = _.find(list, {teamId: parseInt(tId)}),
 
-                             arr = [];
 
-                         if(chooseTeam){
 
-                             arr.push(chooseTeam);
 
-                         }else{
 
-                             //匹配不了说明医生修改了指导所属的 团队,并且入口团队并不在选中的列表中。则默认选择选中团队中的第一个团队来发送
 
-                             arr.push(list[0]);
 
-                         }
 
-                         
 
-                         reqInfo.push({
 
-                             url: "doctor/team/guidance/sendTeamGuidance",
 
-                             data: {
 
-                                 patient: patiCode,
 
-                                 content: $("textarea").val(),
 
-                                 guidanceCode: code || "",
 
-                                 images: imgUrls?imgUrls.join(","):"",
 
- //                              teamId: teamId 
 
- 								teamId: JSON.stringify(arr)
 
-                             }
 
-                         });
 
-                         if(reqInfo.length == 1) {
 
-                         	return getReqPromises(reqInfo, true).then(function(res) {
 
- 	                            if(res[0].status == 200){
 
- 	                                mui.toast("发送成功");
 
- 	                                otherBackAction();
 
- 	                            } else {
 
- 	                                mui.toast("发送失败请重试 !");
 
- 	                            }
 
- 	                            plus.nativeUI.closeWaiting();
 
- 	                        })
 
-                         }else{
 
-                         	return getReqPromise(reqInfo[0].url, reqInfo[0].data, "POST", true).then(function(res) {
 
-                     			if(res.status == 200) {
 
-                     				reqInfo[1].data.guidanceCode = res.guidanceCode;
 
-                     				getReqPromise(reqInfo[1].url, reqInfo[1].data, "POST", true).then(function(res1) {
 
- 	                        			if(res1.status == 200) {
 
- 	                        				mui.toast("发送成功!");
 
- 	                        				otherBackAction();
 
- 	                        			} else {
 
- 	                        				mui.toast( "保存成功,发送失败!")
 
- 	                        			}
 
- 	                        		})
 
-                     			} else {
 
-                     				mui.toast(res.msg || "保存失败无法发送!")
 
-                     			}
 
-                     			plus.nativeUI.closeWaiting();
 
-                     		})
 
-                        }
 
-                     });
 
-                 },
 
-                 cancelValue : "不了,谢谢",
 
-                 cancel: function(){}
 
-             }).showModal();
 
-         }else{ //“我的”入口
 
-             //先将新增的图片上传然后再处理其他业务
 
-             plus.nativeUI.showWaiting();
 
-             uploadImg(function(){
 
-                 params.images = imgUrls ? imgUrls.join(","): "";
 
-                 params.teamInfo = teams;
 
-                 if((action == "add") || is_sys){
 
-                     //新增模板或将系统模板保存为自己的
 
-                     url = "doctor/team/guidance/saveTeamGuidance";
 
-                 }else{
 
-                 	params.saveAsGuidance = 0;
 
-                 	params.guidanceCode = code;
 
-  	              	params.isLeader = docInfo.isLeader;
 
-                     //编辑
 
-                     url = "doctor/team/guidance/modifyTeamGuidance";
 
-                 }
 
-                 sendPost(url, params, null, function(res){
 
-                     if(res.status == 200){
 
-                         mineBackAction();
 
-                     }
 
-                     mui.toast(res.msg);
 
-                     plus.nativeUI.closeWaiting();
 
-                 }, 'POST', '', true);
 
-             });
 
-         }
 
-     });
 
- }
 
- function otherBackAction(){
 
-     var self = plus.webview.currentWebview(),
 
-         opener = self.opener(),
 
-         grant_opener = opener.opener();
 
-     if(opener.id == "jkzd" || opener.id == "guidance_list"){ //新增
 
-         if(grant_opener.id == "guidance_info"){
 
-             //im->info->list->add
 
-             var pre_opener = grant_opener.opener();
 
-             mui.fire(pre_opener, "update");
 
-             pre_opener.show();
 
-             mui.later(function(){
 
-                 grant_opener.close();
 
-                 opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }else{
 
-             //IM/huanzhexinxi->新增页面
 
-             mui.fire(grant_opener, "update");
 
-             grant_opener.show();
 
-             mui.later(function(){
 
-                 opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }
 
-         
 
-     }else if(grant_opener.id == "jkzd" || grant_opener.id == "guidance_list"){ //详情 -> 编辑
 
-         var pre_opener = grant_opener.opener();
 
-         if(pre_opener.id == "guidance_info"){
 
-             //im/huanzhexinxi -> info->list->detail->edit
 
-             mui.fire(pre_opener.opener(), "update");
 
-             pre_opener.opener().show();
 
-             mui.later(function(){
 
-                 opener.close();
 
-                 grant_opener.close();
 
-                 pre_opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }else{
 
-             //IM/huanzhexinxi->list->detail->edit
 
-             mui.fire(pre_opener, "update");
 
-             pre_opener.show();
 
-             mui.later(function(){
 
-                 opener.close();
 
-                 grant_opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }
 
-     }else{ //sys->detail->edit
 
-         var pre_opener = grant_opener.opener(),
 
-             pre_pre_opener = pre_opener.opener();
 
-         if(pre_pre_opener.id == "guidance_info"){
 
-             //IM/huanzhexinxi->info->list->sys->detail->edit
 
-             mui.fire(pre_pre_opener.opener(), "update");
 
-             pre_pre_opener.opener().show();
 
-             mui.later(function(){
 
-                 pre_pre_opener.close();
 
-                 pre_opener.close();
 
-                 grant_opener.close();
 
-                 opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }else{
 
-             //IM/huanzhexinxi->list->sys->detail->edit
 
- //          var entrance = grant_opener.opener().opener();
 
-             mui.fire(pre_pre_opener, "update");
 
-             pre_pre_opener.show();
 
-             mui.later(function(){
 
-                 pre_opener.close();
 
-                 grant_opener.close();
 
-                 opener.close();
 
-                 self.close();
 
-             }, 300);
 
-         }
 
-     }
 
- }
 
- function mineBackAction(){
 
-     var self = plus.webview.currentWebview(),
 
-         opener = self.opener(),
 
-         pre_opener = opener.opener();
 
-     if(opener.id == "guidance_list"){ //mine->add
 
-         mui.fire(opener, 'refresh');
 
- //  	opener.reload(true);
 
-         self.close();
 
-         mui.back();
 
-     } else if(opener.id == "chakantuanduimuban"){
 
-         mui.fire(pre_opener, "refresh");
 
- //  	pre_opener.reload(true);
 
-         mui.later(function(){
 
-             opener.close();
 
-             self.close();
 
-         }, 300);
 
-         pre_opener.show();
 
-     }  else if (opener.id == 'p2dzixun' || opener.id == 'p2p') {
 
-         mui.fire(pre_opener, "refresh");
 
-         mui.later(function(){
 
-             self.close();
 
-         }, 300);
 
-         opener.show();
 
-     }else{ //mine->sys->detail->edit
 
-         var pre_pre_opener = pre_opener.opener();
 
-         mui.fire(pre_pre_opener, "refresh");
 
-         mui.later(function(){
 
-             pre_opener.close();
 
-             opener.close();
 
-             self.close();
 
-         }, 300);
 
-         pre_pre_opener.show();
 
-     }
 
- }
 
 
  |