chanjianjieguo.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. var self,
  2. patient,
  3. pregnancyNo;
  4. mui.plusReady(function(){
  5. self = plus.webview.currentWebview();
  6. pregnancyNo = self.pregnancyNo;
  7. patient = self.patient;
  8. var firstRecord = null,//保存记录
  9. secondRecord = null,
  10. $view = $('#viewContain');
  11. //区域滚动
  12. mui('#main_text').scroll({
  13. scrollY: true, //是否竖向滚动
  14. scrollX: false, //是否横向滚动
  15. bounce: false, //是否启用回弹
  16. deceleration: 0.0005
  17. })
  18. mui('#nav_text').scroll({
  19. scrollY: true, //是否竖向滚动
  20. scrollX: false, //是否横向滚动
  21. bounce: false, //是否启用回弹
  22. deceleration: 0.0005
  23. })
  24. //侧屏
  25. $('.cj-menu').on('tap',function(){
  26. mui('.mui-off-canvas-wrap').offCanvas().show();
  27. })
  28. //切换
  29. $('.cj-li').on('tap',function(){
  30. var $this = $(this)
  31. if(!$this.hasClass('active')){
  32. $this.addClass('active').siblings().removeClass('active')
  33. templateRender($this.attr('data-num'))
  34. setTimeout(function(){
  35. mui('#main_text').scroll().scrollTo(0,0,0);
  36. mui('.mui-off-canvas-wrap').offCanvas().close();
  37. },300)
  38. }else{
  39. setTimeout(function(){
  40. mui('.mui-off-canvas-wrap').offCanvas().close();
  41. },300)
  42. }
  43. })
  44. //请求模板
  45. var templateRequest = function(num){
  46. return new Promise(function(resolve, reject){
  47. $.ajax('../template/'+num+'.html',
  48. { dataType: 'html',
  49. type:'GET',
  50. error: function(xht, type, throwErr) {
  51. mui.toast("模板获取失败");
  52. },
  53. success: function(html) {
  54. resolve(html);
  55. }
  56. }
  57. )
  58. })
  59. },
  60. //请求模板数据
  61. dataRequest = function(num){
  62. return new Promise(function(resolve, reject){
  63. if(num == 0 || num == 2){
  64. if(!firstRecord){
  65. plus.nativeUI.showWaiting();
  66. sendPost("doctor/prenatalnspector/getEhrMaternalFirstExamRecord",{pregnancyNo:pregnancyNo,patient:patient}, function(){
  67. plus.nativeUI.closeWaiting();
  68. mui.toast("请求失败");
  69. }, function(res){
  70. plus.nativeUI.closeWaiting();
  71. if(res.status == 200){
  72. if(! $.isEmptyObject(res.data)){
  73. firstRecord = res.data
  74. resolve(res.data)
  75. }else{
  76. mui.toast('查无数据')
  77. }
  78. }else{
  79. mui.toast('请求数据失败')
  80. return
  81. }
  82. },'get')
  83. }else{
  84. resolve(firstRecord)
  85. }
  86. }
  87. if(num == 1){
  88. if(!secondRecord){
  89. plus.nativeUI.showWaiting();
  90. sendPost("doctor/prenatalnspector/getEhrMaternalReExamRecord",{pregnancyNo:pregnancyNo,patient:patient}, function(){
  91. plus.nativeUI.closeWaiting();
  92. mui.toast("请求失败");
  93. }, function(res){
  94. plus.nativeUI.closeWaiting();
  95. if(res.status == 200){
  96. if(! $.isEmptyObject(res.data)){
  97. secondRecord = res.data
  98. resolve(res.data)
  99. }else{
  100. mui.toast('查无数据')
  101. }
  102. }else{
  103. mui.toast('请求数据失败')
  104. return
  105. }
  106. },'get')
  107. }else{
  108. resolve(secondRecord)
  109. }
  110. }
  111. })
  112. },
  113. bindEvent = function(){
  114. //展开
  115. $('.cj-section').on('tap','.up.icon',function(){
  116. var $this = $(this).parent()
  117. if($this.hasClass('active')){
  118. $this.removeClass('active')
  119. }else{
  120. $this.addClass('active')
  121. }
  122. })
  123. }
  124. //渲染
  125. function templateRender(num){
  126. Promise.all([templateRequest(num),dataRequest(num)]).then(function(datas){
  127. $view.html(datas[0])
  128. $view.removeAttr('avalonctrl').attr('ms-controller',"template");
  129. var vm = avalon.define($.extend({"$id": "template"},{data:datas[1]}))
  130. avalon.scan();
  131. }).then(function(){
  132. //隐藏都没有的模块
  133. for(var i=0; i<$('.cj-section').length;i++){
  134. var $this = $('.cj-section').eq(i)
  135. if($this.find('.cj-position-1').length == 0 && $this.find('.cj-flex-1').length == 0){
  136. $this.hide()
  137. }
  138. }
  139. bindEvent()
  140. })
  141. }
  142. //初始化
  143. templateRender(0)
  144. })