search-doctor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var d = dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var Request = GetRequest();
  3. var hospital = Request["hospital"];
  4. // TODO 示例参数接受,设置默认值
  5. var code = Request["code"] ;
  6. var name = decodeURIComponent(Request["name"]||"");
  7. var openid = "";
  8. var state = Request["state"];
  9. var stateArray = "";
  10. var pagetype = 17;
  11. //checkUserAgent();
  12. if(state){
  13. state = decodeURIComponent(state);
  14. stateArray = state.split(":");
  15. if(stateArray && stateArray.length == 2){
  16. hospital = stateArray[0];
  17. name = stateArray[1];
  18. }
  19. }
  20. //var userAgent = window.localStorage.getItem(agentName);
  21. var $doctorView = $('#doctor_view'),
  22. $doctorList = $('#doctor_list'),
  23. $noResultWrap = $('#no_result_wrap');
  24. var lastId = 0;
  25. //更换页面请求参数
  26. var page = 1;
  27. // 搜索框
  28. $('.searchbar').searchBar();
  29. var reqPromise = function(url,data) {
  30. return new Promise(function(resolve, reject) {
  31. sendPost(url, data, "json", "post",
  32. function queryFailed (req) {
  33. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  34. // TODO 开启示例数据
  35. // resolve({});
  36. }
  37. , function success(req) {
  38. resolve(req);
  39. });
  40. });
  41. },
  42. // 获取列表的最后一个数据对象的id字段值(用于医生列表的分页请求参数)
  43. getLastItemId = function(list) {
  44. var lastObj;
  45. if(list&&list.length) {
  46. lastObj = list[list.length-1];
  47. }
  48. return lastObj?lastObj.id:lastId;
  49. },
  50. // 更新分页上拉加载的提示文本
  51. updatePullUpText= function(scroller,list) {
  52. scroller.on('refresh',function() {
  53. var $wrap = $(scroller.wrapper),
  54. $pullupLabel = $wrap.find('.pullUpLabel');
  55. if(!list || !list.length) {
  56. $pullupLabel.text('没有更多');
  57. } else {
  58. $pullupLabel.text('上拉加载更多');
  59. }
  60. });
  61. },
  62. getReqPromises = function() {
  63. return Promise.all(_.map([{url:"hosptail/doctor_list",data:{hospital:hospital,page: page,pageSize:15}}],
  64. function(param){
  65. return reqPromise(param.url,param.data);
  66. }));
  67. };
  68. //if(userAgent) {
  69. // userAgent = JSON.parse(userAgent);
  70. //}
  71. $doctorView.find('.community-name').text(name);
  72. getReqPromises().then(function(datas) {
  73. //openid = datas[0] && datas[0].openid;
  74. var data = datas[0];
  75. // TODO 示例数据
  76. // data = {"msg":"获取医院医生列表成功!","list":[{"code":"D2016080002","job_name":" 全科医师","introduce":"我是全科医生","name":"大米全科1","dept_name":"","photo":"http://172.19.103.85:8882/res/images/2016/08/12/20160812170142_901.jpg","id":1262,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2016080005","job_name":" 全科医师","introduce":"我是全科医生","name":"大米全科2","dept_name":"","photo":"","id":1271,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2016080225","job_name":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科)","dept_name":"","photo":"","id":1274,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2010080225","job_name":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科1)","dept_name":"","photo":"","id":1276,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"}],"status":200};
  77. // lastId = getLastItemId(data.list);
  78. if(data && data.list.length) {
  79. $noResultWrap.hide();
  80. page ++;
  81. var html = template("doctor_li_tmpl", data);
  82. $doctorList.html(html);
  83. } else {
  84. $noResultWrap.show();
  85. d.close();
  86. return ;
  87. }
  88. var doctorListScroller = $doctorView.initScroll({pullDown: false,pullUpAction: function() {
  89. reqPromise("hosptail/doctor_list", {hospital:hospital,page: page,pageSize:15}).then(function(data) {
  90. // TODO 示例数据
  91. // data = {"msg":"获取医院医生列表成功!","list":[{"code":"D2016080002","job_name":" 全科医师","introduce":"我是全科医生","name":"大米全科1","dept_name":"","photo":"http://172.19.103.85:8882/res/images/2016/08/12/20160812170142_901.jpg","id":1262,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2016080005","job_name":" 全科医师","introduce":"我是全科医生","name":"大米全科2","dept_name":"","photo":"","id":1271,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2016080225","job_name":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科)","dept_name":"","photo":"","id":1274,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"},{"code":"D2010080225","job_name":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科1)","dept_name":"","photo":"","id":1276,"expertise":"我是全科医生","hospital_name":"嘉莲社区医疗服务中心"}],"status":200};
  92. // lastId = getLastItemId(data.list);
  93. page ++;
  94. console.log(data)
  95. var html = template("doctor_li_tmpl", data);
  96. $doctorList.append(html);
  97. updatePullUpText(doctorListScroller,data.list);
  98. doctorListScroller.refresh();
  99. })
  100. }});
  101. d.close();
  102. })
  103. .then(function() {
  104. $doctorList.on('click','li',function() {
  105. //checkUserAgent();
  106. var doctor = $(this).attr('data-code');
  107. window.location.href = "../../ssgg/html/doctor-homepage-new.html?state="+doctor
  108. // window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wxurl+"%2fssgg%2fhtml%2fdoctor-homepage-new.html&response_type=code&scope=snsapi_base&state="+doctor+"#wechat_redirect";
  109. });
  110. }).catch(function(e) {
  111. console && console.error(e)
  112. })
  113. template.helper('getPhoto', function(str){
  114. return getImgUrl(str);
  115. })