// 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview、encry相关) baseEnv = null, self, docInfo = null; var sort,touchtime, item_offset = { left: '', top: '' }; var old_back = mui.back; // 获取登录相关信息 var getBaseInfo = function() { docInfo = JSON.parse(plus.storage.getItem("docInfo")); // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")); return { userAgent: userAgent } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus.webview.currentWebview() }; mui.back = function(){ var index = plus.webview.getWebviewById("index"); mui.fire(index, 'refresh'); plus.webview.currentWebview().close(); } // 因为有异步请求,需要等待数据返回之后进行处理,所以返回Promise return Promise.resolve().then(function(res) { return env; }); }, initPage = function(){ plus.nativeUI.showWaiting(); $("#edit_btn").text("编辑"); $("#edit_btn").attr("data-status", "read"); $("#reply_list").find(".c-list-key").hide(); $(".c-list-info").attr("contenteditable","false"); var params={} if(self.type == 'xufang'){ params.type=1 } sendGet("doctor/reply/list",params,null,function(res){ $("#reply_list").empty().append(template('reply_list_tmp',{list: res.data})); plus.nativeUI.closeWaiting(); }); }, bindEvents = function(){ sort = new Sortable(document.getElementById("reply_list"), { chosenClass: 'sort-chosen', ghostClass: 'sort-ghost', scroll: true, // delay:300, animation: 400, handle: '.drag-handle', isDropAnimation: false, //自定义属性 onStart: function( /**Event*/ evt) { // 拖拽 //console.log(new Date(evt.timeStamp).toLocaleString()); //console.log(evt.oldIndex); touchtime = evt.timeStamp; item_offset.left = evt.item.offsetLeft; item_offset.top = evt.item.offsetTop; var itemEl = evt.item; }, onEnd: function( /**Event*/ evt) { // 拖拽 var itemEl = evt.item; //console.log(new Date(evt.timeStamp).toLocaleString()); var timespan = evt.timeStamp - touchtime; //console.log(evt.timeStamp - touchtime); if (timespan < 200) {} else if (itemEl.offsetLeft == item_offset.left && itemEl.offsetTop == item_offset.top) {} else { // reset_order(); //TODO 还有一个bug未处理,重新排序后,预览图片并返回时offset位置不对,应提供方法重置previewimg } touchtime = null; //将保存按钮高亮 $("#edit_btn").removeClass("disabled"); }, }); //编辑按钮的点击事件 $("#edit_btn").on('click', function(){ var status = $(this).attr("data-status"); if(status == "read"){ $(this).text("保存排序"); $(this).addClass("disabled"); $(this).attr("data-status", "edit"); $("#reply_list").find(".c-list-key").show(); $(".c-list-info.ok-fill").attr("contenteditable","true"); } if(status == "edit"){ if(!$(this).hasClass("disabled")){ $(this).text("编辑"); $(this).attr("data-status", "read"); $("#reply_list").find(".c-list-key").hide(); $(".c-list-info").attr("contenteditable","false"); //保存排序 var li_list = $("#reply_list").find("li"), len = li_list.length, id_list = []; for(i=0; i 100){ $(this).text(content.substr(0, 100)); var range = document.createRange(); range.selectNodeContents(this); range.collapse(false); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } }).on('blur','.c-list-info.ok-fill', function(){ var editable = $(this).attr("contenteditable"), $parent = $(this).closest("li"), id = $(this).closest("li").attr("data-id"); if(editable == "true"){ //保存编辑的内容 if($.trim($(this).text()).length == 0){ //清空内容默认删除该内容 plus.nativeUI.showWaiting(); sendPost("doctor/reply/delete",{id:id},null, function(res){ if(res.status == 200){ var xufang = plus.webview.getWebviewById('xufangzixun') setTimeout(function(){ if(xufang){ mui.fire(xufang, 'quickReplyRefresh'); } },500) $parent.remove(); mui.toast("删除成功"); }else{ // mui.toast(res.msg); } plus.nativeUI.closeWaiting(); }); }else{ var url = "doctor/reply/modify", params = {id: id, content: $(this).text()}; if(self.type == 'xufang'){ params.type = 1 } plus.nativeUI.showWaiting(); sendPost(url, params, null, function(res){ if(res.status == 200){ mui.toast("修改成功"); var xufang = plus.webview.getWebviewById('xufangzixun') setTimeout(function(){ if(xufang){ mui.fire(xufang, 'quickReplyRefresh'); } },500) } plus.nativeUI.closeWaiting(); }); } } }) $("#add_reply").on('click', function(){ if(self.type == 'xufang'){ openWebview("add_reply.html",{type:'xufang'}); }else{ openWebview("add_reply.html"); } $("#edit_btn").text("编辑"); $("#edit_btn").attr("data-status", "read"); $("#edit_btn").removeClass("disabled"); $("#reply_list").find(".c-list-key").hide(); $(".c-list-info").attr("contenteditable","false"); }) }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { self = plus.webview.currentWebview(); // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { old_back = mui.back; mui.back = function(){ if($("#edit_btn").attr("data-status") == "edit"){ //编辑状态时点击返回,退出编辑状态 $("#edit_btn").text("编辑"); $("#edit_btn").removeClass("disabled"); $("#edit_btn").attr("data-status", "read"); $("#reply_list").find(".c-list-key").hide(); $(".c-list-info").attr("contenteditable","false"); }else{ old_back(); } } // 获取登录医生信息 baseInfo = getBaseInfo(); //初始化页面内容 initPage(); // 绑定页面事件 bindEvents(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); }); window.addEventListener("refresh", function(){ initPage(); });