health_article_list.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var Request = GetRequest();
  3. var doctorCode = Request["docCode"];
  4. var page = 0,
  5. pageSize = 10,
  6. pagetype = 0,
  7. firstLevelCategoryId = "", // 文章一级分类
  8. hospital ="" , // 医生所属社区Code
  9. // 搜索框
  10. $searchbar = $('.searchbar'),
  11. // 搜索输入框
  12. $searchbarInput = $('.lin-search-ipt input'),
  13. $searchtResult = $("#articleList");
  14. $(function(){
  15. checkUserAgent();
  16. })
  17. function toast(msg){
  18. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
  19. }
  20. function queryInit(){
  21. d.show();
  22. Promise.all([getCategoryByNamePromise(),jimeiHomepagePromise()])
  23. .then(function(responses) {
  24. var res0 = responses[0]
  25. var res1 = responses[1]
  26. if(res0.status == 200 && res1.status == 200) {
  27. firstLevelCategoryId = res0.data.cid
  28. hospital = res1.data.hospital
  29. } else {
  30. d.close()
  31. toast('获取数据失败')
  32. return Promise.reject()
  33. }
  34. }).then(function() {
  35. getList(true);
  36. initScroller();
  37. bindEvents();
  38. })
  39. }
  40. function initScroller(){
  41. //阻尼系数
  42. var deceleration = mui.os.ios?0.003:0.0009;
  43. mui('.mui-scroll-wrapper').scroll({
  44. bounce: false,
  45. indicators: true, //是否显示滚动条
  46. deceleration:deceleration
  47. });
  48. // mui.ready(function() {
  49. mui(".mui-scroll-wrapper").pullRefresh({
  50. up:{
  51. callback: function(){
  52. page++;
  53. var self = this;
  54. setTimeout(function(){
  55. getList(false);
  56. self.endPullupToRefresh();
  57. }, 1000)
  58. }
  59. },
  60. down: {
  61. callback: function(){
  62. var self = this;
  63. page = 0;
  64. getList(true);
  65. this.endPulldownToRefresh();
  66. }
  67. }
  68. })
  69. // })
  70. }
  71. function getCategoryByNamePromise(){
  72. return new Promise(function(resolve, reject) {
  73. sendPost("third/jkEdu/Article/getCategoryByName",{name:'健康文章'},"JSON","GET",function(){
  74. toast('请求失败')
  75. },function(res){
  76. resolve(res)
  77. })
  78. })
  79. }
  80. function jimeiHomepagePromise(){
  81. return new Promise(function(resolve, reject) {
  82. sendPost("patient/family_contract/jimeiHomepage",{
  83. doctor:doctorCode,pageIndex:page,pageSize:pageSize
  84. },"JSON","GET",function(){
  85. toast('请求失败')
  86. },function(res){
  87. resolve(res)
  88. })
  89. })
  90. }
  91. function getList(isInit){
  92. var url = "patient/jkEdu/article/queryArticlePcList",
  93. params = {
  94. doctor: doctorCode,
  95. articleTitle: $searchbarInput.val(),
  96. firstLevelCategoryId: firstLevelCategoryId, // 文章一级分类
  97. isMyArticle: true,
  98. currentUserRole: hospital,
  99. currentUserRoleLevel: 4,
  100. iDisplayStart: page,
  101. iDisplayLength: pageSize
  102. };
  103. d.show();
  104. sendPost(url, params, 'json', 'GET', queryFailed, function(res){
  105. d.close();
  106. if(res.status == 200){
  107. if(res.data.aaData.length > 0){
  108. var html = template("articleTmp", {list: res.data.aaData});
  109. if(isInit){
  110. $("#articleContent .mui-scroll-wrapper").show();
  111. $("#articleContent .div-no-info").hide();
  112. $("#articleList").empty().append(html);
  113. }else{
  114. $("#articleList").append(html);
  115. }
  116. if(res.data.aaData.length < pageSize){
  117. mui("#articleContent .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  118. }
  119. }
  120. else{
  121. if(isInit){
  122. //数据库中无数据
  123. $("#articleContent .mui-scroll-wrapper").hide();
  124. $("#articleContent .div-no-info").show();
  125. }else{
  126. mui("#articleContent .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  127. }
  128. }
  129. }else{
  130. queryFailed(res);
  131. }
  132. })
  133. }
  134. function queryFailed(res){
  135. d.close();
  136. if(res && res.msg) {
  137. dialog({
  138. contentType: 'tipsbox',
  139. skin: 'bk-popup',
  140. content: res.msg
  141. }).show();
  142. } else {
  143. dialog({
  144. contentType: 'tipsbox',
  145. skin: 'bk-popup',
  146. content: '加载失败'
  147. }).show();
  148. }
  149. }
  150. function bindEvents() {
  151. $("#articleContent").on('tap','li',function() {
  152. d.show()
  153. var articleId = $(this).attr('data-id')
  154. window.location.href="../../jkjy/html/article2.html?dataId="+articleId+'&articleId='+articleId+'&type='+'1';
  155. });
  156. //搜索功能
  157. $searchbarInput.on('keydown',function(e) {
  158. if (e.which === 13) {
  159. //按回车键后执行的动作
  160. page = 0;
  161. getList(true);
  162. }else{
  163. if($searchbarInput.length == 0){
  164. alert(1);
  165. }
  166. }
  167. });
  168. template.helper('getDate', function(str){
  169. if(str && str.length > 0){
  170. return str.substr(0, 10);
  171. }
  172. });
  173. }
  174. template.helper("setPhoto", function(p) {
  175. return getImgUrl(p);
  176. })
  177. function search(){
  178. page = 0;
  179. getList(true);
  180. }