jiankangxuanjiao.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. var d = dialog({contentType: 'load',skin: 'bk-popup'})
  2. //var iscrollState = ""//判断拉取方向
  3. var page = 0;
  4. var pagesize = 10;
  5. var firstLevelCategoryId = ""
  6. var hospital = "" // 医生所属社区Code
  7. var pageData = {}
  8. var doctor = null
  9. function toast(msg){
  10. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
  11. }
  12. function getCategoryByNamePromise(){
  13. return new Promise(function(resolve, reject) {
  14. sendPost("third/jkEdu/Article/getCategoryByName",{name:'健康文章'},"JSON","GET",function(){
  15. toast('请求失败')
  16. },function(res){
  17. resolve(res)
  18. })
  19. })
  20. }
  21. function jimeiHomepagePromise(){
  22. return new Promise(function(resolve, reject) {
  23. sendPost("patient/family_contract/jimeiHomepage",{doctor:doctor,pageIndex:1,pageSize:3},"JSON","GET",function(){
  24. toast('请求失败')
  25. },function(res){
  26. resolve(res)
  27. })
  28. })
  29. }
  30. function queryArticleAPPListPromise(){
  31. return new Promise(function(resolve, reject) {
  32. sendPost("patient/jkEdu/article/queryArticlePcList",{
  33. doctor: doctor,
  34. firstLevelCategoryId: firstLevelCategoryId, // 文章一级分类
  35. isMyArticle: true,
  36. currentUserRole: hospital,
  37. currentUserRoleLevel: 4,
  38. iDisplayStart: page,
  39. iDisplayLength: 10
  40. },"JSON","GET",function(){
  41. toast('请求失败')
  42. },function(res){
  43. resolve(res)
  44. })
  45. })
  46. }
  47. $(function(){
  48. // 判断是否登录
  49. checkUserAgent();
  50. //轮播图
  51. mui("#slider").slider({
  52. interval: 2000
  53. })
  54. })
  55. function queryInit(){
  56. d.show();
  57. sendPost("patient/family_contract/getSignDoctors",{}, 'json', 'get',function(){
  58. d.close();
  59. toast('请求失败')
  60. },function(res){
  61. d.close();
  62. if(res.status == 200){
  63. var html = template('doctor_tmp',{data:res.list[0]})
  64. doctor = res.list[0] && res.list[0].code
  65. $('#doctor_msg').html(html).show();
  66. mui.init({
  67. pullRefresh : {
  68. container:'#wrapper',
  69. up : {
  70. height:50,
  71. contentinit: '',
  72. contentdown: '',
  73. contentrefresh : "正在加载...",
  74. contentnomore:'没有更多数据了',
  75. auto: true,
  76. callback: function() {
  77. var self = this;
  78. page++;
  79. queryArticle(function(val){
  80. setTimeout(function(){
  81. self.endPullupToRefresh(val);
  82. },500)
  83. })
  84. }
  85. }
  86. }
  87. })
  88. }else{
  89. toast('获取医生信息失败')
  90. }
  91. })
  92. }
  93. function queryArticle(fun){
  94. Promise.all([getCategoryByNamePromise(),jimeiHomepagePromise()]).then(function(responses) {
  95. var res0 = responses[0]
  96. var res1 = responses[1]
  97. if(res0.status == 200 && res1.status == 200) {
  98. firstLevelCategoryId = res0.data.cid
  99. hospital = res1.data.hospital
  100. pageData = res1.data
  101. } else {
  102. d.close()
  103. toast('获取数据失败')
  104. return Promise.reject()
  105. }
  106. }).then(function() {
  107. return queryArticleAPPListPromise().then(function(res) {
  108. d.close()
  109. if(res.status == 200){
  110. if(res.data.length>0){
  111. if(res.data.length < pagesize){
  112. fun&&fun.call(this,true)
  113. }else{
  114. fun&&fun.call(this,false)
  115. }
  116. }else{
  117. fun&&fun.call(this,true)
  118. }
  119. var list = res.data.aaData
  120. var data = $.extend({},pageData, {
  121. healthEduArticles: list
  122. })
  123. var html = template('article_tmp',{data: data})
  124. $('.xj-ul').append(html);
  125. $('.xj-main').show()
  126. bindEvents()
  127. }else{
  128. fun&&fun.call(this,false)
  129. toast('获取健康文章失败')
  130. }
  131. })
  132. }).catch(function(e) {
  133. d.close()
  134. console && console.error(e)
  135. })
  136. }
  137. function bindEvents(){
  138. $('#doctor_msg').on('tap',function(){
  139. window.location.href="doctor-index.html?docCode="+$(this).find('.xj-nav-foot').attr('data-id')
  140. })
  141. $('.xj-main').on('tap','.xj-li',function(){
  142. d.show()
  143. window.location.href=articleUrl+"/jkeduweb/web/jkEdu/articleDetail.html?behavior=4&articleId="+$(this).attr('data-id')
  144. })
  145. }
  146. template.helper("setPhoto", function(p) {
  147. return getImgUrl(p);
  148. })
  149. template.helper("setTimeFormat", function(p) {
  150. var now = new Date()
  151. var old = new Date(p.replace(/\-/g,'/'))
  152. if(now.getFullYear() == old.getFullYear()){
  153. if(now.getMonth() == old.getMonth()){
  154. if(now.getDate() == old.getDate()){
  155. if(now.getHours() == old.getHours()){
  156. if(now.getMinutes() == old.getMinutes()){
  157. return '1分钟前'
  158. }else{
  159. var a = now.getMinutes() - old.getMinutes()
  160. return a+'分钟前'
  161. }
  162. }else{
  163. var b = now.getHours() - old.getHours()
  164. return b+'小时前'
  165. }
  166. }else{
  167. var c = now.getDate() - old.getDate()
  168. if(c>7){
  169. return p.substr(5,5)
  170. }else{
  171. return c+'天前'
  172. }
  173. }
  174. }else{
  175. return p.substr(5,5)
  176. }
  177. }else{
  178. return p.substr(0,10)
  179. }
  180. })
  181. template.helper("setTime", function(p) {
  182. if(p && p.length>0){
  183. return p.substr(0,16)
  184. }else{
  185. return ''
  186. }
  187. })