hospital-dept.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-code="">全部</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. deptName = $(this).attr("data-name") || '';
  53. var url = "select-consult-doctor.html?deptId="+deptId+"&deptName="+deptName;
  54. window.location.replace(url);
  55. })
  56. }
  57. function initScroller(){
  58. //阻尼系数
  59. var deceleration = mui.os.ios?0.003:0.0009;
  60. mui('.mui-scroll-wrapper').scroll({
  61. bounce: false,
  62. indicators: true, //是否显示滚动条
  63. deceleration:deceleration
  64. });
  65. mui.ready(function() {
  66. mui(".mui-scroll-wrapper").pullRefresh({
  67. down:{
  68. callback: function(){
  69. getDeptList(true);
  70. this.endPulldownToRefresh();
  71. }
  72. },
  73. up: {
  74. callback: function() {
  75. var self = this;
  76. setTimeout(function() {
  77. getDeptList(false);
  78. }, 1000);
  79. }
  80. }
  81. });
  82. });
  83. }
  84. //请求失败处理事件
  85. function queryFailed(res, message){
  86. d.close();
  87. if(message){
  88. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  89. }else{
  90. if (res && res.msg) {
  91. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  92. } else {
  93. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  94. }
  95. }
  96. }