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'+ '
'; $("#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 += '' + $(this).attr('data-name') + ''; }); $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 -1) { imgUrls.splice(i, 1); break; } } for(var j=0; jinfo->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(); } }