chanjianjieguo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var Request = GetRequest();
  3. var pregnancyNo = Request['pregnancyNo'];
  4. function toast(msg){
  5. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
  6. }
  7. $(function(){
  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. 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. d.show()
  66. sendPost('patient/prenatalnspector/getEhrMaternalFirstExamRecord',{pregnancyNo:pregnancyNo},'json', 'get',null,function(res){
  67. d.close()
  68. if(res.status == 200){
  69. if(! $.isEmptyObject(res.data)){
  70. firstRecord = res.data
  71. resolve(res.data)
  72. }else{
  73. toast('查无数据')
  74. }
  75. }else{
  76. toast('请求数据失败')
  77. return
  78. }
  79. })
  80. }else{
  81. resolve(firstRecord)
  82. }
  83. }
  84. if(num == 1){
  85. if(!secondRecord){
  86. d.show()
  87. sendPost('patient/prenatalnspector/getEhrMaternalReExamRecord',{pregnancyNo:pregnancyNo},'json', 'get',null,function(res){
  88. d.close()
  89. if(res.status == 200){
  90. if(! $.isEmptyObject(res.data)){
  91. secondRecord = res.data
  92. resolve(res.data)
  93. }else{
  94. toast('查无数据')
  95. }
  96. }else{
  97. toast('请求数据失败')
  98. return
  99. }
  100. })
  101. }else{
  102. resolve(secondRecord)
  103. }
  104. }
  105. })
  106. },
  107. bindEvent = function(){
  108. //展开
  109. $('.cj-section').on('tap','.up.icon',function(){
  110. var $this = $(this).parent()
  111. if($this.hasClass('active')){
  112. $this.removeClass('active')
  113. }else{
  114. $this.addClass('active')
  115. }
  116. })
  117. }
  118. //渲染
  119. function templateRender(num){
  120. Promise.all([templateRequest(num),dataRequest(num)]).then(function(datas){
  121. $view.html(datas[0])
  122. $view.removeAttr('avalonctrl').attr('ms-controller',"template");
  123. var vm = avalon.define($.extend({"$id": "template"},{data:datas[1]}))
  124. avalon.scan();
  125. }).then(function(){
  126. //隐藏都没有的模块
  127. for(var i=0; i<$('.cj-section').length;i++){
  128. var $this = $('.cj-section').eq(i)
  129. if($this.find('.cj-position-1').length == 0 && $this.find('.cj-flex-1').length == 0){
  130. $this.hide()
  131. }
  132. }
  133. bindEvent()
  134. })
  135. }
  136. //初始化
  137. templateRender(0)
  138. })