mingyi-homepage.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. Request = GetRequest();
  2. var id = 0;
  3. var pageSize = 15;
  4. var d = dialog({contentType:'load', skin:'bk-popup'});
  5. var doctorCode = Request["doctorCode"];
  6. var scroller1 = null;
  7. var userAgent = window.localStorage.getItem(agentName);
  8. $(function(){
  9. //添加isrcoll
  10. scroller1 = new IScrollPullUpDown('wrapper',{
  11. probeType:2,
  12. bounceTime: 250,
  13. bounceEasing: 'quadratic',
  14. mouseWheel:false,
  15. scrollbars:true,
  16. click:true,
  17. fadeScrollbars:true,
  18. interactiveScrollbars:false
  19. },null,null);
  20. pageInit();
  21. })
  22. var count = 0;
  23. var ids=[
  24. {cosultTime:"zhouyi1",consultCount:"zhouyi2"},
  25. {cosultTime:"zhouer1",consultCount:"zhouer2"},
  26. {cosultTime:"zhousan1",consultCount:"zhousan2"},
  27. {cosultTime:"zhousi1",consultCount:"zhousi2"},
  28. {cosultTime:"zhouwu1",consultCount:"zhouwu2"},
  29. {cosultTime:"zhouliu1",consultCount:"zhouliu2"},
  30. {cosultTime:"zhouri1",consultCount:"zhouri2"}
  31. ];
  32. function pageInit(){
  33. d.show();
  34. pageInitData();
  35. }
  36. function getListFail(res){
  37. d.close();
  38. if (res && res.msg) {
  39. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  40. } else {
  41. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  42. }
  43. }
  44. //查询医生的工作时间+名医主页信息,并判断当前是否可咨询(该医生今日是否有次数、是否在医生工作时间内)如当前可咨询,则立即咨询高亮显示,如不可咨询,则置灰
  45. function pageInitData(){
  46. sendPost('/patient/consult/doctor_worktime', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  47. if(res.status==200){
  48. var workWeek = res.data.workWeeks;
  49. var worktime = res.data.workTime;
  50. var doctor = res.data.doctor;
  51. if(workWeek&&workWeek.length>0){
  52. for(var i = 0 ;i<workWeek.length;i++){
  53. var weekInfo = workWeek[i];
  54. if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==1){
  55. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.nightEnd);
  56. }else if(weekInfo.morning==1 && weekInfo.afternoon==0 && weekInfo.night==0){
  57. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.morningEnd);
  58. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==0){
  59. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.afternoonEnd);
  60. }else if(weekInfo.morning==0 && weekInfo.afternoon==0 && weekInfo.night==1){
  61. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.nightBegin+"~"+worktime.nightEnd);
  62. }else if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==0){
  63. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.afternoonEnd);
  64. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==1){
  65. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.nightEnd);
  66. }
  67. $("#"+ids[weekInfo.week-1].consultCount).html(worktime.famousConsultTimes+"次");
  68. }
  69. }
  70. var photo = doctor.photo;
  71. if(!photo){
  72. var photo = "../../../images/noSexDoctor.jpg";
  73. if(doctor.sex==1){
  74. photo = "../../../images/d-male.png";
  75. }else if(doctor.sex==2){
  76. photo = "../../../images/d-female.png";
  77. }
  78. }
  79. $("#photo").attr("src", getImgUrl(photo));
  80. $("#name").html(doctor.name);
  81. $("#jobName").html(doctor.jobName);
  82. $("#deptName").html(doctor.deptName);
  83. $("#hospitalName").html(doctor.hospitalName);
  84. $("#expertise").html(doctor.expertise);
  85. $("#introduce").html(doctor.introduce);
  86. scroller1.myScroll.refresh();
  87. d.close();
  88. isWordTimeInit();//判断当前是否可咨询(该医生今日是否有次数、是否在医生工作时间内)如当前可咨询,则立即咨询高亮显示,如不可咨询,则置灰
  89. }else{
  90. getListFail(res);
  91. }
  92. });
  93. }
  94. //判断当前是否可咨询(该医生今日是否有次数、是否在医生工作时间内)如当前可咨询,则立即咨询高亮显示,如不可咨询,则置灰
  95. function isWordTimeInit(){
  96. var week = new Date().getDay()==0?7:new Date().getDay();
  97. var myDate = new Date();
  98. if($("#"+ids[week-1].cosultTime).html()){//有上班时间
  99. //查询名医当前是否在工作时间内
  100. sendPost('patient/consult/is_doctor_working', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  101. if(res.status==200){
  102. var data = res.data;//0:医生不接受咨询 1:医生接受咨询 2:医生当前不在工作时间
  103. if(data==1){
  104. sendPost('patient/consult/consult_times_remain', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  105. if(res.status==200){
  106. count = res.data;//名医剩余咨询次数
  107. if(count>0){
  108. $("#bang-btn").addClass("active");
  109. }else{
  110. $("#bang-btn").removeClass("active");
  111. }
  112. }else{
  113. getListFail(res);
  114. }
  115. });
  116. }else if(data==2){
  117. // dialog({
  118. // content: '医生不在工作时间内哦,请在医生咨询计划时间段内咨询',
  119. // cancelValue: '我知道了',
  120. // cancel: function () {
  121. // $("#bang-btn").removeClass("active");
  122. // return;
  123. // }
  124. // }).showModal();
  125. $("#bang-btn").removeClass("active");
  126. return false;
  127. }else{
  128. // dialog({
  129. // content: '对不起,该医生已暂停接受咨询,您可选择其他医生进行咨询',
  130. // cancelValue: '我知道了',
  131. // cancel: function () {
  132. // $("#bang-btn").removeClass("active");
  133. // return;
  134. // }
  135. // }).showModal();
  136. $("#bang-btn").removeClass("active");
  137. return false;
  138. }
  139. }else{
  140. getListFail(res);
  141. }
  142. });
  143. }
  144. }
  145. //立即咨询事件
  146. $("#bang-btn").on("click",function(){
  147. if($(this).hasClass("active")){
  148. d.show();
  149. if(userAgent) {
  150. userAgent = JSON.parse(userAgent);
  151. }
  152. //先判断这位名医是否是您的签约医生
  153. sendPost('patient/family_contract/getSignMessage', {patientCode:userAgent.represented?userAgent.represented:userAgent.uid}, 'json', 'get', getListFail, function(res){
  154. if(res.status==200){
  155. var list = res.list;
  156. var isMySignDoctor = false;
  157. for(var i=0;i<list.length;i++){
  158. if(list[i].code==doctorCode){
  159. isMySignDoctor = true;
  160. break;
  161. }
  162. }
  163. if(isMySignDoctor){
  164. d.close();
  165. dialog({
  166. content: '对不起,这位名医是您的签约医生,可直接对其发起健康咨询',
  167. okValue:'前往咨询',
  168. ok: function (){
  169. window.location.href = server + "wx/html/yszx/html/doctor-consultation.html";
  170. },
  171. cancelValue: '不了,谢谢',
  172. cancel: function () {
  173. wx.closeWindow();
  174. }
  175. }).showModal();
  176. }else{
  177. //查询名医当前是否在工作时间内
  178. sendPost('patient/consult/is_doctor_working', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  179. if(res.status==200){
  180. var data = res.data;//0:医生不接受咨询 1:医生接受咨询 2:医生当前不在工作时间
  181. if(data==1){
  182. sendPost('/patient/consult/doctor_worktime', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  183. if(res.status==200){
  184. var workWeek = res.data.workWeeks;
  185. var worktime = res.data.workTime;
  186. var doctor = res.data.doctor;
  187. if(workWeek&&workWeek.length>0){
  188. for(var i = 0 ;i<workWeek.length;i++){
  189. var weekInfo = workWeek[i];
  190. if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==1){
  191. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.nightEnd);
  192. }else if(weekInfo.morning==1 && weekInfo.afternoon==0 && weekInfo.night==0){
  193. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.morningEnd);
  194. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==0){
  195. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.afternoonEnd);
  196. }else if(weekInfo.morning==0 && weekInfo.afternoon==0 && weekInfo.night==1){
  197. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.nightBegin+"~"+worktime.nightEnd);
  198. }else if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==0){
  199. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.afternoonEnd);
  200. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==1){
  201. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.nightEnd);
  202. }
  203. $("#"+ids[weekInfo.week-1].consultCount).html(worktime.famousConsultTimes+"次");
  204. }
  205. setTimeout(function(){
  206. isWordTime();//判断医生是否在工作时间内+查询某个医生名医当前剩余咨询次数
  207. },300)
  208. }
  209. }
  210. });
  211. }else if(data==2){
  212. sendPost('/patient/consult/doctor_worktime', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  213. if(res.status==200){
  214. var workWeek = res.data.workWeeks;
  215. var worktime = res.data.workTime;
  216. var doctor = res.data.doctor;
  217. if(workWeek&&workWeek.length>0){
  218. for(var i = 0 ;i<workWeek.length;i++){
  219. var weekInfo = workWeek[i];
  220. if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==1){
  221. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.nightEnd);
  222. }else if(weekInfo.morning==1 && weekInfo.afternoon==0 && weekInfo.night==0){
  223. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.morningEnd);
  224. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==0){
  225. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.afternoonEnd);
  226. }else if(weekInfo.morning==0 && weekInfo.afternoon==0 && weekInfo.night==1){
  227. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.nightBegin+"~"+worktime.nightEnd);
  228. }else if(weekInfo.morning==1 && weekInfo.afternoon==1 && weekInfo.night==0){
  229. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.morningBegin+"~"+worktime.afternoonEnd);
  230. }else if(weekInfo.morning==0 && weekInfo.afternoon==1 && weekInfo.night==1){
  231. $("#"+ids[weekInfo.week-1].cosultTime).html(worktime.afternoonBegin+"~"+worktime.nightEnd);
  232. }
  233. $("#"+ids[weekInfo.week-1].consultCount).html(worktime.famousConsultTimes+"次");
  234. }
  235. setTimeout(function(){
  236. isWordTime();//判断医生是否在工作时间内+查询某个医生名医当前剩余咨询次数
  237. },300)
  238. }
  239. }
  240. });
  241. return false;
  242. }else{
  243. d.close();
  244. dialog({
  245. content: '对不起,该医生已暂停接受咨询,您可选择其他医生进行咨询',
  246. cancelValue: '我知道了',
  247. cancel: function () {
  248. $("#bang-btn").removeClass("active");
  249. return;
  250. }
  251. }).showModal();
  252. return false;
  253. }
  254. }else{
  255. getListFail(res);
  256. }
  257. });
  258. }
  259. }else{
  260. getListFail(res);
  261. }
  262. });
  263. }
  264. })
  265. //查询某个医生名医当前剩余咨询次数
  266. function consultTimesRemain(){
  267. sendPost('patient/consult/consult_times_remain', {doctor:doctorCode}, 'json', 'post', getListFail, function(res){
  268. if(res.status==200){
  269. count = res.data;//名医剩余咨询次数
  270. if(count>0){
  271. var week = new Date().getDay();
  272. var myDate = new Date();
  273. window.location.href = "add-consult.html?type=6&doctorCode="+doctorCode;
  274. }else {
  275. dialog({
  276. content: '您来晚了哦~该医生今日已无免费次数,您可咨询其他名医或改天再来~',
  277. cancelValue: '我知道了',
  278. cancel: function () {
  279. $("#bang-btn").removeClass("active");
  280. return;
  281. }
  282. }).showModal();
  283. return false;
  284. }
  285. }else{
  286. getListFail(res);
  287. }
  288. });
  289. }
  290. function time_range(beginTime, endTime, nowTime) {
  291. var strb = beginTime.split (":");
  292. if (strb.length != 2) {
  293. return false;
  294. }
  295. var stre = endTime.split (":");
  296. if (stre.length != 2) {
  297. return false;
  298. }
  299. var strn = nowTime.split (":");
  300. if (stre.length != 2) {
  301. return false;
  302. }
  303. var b = new Date ();
  304. var e = new Date ();
  305. var n = new Date ();
  306. b.setHours (strb[0]);
  307. b.setMinutes (strb[1]);
  308. e.setHours (stre[0]);
  309. e.setMinutes (stre[1]);
  310. n.setHours (strn[0]);
  311. n.setMinutes (strn[1]);
  312. if (n.getTime () - b.getTime () > 0 && n.getTime () - e.getTime () < 0) {
  313. return "1";//在时间范围内
  314. } else {
  315. return "0";//不在工作时间内
  316. }
  317. }
  318. function CompareDate(t1,t2)
  319. {
  320. var date = new Date();
  321. var a = t1.split(":");
  322. var b = t2.split(":");
  323. return date.setHours(a[0],a[1]) > date.setHours(b[0],b[1]);
  324. }
  325. //判断医生是否在工作时间内
  326. function isWordTime(){
  327. d.close();
  328. var week = new Date().getDay()==0?7:new Date().getDay();
  329. var myDate = new Date();
  330. if($("#"+ids[week-1].cosultTime).html()){//有上班时间
  331. var cosultTimeArr = $("#"+ids[week-1].cosultTime).html().split("~");
  332. var curHours = myDate.getHours(); //获取当前小时数(0-23)
  333. var curMinutes = myDate.getMinutes();//获取当前分钟数(0-59)
  334. var curTime = curHours+":"+curMinutes;
  335. var timeRange = time_range(cosultTimeArr[0],cosultTimeArr[1],curTime)
  336. if(timeRange=="1"){//在工作时间内,查询某个医生名医当前剩余咨询次数
  337. consultTimesRemain();
  338. }else{//不在工作时间内,判断早晚
  339. var isFlag1 = CompareDate(curTime,cosultTimeArr[0]);
  340. var isFlag2 = CompareDate(curTime,cosultTimeArr[1]);
  341. if(!isFlag1){//来早了
  342. dialog({
  343. content: '您来早了哦,'+$("#name").html()+'医生将在'+cosultTimeArr[0]+'准时开始接受咨询~',
  344. cancelValue: '我知道了',
  345. cancel: function () {
  346. $("#bang-btn").removeClass("active");
  347. return;
  348. }
  349. }).showModal();
  350. return false;
  351. }
  352. if(isFlag2){//来晚了
  353. dialog({
  354. content: '您来晚了哦~'+$("#name").html()+'医生本日咨询时间已过,请改日再来~',
  355. cancelValue: '我知道了',
  356. cancel: function () {
  357. $("#bang-btn").removeClass("active");
  358. return;
  359. }
  360. }).showModal();
  361. return false;
  362. }
  363. }
  364. }else{
  365. dialog({
  366. content: '医生今天不上班哦,请在医生咨询计划时间段内咨询',
  367. cancelValue: '我知道了',
  368. cancel: function () {
  369. $("#bang-btn").removeClass("active");
  370. return;
  371. }
  372. }).showModal();
  373. return false;
  374. }
  375. }