select-consult-doctor.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. var page = 1;
  2. var pageSize = 1000000;
  3. var d = dialog({contentType:'load', skin:'bk-popup'});
  4. var patientcode ="";
  5. var isSearch = false;
  6. // 获取链接带参
  7. var request = GetRequest(),
  8. deptId =request["deptId"] || null;
  9. // 搜索框
  10. var $searchbar = $('.searchbar'),
  11. // 搜索输入框
  12. $searchbarInput = $('.searchbar input'),
  13. // 搜索取消按钮
  14. $searchCancelBtn = $('.searchbar-cancel'),
  15. // 搜索框下面悬浮的搜索提示
  16. $searchSuggest = $('#search_suggest_text'),
  17. $listTIt = $('#list_tit'),
  18. // 搜索结果展示容器
  19. $searchtResult = $('.div-content');
  20. // 搜索框初始化
  21. $searchbar.addClass("searchbar-active");
  22. var getReqPromise = null;
  23. var scroller1 = null;
  24. $(function(){
  25. //添加isrcoll
  26. scroller1 = new IScrollPullUpDown('wrapper2',{
  27. probeType:2,
  28. bounceTime: 250,
  29. bounceEasing: 'quadratic',
  30. mouseWheel:false,
  31. scrollbars:true,
  32. click:true,
  33. fadeScrollbars:true,
  34. interactiveScrollbars:false
  35. },pullDownAction);
  36. bindEvents();
  37. pageInit();
  38. })
  39. //下拉刷新
  40. function pullDownAction(theScrollerTemp) {
  41. setTimeout(function () {
  42. $(".c-list").html("");
  43. page=1;
  44. pageInit();
  45. }, 1000);
  46. }
  47. //上拉加载数据
  48. function pullUpAction(theScrollerTemp) {
  49. $(".pullUp").show();
  50. setTimeout(function () {
  51. page++;
  52. pageInit();
  53. }, 1000);
  54. }
  55. function pageInit(){
  56. d.show();
  57. var params = {};
  58. if(deptId) {
  59. params.dept = deptId
  60. }
  61. params.page = page;
  62. params.pagesize = pageSize;
  63. params.name = $(".inp-search").val();
  64. getReqPromise("patient/consult/doctorList",params).then(function(data){
  65. // getReqPromise("patient/consult/famousDoctorList",params).then(function(data){
  66. if(data.status == 200){
  67. var rowData = data.list;
  68. if (rowData.length > 0) {
  69. var listResult = _.map(rowData,function(item,index){
  70. var countClass = "c-74bf00";
  71. var num = item.num || 0;
  72. var expertise = "";
  73. var job_name = "";
  74. var photo = item.photo;
  75. if(!photo){
  76. var photo = "../../../images/noSexDoctor.jpg";
  77. if(item.sex==1){
  78. photo = "../../../images/d-male.png";
  79. }else if(item.sex==2){
  80. photo = "../../../images/d-female.png";
  81. }
  82. }
  83. if(num==0){
  84. countClass = "c-FF6A56";
  85. }
  86. if(item.expertise){
  87. expertise = '<div class="c-f12 c-666666">'+
  88. '<span class="span-content">'+item.expertise || ""+'</span>'+
  89. // '<span class="span-content">高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠心病、心律失常等疾病的诊治擅长高血压、冠</span>'+
  90. '</div>';
  91. }
  92. if(item.job_name.trim()){
  93. job_name = '<span class="c-f14 c-666666 pl10">('+item.job_name+')</span>';
  94. }
  95. var content ='<li class="mt10" data-code="'+item.code+'" data-name="'+item.name+'" data-id="'+item.id+'">'+
  96. '<div class="n-list dr-item c-border c-100">'+
  97. '<div class="n-list-li">'+
  98. '<div class="n-list-key">'+
  99. '<div class="n-avatar-l img-round">'+
  100. '<img src="'+getImgUrl(item.photo)+'">'+
  101. '</div>'+
  102. '</div>'+
  103. '<div class="pdr-50 pl5">'+
  104. '<div class="c-f14 c-323232">'+
  105. '<span class="c-bold search-target-text">'+item.name+'</span>'+
  106. '<span class="plr5">'+ item.dept_name +'</span>' + item.job_name +
  107. '</div>'+
  108. '<div class="c-f14 c-323232">'+
  109. '<span>'+item.hospital_name+'</span>'+
  110. '</div>'+
  111. expertise+
  112. '<div class="c-f12 c-323232 pt10 clearfix">' +
  113. '<div class="fl w-33"><span class="pr5">关注</span>' + item.concernNum + '</div>' +
  114. '<div class="fl w-33"><span class="pr5">咨询</span>'+item.consultNum+'</div>' +
  115. '<div class="fl w-33"><span class="pr5">文章</span>'+item.articleNum+'</div>' +
  116. '</div>'+
  117. '</div>'+
  118. '</div>'+
  119. '</div>'+
  120. '</li>';
  121. id = item.id;
  122. return content;
  123. })
  124. $(".c-list").append(listResult);
  125. var kw = $(".inp-search").val();
  126. highlightKeyword(kw);
  127. scroller1.myScroll.refresh();
  128. }else {
  129. if(isSearch){//查询无结果
  130. $(".main").show();
  131. $(".div-content").hide();
  132. $(".div-no-search-info").show();
  133. $(".div-search-content").html("查无数据");
  134. isSearch = false;
  135. }else if(page==1){//page为1的时候证明是第一次加载,第一次加载无数据,显示无数据界面
  136. $(".main").hide();
  137. $(".div-no-search-info").show();
  138. $(".div-search-content").html("今天无医坐诊哦,请改天再来~");
  139. }else {
  140. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'无更多数据'}).show();
  141. }
  142. }
  143. } else {
  144. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:data.msg}).show();
  145. }
  146. d.close();
  147. $(".pullUp").hide();
  148. });
  149. }
  150. function bindEvents(){
  151. $(".c-list").on("click","li",function(){
  152. d.show();
  153. var doctorCode = $(this).attr("data-code");
  154. var docName = $(this).attr("data-name");
  155. sendPost('patient/consult/is_consult_unfinished', {doctor: doctorCode}, 'json', 'post',
  156. function(res){
  157. d.close();
  158. if (res && res.msg) {
  159. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  160. } else {
  161. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取是否存在咨询失败'}).show();
  162. }
  163. }, function(res){
  164. d.close();
  165. if(res.status == 200){
  166. if(res.data == ""){
  167. window.location.href = "mingyi-homepage.html?doctorCode="+doctorCode;
  168. } else {
  169. dialog({
  170. content: '十分抱歉,您与'+ docName +'医生还有<br/>未结束咨询,无法发起新的咨询',
  171. okValue:'前往查看',
  172. ok: function (){
  173. var userAgent = window.localStorage.getItem(agentName);
  174. var userInfo = JSON.parse(userAgent);
  175. var rep = userInfo.represented?userInfo.represented:userInfo.uid;
  176. window.location.href = "consulting-doctor.html?consult=" + res.data +"&toUser="+rep;
  177. },
  178. cancelValue: '我知道了',
  179. cancel: function () {
  180. $(".modal-overlay").trigger("click");
  181. $(".sanshi-icon").removeClass("active");
  182. $(".jiating-icon").removeClass("active");
  183. $(".mingyi-icon").removeClass("active");
  184. return;
  185. }
  186. }).showModal();
  187. }
  188. } else {
  189. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  190. }
  191. })
  192. })
  193. // 控制搜索关键字悬浮提示的显示
  194. getReqPromise = function(url, data) {
  195. return new Promise(function(resolve, reject) {
  196. sendPost(url, data, "json", "get",
  197. function queryFailed (req) {
  198. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  199. // TODO 开启示例数据
  200. //resolve({});
  201. }
  202. , function success(req) {
  203. resolve(req);
  204. });
  205. });
  206. }
  207. //取消事件
  208. $searchCancelBtn.on('click',function() {
  209. $(this).hide();
  210. $searchSuggest.text('');
  211. $searchSuggest.hide();
  212. $listTIt.show()
  213. $searchtResult.show();
  214. });
  215. $searchSuggest.on('click',function() {
  216. search();
  217. });
  218. //搜索框事件
  219. $(".inp-search").on("input",function(){
  220. var text = $(this).val().trim();
  221. $searchtResult.hide();
  222. showSearchSuggest(text);
  223. if(text){
  224. $searchCancelBtn.show();
  225. $searchCancelBtn.css("opacity","1");
  226. }else{
  227. $searchCancelBtn.hide();
  228. $searchCancelBtn.css("opacity","0");
  229. search();
  230. }
  231. })
  232. // 选择科室
  233. $('#select_dept').on('click', function() {
  234. window.location.href = 'hospital-dept.html'
  235. })
  236. // 已关注医生列表
  237. $('#focused').on('click', function() {
  238. window.location.href = 'focused-doctor.html'
  239. })
  240. }
  241. var showSearchSuggest = function(text) {
  242. var suggestText = '搜索“'+text+'”';
  243. // 如果text不为空,则显示;否则隐藏
  244. if(text&&text.trim().length) {
  245. $searchSuggest.text(suggestText);
  246. $searchSuggest.show();
  247. $listTIt.hide();
  248. } else {
  249. $searchSuggest.text('');
  250. $searchSuggest.hide();
  251. $listTIt.show();
  252. }
  253. },
  254. // 关键字高亮显示
  255. highlightKeyword = function(kw) {
  256. $searchTarget = $('.search-target-text');
  257. $searchTarget.hide();
  258. _.each($searchTarget,function(ele){
  259. var $ele = $(ele),
  260. text = $ele.text(),
  261. reg = new RegExp(kw+"(?!>)","gi"),
  262. html = text.replace(reg,'<em>'+kw+'</em>');
  263. $ele.html(html);
  264. });
  265. $searchTarget.show();
  266. },
  267. // TODO搜索框搜索执行方法
  268. search = function () {
  269. $(".div-no-search-info").hide();
  270. isSearch = true;
  271. $searchSuggest.text('');
  272. $searchSuggest.hide();
  273. $listTIt.show()
  274. $searchCancelBtn.hide();
  275. $searchCancelBtn.css("opacity","0");
  276. $searchtResult.show();
  277. $(".c-list").html("");
  278. id=0;
  279. pageInit();
  280. },
  281. // 重置搜索结果的容器高度(为了让滚动条出现在容器内部,而不引起外部内容滚动)
  282. resetResultWrapHeight = function() {
  283. var winHeight = $(window).height(),
  284. diff = 45,
  285. $wrap = $('.div-content');
  286. $wrap.height(winHeight-diff);
  287. },
  288. // 监听窗口大小变化,重置所属区列表、社区列表列表容器高度
  289. resultWrapAutoAdapt = function() {
  290. resetResultWrapHeight();
  291. $(window).on('resize',function() {
  292. resetResultWrapHeight();
  293. });
  294. };