doctor-homepage.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. var request = GetRequest();
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var doctorCode = request["state"], //医生二维码扫描连接的参数,doctorCode_type
  4. doctor = request["doctor"],
  5. type = ''; //如果是扫二维码的页面,则这个type值为1
  6. if(doctorCode){
  7. doctor = doctorCode.split("_")[0];
  8. type = 1;
  9. }
  10. var userAgent = window.localStorage.getItem(agentName);
  11. var pagetype = 0;
  12. var docInfo;
  13. $(function(){
  14. checkUserAgent();
  15. })
  16. function queryInit(){
  17. userAgent = JSON.parse(userAgent);
  18. pageInitData();
  19. bindEvents();
  20. wxGetSign();
  21. }
  22. function pageInitData(){
  23. d.show();
  24. var url = "family_contract/homepage/homepage",
  25. params = {
  26. doctor:doctor
  27. }
  28. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  29. if(res.status==200){
  30. var data = res.data;
  31. docInfo = res.data;
  32. var photo = data.photo;
  33. if(!photo){
  34. var photo = "../../../images/noSexDoctor.jpg";
  35. if(doctor.sex==1){
  36. photo = "../../../images/d-male.png";
  37. }else if(doctor.sex==2){
  38. photo = "../../../images/d-female.png";
  39. }
  40. }
  41. $("#photo").attr("src", getImgUrl(photo));
  42. $("#concern").text(data.concernCount);
  43. //获得关注状态
  44. var concernStatus = data.sign; //-1没有关注,1已关注
  45. if(concernStatus < 0){
  46. $("#isFocus").text("关注");
  47. $("#isFocus").addClass("grey");
  48. }else{
  49. $("#isFocus").text("已关注");
  50. $("#isFocus").removeClass("grey");
  51. }
  52. $("#name").html(data.name);
  53. $("#jobName").html(data.jobName);
  54. $("#deptName").html(data.dept);
  55. $("#hospitalName").html(data.hospital);
  56. $("#expertise").html(data.expertise);
  57. $("#introduce").html(data.intro);
  58. d.close();
  59. }else{
  60. queryFailed(res);
  61. }
  62. });
  63. }
  64. function bindEvents(){
  65. //立即咨询事件
  66. $("#bang-btn").on("click",function(){
  67. //是否关注了这个医生
  68. if(docInfo.sign == -1){
  69. concernDoctor(true); //关注医生
  70. }else{
  71. //判断是否有未结束的咨询
  72. d.show();
  73. is_consult_finished();
  74. }
  75. });
  76. $("#isFocus").on('click', function(){
  77. var $this = $(this);
  78. if($this.hasClass("disabled")){
  79. return false;
  80. }
  81. $this.addClass("disabled");
  82. if($this.hasClass("grey")){
  83. concernDoctor();
  84. }else{
  85. //先判断是否有未结束的咨询,如果有未结束的咨询则不允许取消关注
  86. d.show();
  87. is_consult_finished(true);
  88. }
  89. })
  90. }
  91. //关注医生
  92. function concernDoctor(addConsult){
  93. d.show();
  94. var url = "/patient/concern/addConcern",
  95. params = {
  96. patient: userAgent.uid,
  97. doctor: doctor,
  98. concernSource: type || '2'//(关注方式: 1扫描二维码 2咨询关注 3.其他)
  99. };
  100. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  101. if(res.status == 200){
  102. console.log(res);
  103. if(addConsult){
  104. is_consult_finished();
  105. }else{
  106. //修改关注按钮的状态
  107. d.close();
  108. $("#isFocus").text("已关注");
  109. $("#isFocus").removeClass("grey");
  110. $("#isFocus").removeClass("disabled");
  111. //修改关注数
  112. var count = $("#concern").text();
  113. $("#concern").text(parseInt(count) + 1);
  114. }
  115. }else{
  116. $("#isFocus").removeClass("disabled");
  117. queryFailed(res);
  118. }
  119. })
  120. }
  121. //取消关注
  122. function cancelConcern(){
  123. // d.show();
  124. var url = "/patient/concern/deleteConcern",
  125. params = {
  126. patient: userAgent.uid,
  127. doctor: doctor
  128. };
  129. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  130. d.close();
  131. if(res.status == 200){
  132. $("#isFocus").text("关注");
  133. $("#isFocus").addClass("grey");
  134. $("#isFocus").removeClass("disabled");
  135. //修改关注数
  136. var count = $("#concern").text();
  137. $("#concern").text(parseInt(count) - 1);
  138. }else{
  139. $("#isFocus").removeClass("disabled");
  140. queryFailed(res);
  141. }
  142. })
  143. }
  144. //判断是否有未结束的咨询
  145. function is_consult_finished(isCancelConcern){
  146. var url = 'patient/consult/is_consult_unfinished',
  147. params = {doctor: docInfo.doctor};
  148. sendPost(url, params, 'json', 'post', function(res){
  149. queryFailed(res, '获取是否存在咨询失败');
  150. },function(res){
  151. if(res.status == 200){
  152. if(res.data == ""){
  153. if(isCancelConcern){
  154. cancelConcern();
  155. }else{
  156. checkDocInWork();
  157. // window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  158. }
  159. } else {
  160. d.close();
  161. $("#isFocus").removeClass("disabled");
  162. var content = '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,';
  163. if(isCancelConcern){
  164. content += '需结束咨询后才能取消关注';
  165. }else{
  166. content += '无法发起新的咨询';
  167. }
  168. dialog({
  169. content: content,
  170. okValue:'前往查看',
  171. ok: function (){
  172. var url = "../../qygl/html/sign_info.html?consult="+res.data+"&doctor="+docInfo.doctor;
  173. window.location.href = url;
  174. },
  175. cancelValue: '我知道了',
  176. cancel: function () {
  177. return;
  178. }
  179. }).showModal();
  180. }
  181. } else {
  182. queryFailed(res)
  183. }
  184. });
  185. }
  186. //获取签约医生的工作时间
  187. function checkDocInWork(){
  188. var url = 'patient/consult/isDoctorWorkWhenconsult',
  189. params = {
  190. doctor: doctor
  191. };
  192. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  193. $("#isFocus").removeClass("disabled");
  194. if(res.status == 200){
  195. d.close();
  196. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  197. if(!(res.data == "1")){
  198. dialog({
  199. content: '您好,由于您关注的医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  200. okValue:'查看医生工作时间',
  201. ok: function (){
  202. window.location.href = "doctor-work-hours.html?doctor=" + doctor;
  203. },
  204. cancelValue: '继续新增咨询',
  205. cancel: function () {
  206. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  207. }
  208. }).showModal();
  209. }else{
  210. //跳转到新增咨询页面
  211. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  212. }
  213. }else{
  214. queryFailed(res);
  215. }
  216. });
  217. }
  218. function queryFailed(res){
  219. d.close();
  220. if (res && res.msg) {
  221. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  222. } else {
  223. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  224. }
  225. }
  226. //获取微信信息,并配置微信api接口
  227. function wxGetSign(){
  228. var params = {};
  229. params.pageUrl = window.location.href;
  230. $.ajax(server + "weixin/getSign", {
  231. data: params,
  232. dataType: "json",
  233. type: "post",
  234. success: function(res){
  235. if (res.status == 200) {
  236. var t = res.data.timestamp;
  237. var noncestr = res.data.noncestr;
  238. var signature = res.data.signature;
  239. wx.config({
  240. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  241. appId: appId, // 必填,公众号的唯一标识
  242. timestamp: t, // 必填,生成签名的时间戳
  243. nonceStr: noncestr, // 必填,生成签名的随机串
  244. signature: signature,// 必填,签名,见附录1
  245. jsApiList: [
  246. 'closeWindow'
  247. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  248. });
  249. }
  250. }
  251. });
  252. }