hospital-dept.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var page = 1,
  3. pageSize = 100;
  4. $(function(){
  5. initScroller();
  6. getDeptList(true);
  7. bindEvents();
  8. })
  9. function getDeptList(isInit){
  10. d.show();
  11. if(isInit){
  12. page = 1;
  13. }
  14. var url = "patient/consult/dept_list",
  15. params = {
  16. page: page,
  17. pagesize: pageSize
  18. };
  19. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  20. if(res.status == 200){
  21. d.close();
  22. var list = res.data;
  23. if(list.length > 0){
  24. var html = template('dept_tmp', {list: list});
  25. if(isInit){
  26. var all = '<li class="c-list-cover list-arrow-r ptb10 plr10" data-id="">全部</li>';
  27. $("#deptList").empty().append(all+html);
  28. }else{
  29. $("#deptList").append(html);
  30. }
  31. if(list.length < pageSize){
  32. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  33. }else{
  34. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(false);
  35. }
  36. }else{
  37. if(isInit){
  38. $(".c-main").hide();
  39. $(".div-no-info").show();
  40. }else{
  41. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  42. }
  43. }
  44. }else{
  45. queryFailed(res);
  46. }
  47. });
  48. }
  49. function bindEvents(){
  50. $("#deptList").on('tap', 'li', function(){
  51. var deptId = $(this).attr("data-code");
  52. var url = "select-consult-doctor.html?deptId="+deptId;
  53. window.location.replace(url);
  54. })
  55. }
  56. function initScroller(){
  57. //阻尼系数
  58. var deceleration = mui.os.ios?0.003:0.0009;
  59. mui('.mui-scroll-wrapper').scroll({
  60. bounce: false,
  61. indicators: true, //是否显示滚动条
  62. deceleration:deceleration
  63. });
  64. mui.ready(function() {
  65. mui(".mui-scroll-wrapper").pullRefresh({
  66. down:{
  67. callback: function(){
  68. getDeptList(true);
  69. this.endPulldownToRefresh();
  70. }
  71. },
  72. up: {
  73. callback: function() {
  74. var self = this;
  75. setTimeout(function() {
  76. getDeptList(false);
  77. }, 1000);
  78. }
  79. }
  80. });
  81. });
  82. }
  83. //请求失败处理事件
  84. function queryFailed(res, message){
  85. d.close();
  86. if(message){
  87. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  88. }else{
  89. if (res && res.msg) {
  90. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  91. } else {
  92. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  93. }
  94. }
  95. }