| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 | 
							- var action,
 
-     code ,
 
-     reference, //标记入口
 
-     patiCode,
 
-     is_sys = false,
 
-     content_details,
 
-     uploadImages = [],
 
-     imMsg = '',
 
-     imgUrls = [];
 
- var $text_count = $("#text_count"),
 
-     text_count = 0,
 
-     $img_count = $("#img_count"),
 
-     img_count = 0,
 
-     $view_btn = $("#view_btn"),
 
-     $action_btn = $("#action_btn");
 
- mui.init();
 
- mui.plusReady(function(){
 
-     var self = plus.webview.currentWebview();
 
-     action = self.action;
 
-     reference = self.reference;
 
-     imMsg = self.msg;
 
-     is_sys = self.is_sys;
 
-     code = self.code;
 
-     patiCode = self.patiCode;
 
-     content_details = self.content_details;
 
-     
 
-     if (imMsg) {
 
-     	$("textarea").val(imMsg);
 
-         var count = imMsg.length;
 
-         $text_count.text(count);
 
-     }
 
-     
 
-     var title = (action == "add") ? "新增" : "编辑";
 
-     $("#title").text(title);
 
-     
 
-     var action_text = "";
 
-     if(reference != "mine"){
 
-         var text = "是否将变更保存到原模板";
 
-         if(is_sys || action == "add"){
 
-             text = "是否保存为您的模板";
 
-         }
 
-         $("#save_as_self").find(".c-list-key").text(text);
 
-         $("#save_as_self").show();
 
-         action_text = "发送";
 
-     }else{
 
-         if(action == "add"){
 
-             action_text = "新增";
 
-         }else{
 
-             action_text = "保存";
 
-         }
 
-     }
 
-     $action_btn.text(action_text);
 
-     getDetail();
 
-     bindEvents();
 
- });
 
- function getDetail(){
 
-     if(content_details){
 
-         $("#temp_name").val(content_details.modelName);
 
-         $("textarea").val(content_details.content);
 
-         $("#text_count").text(content_details.content.length);
 
-         imgUrls = content_details.imagesUrls;
 
-         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();
 
-                 }
 
-             } else {
 
-                 mui.toast("上传图片失败!");
 
-                 plus.nativeUI.closeWaiting();
 
-             }
 
-         });
 
-         var url = uploadImages[upload_count];
 
-         task.addFile(url, {key: "file"});
 
-         task.start();
 
-     }else{
 
-         cb();
 
-     }
 
- }
 
- function bindEvents(){
 
-     $("#add").on('click', function(){
 
-         if(img_count < 9){
 
- //      	alert(img_count);
 
-         	var num = 9 - (img_count || 0);
 
-             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(imgUrls[i] == url) {
 
-             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);
 
-     });
 
-     
 
-     //预览功能
 
-     $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("preview_detail.html",{
 
-             code: code, 
 
-             detail:{content: content, images: images, imgUrls: imgUrls, uploadImages: uploadImages, title: $("#temp_name").val()},
 
-             reference: reference,
 
-             patiCode: patiCode,
 
-             is_sys: is_sys,
 
-             checked: $(".mui-switch").hasClass("mui-active")
 
-         });
 
-     });
 
-     
 
-     //action 按钮
 
-     $action_btn.on('tap', function(){
 
-         var content = $.trim($("textarea").val());
 
-         if(content.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '指导内容不能为空!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         var title = $.trim($("#temp_name").val());
 
-         if(title.length == 0){
 
-             dialog({
 
-                 contentType: 'tipsbox',
 
-                 skin: 'bk-popup',
 
-                 content: '模板名称不能为空!',
 
-                 closeTime: 2000
 
-             }).showModal();
 
-             return false;
 
-         }
 
-         
 
-         //IM入口
 
-         var url = "";
 
-         var params = {
 
-             content: $("textarea").val(),
 
-             modelName: $("#temp_name").val()
 
-         };
 
-         if(reference != "mine"){
 
-             dialog({
 
-                 content: "发出后无法变更,是否确认发送给居民?",
 
-                 okValue: "继续发送",
 
-                 ok: function(){
 
-                     plus.nativeUI.showWaiting();
 
-                     //先将新增的图片上传然后再处理其他业务
 
-                     uploadImg(function(){
 
-                         params.imagesUrl = imgUrls?imgUrls.join(","):"";
 
-                         var checked = $(".mui-switch").hasClass("mui-active");
 
-                         var reqInfo = [];
 
-                         if(checked) {
 
-                             if(is_sys || (action == "add")){
 
-                                 //先将内容保存为自己模板
 
-                                 url = "/doctor/guidance_temp/add";
 
-                             }else{
 
-                                 url = "/doctor/guidance_temp/modify";
 
-                                 params.code = code;
 
-                             }
 
-                             reqInfo.push({url: url, data: params, reqType: 'POST'});
 
-                         }
 
-                         reqInfo.push({
 
-                             url: "/doctor/health/guidance/add",
 
-                             data: {
 
-                                 patient: patiCode,
 
-                                 content: $("textarea").val(),
 
-                                 modelCode: code || "",
 
-                                 images: imgUrls?imgUrls.join(","):""
 
-                             }
 
-                         });
 
-                         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.modelCode = res.modelCode;
 
-                     				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.imagesUrl = imgUrls ? imgUrls.join(","): "";
 
-                 if((action == "add") || is_sys){
 
-                     //新增模板或将系统模板保存为自己的
 
-                     url = "/doctor/guidance_temp/add";
 
-                 }else{
 
-                     //编辑
 
-                     url = "/doctor/guidance_temp/modify";
 
-                     params.code = code;
 
-                 }
 
-                 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" || opener.id == "jkzd"){ //mine->add
 
- //      mui.fire(opener, 'refresh');
 
-     	opener.reload(true);
 
-         self.close();
 
-     }else if(pre_opener.id == "guidance_list" || pre_opener.id == "jkzd"){ //mine->detail->edit
 
- //      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");
 
-     		pre_pre_opener.reload(true);
 
-         mui.later(function(){
 
-             pre_opener.close();
 
-             opener.close();
 
-             self.close();
 
-         }, 300);
 
-         pre_pre_opener.show();
 
-     }
 
- }
 
 
  |