select-consult-doctor.js 8.4 KB

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