doctor-homepage.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. var Request = GetRequest();
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var doctorCode = Request["doctorCode"],
  4. type = Request["type"]; //如果是扫二维码的页面,则这个type值为1
  5. var userAgent = window.localStorage.getItem(agentName);
  6. var pagetype = 0;
  7. var docInfo;
  8. $(function(){
  9. checkUserAgent();
  10. })
  11. function queryInit(){
  12. userAgent = JSON.parse(userAgent);
  13. pageInitData();
  14. bindEvents();
  15. wxGetSign();
  16. }
  17. function pageInitData(){
  18. d.show();
  19. var url = "family_contract/homepage/homepage",
  20. params = {
  21. doctor:doctorCode
  22. }
  23. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  24. if(res.status==200){
  25. var data = res.data;
  26. docInfo = res.data;
  27. var photo = data.photo;
  28. if(!photo){
  29. var photo = "../../../images/noSexDoctor.jpg";
  30. if(doctor.sex==1){
  31. photo = "../../../images/d-male.png";
  32. }else if(doctor.sex==2){
  33. photo = "../../../images/d-female.png";
  34. }
  35. }
  36. $("#photo").attr("src", getImgUrl(photo));
  37. $("#concern").text(data.concernCount);
  38. //获得关注状态
  39. var concertStatus = data.sign; //-1没有关注,1已关注
  40. if(concertStatus < 0){
  41. $("#isFocus").text("关注");
  42. $("#isFocus").addClass("grey");
  43. }else{
  44. $("#isFocus").text("已关注");
  45. $("#isFocus").removeClass("grey");
  46. }
  47. $("#name").html(data.name);
  48. $("#jobName").html(data.jobName);
  49. $("#deptName").html(data.dept);
  50. $("#hospitalName").html(data.hospital);
  51. $("#expertise").html(data.expertise);
  52. $("#introduce").html(data.intro);
  53. d.close();
  54. }else{
  55. queryFailed(res);
  56. }
  57. });
  58. }
  59. function bindEvents(){
  60. //立即咨询事件
  61. $("#bang-btn").on("click",function(){
  62. //是否关注了这个医生
  63. if(docInfo.sign == -1){
  64. concertDoctor(true); //关注医生
  65. }else{
  66. //判断是否有未结束的咨询
  67. d.show();
  68. is_consult_finished();
  69. }
  70. });
  71. $("#isFocus").on('click', function(){
  72. var $this = $(this);
  73. if($this.hasClass("grey")){
  74. concertDoctor();
  75. }else{
  76. cancelConcert();
  77. }
  78. })
  79. }
  80. //关注医生
  81. function concertDoctor(addConsult){
  82. d.show();
  83. var url = "/patient/concern/addConcern",
  84. params = {
  85. patient: userAgent.uid,
  86. doctor: doctorCode,
  87. concernSource: type || '2'//(关注方式: 1扫描二维码 2咨询关注 3.其他)
  88. };
  89. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  90. if(res.status == 200){
  91. console.log(res);
  92. if(addConsult){
  93. is_consult_finished();
  94. }else{
  95. //修改关注按钮的状态
  96. d.close();
  97. $("#isFocus").text("已关注");
  98. $("#isFocus").removeClass("grey");
  99. }
  100. }else{
  101. queryFailed(res);
  102. }
  103. })
  104. }
  105. //取消关注
  106. function cancelConcert(){
  107. d.show();
  108. var url = "/patient/concern/deleteConcern",
  109. params = {
  110. patient: userAgent.uid,
  111. doctor: doctorCode
  112. };
  113. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  114. d.close();
  115. if(res.status == 200){
  116. $("#isFocus").text("关注");
  117. $("#isFocus").addClass("grey");
  118. }else{
  119. queryFailed(res);
  120. }
  121. })
  122. }
  123. //判断是否有未结束的咨询
  124. function is_consult_finished(){
  125. var url = 'patient/consult/is_consult_unfinished',
  126. params = {doctor: docInfo.doctor};
  127. sendPost(url, params, 'json', 'post', function(res){
  128. queryFailed(res, '获取是否存在咨询失败');
  129. },function(res){
  130. d.close();
  131. if(res.status == 200){
  132. if(res.data == ""){
  133. //无进行中的咨询, 跳转去
  134. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  135. } else {
  136. dialog({
  137. content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',
  138. okValue:'前往查看',
  139. ok: function (){
  140. var url = "../../qygl/html/sign_info.html?consult="+res.data+"&doctor="+docInfo.doctor;
  141. window.location.href = url;
  142. },
  143. cancelValue: '我知道了',
  144. cancel: function () {
  145. return;
  146. }
  147. }).showModal();
  148. }
  149. } else {
  150. queryFailed(res)
  151. }
  152. });
  153. }
  154. function queryFailed(res){
  155. d.close();
  156. if (res && res.msg) {
  157. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  158. } else {
  159. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  160. }
  161. }
  162. //获取微信信息,并配置微信api接口
  163. function wxGetSign(){
  164. var params = {};
  165. params.pageUrl = window.location.href;
  166. $.ajax(server + "weixin/getSign", {
  167. data: params,
  168. dataType: "json",
  169. type: "post",
  170. success: function(res){
  171. if (res.status == 200) {
  172. var t = res.data.timestamp;
  173. var noncestr = res.data.noncestr;
  174. var signature = res.data.signature;
  175. wx.config({
  176. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  177. appId: appId, // 必填,公众号的唯一标识
  178. timestamp: t, // 必填,生成签名的时间戳
  179. nonceStr: noncestr, // 必填,生成签名的随机串
  180. signature: signature,// 必填,签名,见附录1
  181. jsApiList: [
  182. 'closeWindow'
  183. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  184. });
  185. }
  186. }
  187. });
  188. }