var self, patient, pregnancyNo; mui.plusReady(function(){ self = plus.webview.currentWebview(); pregnancyNo = self.pregnancyNo; patient = self.patient; var firstRecord = null,//保存记录 secondRecord = null, $view = $('#viewContain'); //区域滚动 mui('#main_text').scroll({ scrollY: true, //是否竖向滚动 scrollX: false, //是否横向滚动 bounce: false, //是否启用回弹 deceleration: 0.0005 }) mui('#nav_text').scroll({ scrollY: true, //是否竖向滚动 scrollX: false, //是否横向滚动 bounce: false, //是否启用回弹 deceleration: 0.0005 }) //侧屏 $('.cj-menu').on('tap',function(){ mui('.mui-off-canvas-wrap').offCanvas().show(); }) //切换 $('.cj-li').on('tap',function(){ var $this = $(this) if(!$this.hasClass('active')){ $this.addClass('active').siblings().removeClass('active') templateRender($this.attr('data-num')) setTimeout(function(){ mui('#main_text').scroll().scrollTo(0,0,0); mui('.mui-off-canvas-wrap').offCanvas().close(); },300) }else{ setTimeout(function(){ mui('.mui-off-canvas-wrap').offCanvas().close(); },300) } }) //请求模板 var templateRequest = function(num){ return new Promise(function(resolve, reject){ $.ajax('../template/'+num+'.html', { dataType: 'html', type:'GET', error: function(xht, type, throwErr) { mui.toast("模板获取失败"); }, success: function(html) { resolve(html); } } ) }) }, //请求模板数据 dataRequest = function(num){ return new Promise(function(resolve, reject){ if(num == 0 || num == 2){ if(!firstRecord){ plus.nativeUI.showWaiting(); sendPost("doctor/prenatalnspector/getEhrMaternalFirstExamRecord",{pregnancyNo:pregnancyNo,patient:patient}, function(){ plus.nativeUI.closeWaiting(); mui.toast("请求失败"); }, function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200){ if(! $.isEmptyObject(res.data)){ firstRecord = res.data resolve(res.data) }else{ mui.toast('查无数据') } }else{ mui.toast('请求数据失败') return } },'get') }else{ resolve(firstRecord) } } if(num == 1){ if(!secondRecord){ plus.nativeUI.showWaiting(); sendPost("doctor/prenatalnspector/getEhrMaternalReExamRecord",{pregnancyNo:pregnancyNo,patient:patient}, function(){ plus.nativeUI.closeWaiting(); mui.toast("请求失败"); }, function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200){ if(! $.isEmptyObject(res.data)){ secondRecord = res.data resolve(res.data) }else{ mui.toast('查无数据') } }else{ mui.toast('请求数据失败') return } },'get') }else{ resolve(secondRecord) } } }) }, bindEvent = function(){ //展开 $('.cj-section').on('tap','.up.icon',function(){ var $this = $(this).parent() if($this.hasClass('active')){ $this.removeClass('active') }else{ $this.addClass('active') } }) } //渲染 function templateRender(num){ Promise.all([templateRequest(num),dataRequest(num)]).then(function(datas){ $view.html(datas[0]) $view.removeAttr('avalonctrl').attr('ms-controller',"template"); var vm = avalon.define($.extend({"$id": "template"},{data:datas[1]})) avalon.scan(); }).then(function(){ //隐藏都没有的模块 for(var i=0; i<$('.cj-section').length;i++){ var $this = $('.cj-section').eq(i) if($this.find('.cj-position-1').length == 0 && $this.find('.cj-flex-1').length == 0){ $this.hide() } } bindEvent() }) } //初始化 templateRender(0) })