123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- // 基本信息(包括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<len; i++){
- var item = li_list[i],
- id = $(item).attr("data-id");
- id_list.push(id);
- }
- plus.nativeUI.showWaiting();
- var url = "doctor/reply/sortList",
- params = {id: id_list.join(",")};
- if(self.type == 'xufang'){
- params.type =1;//续方咨询排序标志
- }
- sendPost(url, params, null, function(res){
- var xufang = plus.webview.getWebviewById('xufangzixun')
- var xufang2 = plus.webview.getWebviewById('xufangzixun.html')
- setTimeout(function(){
- if(xufang){
- mui.fire(xufang, 'quickReplyRefresh');
- }
- if(xufang2){
- mui.fire(xufang2, 'quickReplyRefresh');
- }
- },500)
- mui.toast(res.msg);
- plus.nativeUI.closeWaiting();
- });
- }
- }
- });
- //删除图标的点击事件
- $("#reply_list").on('click', '.del-icon', function(){
- var parent = this.parentElement.parentElement;
- //点开显示删除按钮
- mui.swipeoutOpen(this.parentElement.parentElement);
- }).on('click','.mui-disabled', function(){
- var self = this,
- $this = $(this),
- $parent = $this.parent(),
- code = $parent.attr("data-id");
- plus.nativeUI.showWaiting();
- sendPost("doctor/reply/delete",{id:code},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();
- });
- }).on('click','.c-list-info',function(){
- mui.swipeoutClose(this.parentElement.parentElement);
- var editable = $(this).attr("contenteditable");
- if(editable == "false" && $("#edit_btn").attr("data-status")=="read"){
- //将结果放置到IM的输入框内
- var content = $(this).text();
- var type = $(this).attr('data-type')
- var opener = baseEnv.webview.opener();
- if(opener){
- mui.fire(opener, 'fillText', {content: content,type:type});
- old_back();
- }
- }
- }).on("input",'.c-list-info.ok-fill', function(e){
- var content = $(this).text(),
- len = content.length;
- if(content == " "){
- content = $.trim(content);
- len = content.length;
- }
- if(len > 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();
- });
|