doctor-homepage.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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("grey")){
  79. concernDoctor();
  80. }else{
  81. //先判断是否有未结束的咨询,如果有未结束的咨询则不允许取消关注
  82. d.show();
  83. is_consult_finished(true);
  84. }
  85. })
  86. }
  87. //关注医生
  88. function concernDoctor(addConsult){
  89. d.show();
  90. var url = "/patient/concern/addConcern",
  91. params = {
  92. patient: userAgent.uid,
  93. doctor: doctor,
  94. concernSource: type || '2'//(关注方式: 1扫描二维码 2咨询关注 3.其他)
  95. };
  96. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  97. if(res.status == 200){
  98. console.log(res);
  99. if(addConsult){
  100. is_consult_finished();
  101. }else{
  102. //修改关注按钮的状态
  103. d.close();
  104. $("#isFocus").text("已关注");
  105. $("#isFocus").removeClass("grey");
  106. }
  107. }else{
  108. queryFailed(res);
  109. }
  110. })
  111. }
  112. //取消关注
  113. function cancelConcern(){
  114. // d.show();
  115. var url = "/patient/concern/deleteConcern",
  116. params = {
  117. patient: userAgent.uid,
  118. doctor: doctor
  119. };
  120. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  121. d.close();
  122. if(res.status == 200){
  123. $("#isFocus").text("关注");
  124. $("#isFocus").addClass("grey");
  125. }else{
  126. queryFailed(res);
  127. }
  128. })
  129. }
  130. //判断是否有未结束的咨询
  131. function is_consult_finished(isCancelConcern){
  132. var url = 'patient/consult/is_consult_unfinished',
  133. params = {doctor: docInfo.doctor};
  134. sendPost(url, params, 'json', 'post', function(res){
  135. queryFailed(res, '获取是否存在咨询失败');
  136. },function(res){
  137. if(res.status == 200){
  138. if(res.data == ""){
  139. if(isCancelConcern){
  140. cancelConcern();
  141. }else{
  142. checkDocInWork();
  143. // window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  144. }
  145. } else {
  146. d.close();
  147. var content = '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,';
  148. if(isCancelConcern){
  149. content += '需结束咨询后才能取消关注';
  150. }else{
  151. content += '无法发起新的咨询';
  152. }
  153. dialog({
  154. content: content,
  155. okValue:'前往查看',
  156. ok: function (){
  157. var url = "../../qygl/html/sign_info.html?consult="+res.data+"&doctor="+docInfo.doctor;
  158. window.location.href = url;
  159. },
  160. cancelValue: '我知道了',
  161. cancel: function () {
  162. return;
  163. }
  164. }).showModal();
  165. }
  166. } else {
  167. queryFailed(res)
  168. }
  169. });
  170. }
  171. //获取签约医生的工作时间
  172. function checkDocInWork(){
  173. var url = 'patient/consult/isDoctorWorkWhenconsult',
  174. params = {
  175. doctor: doctor
  176. };
  177. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  178. if(res.status == 200){
  179. d.close();
  180. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  181. if(!(res.data == "1")){
  182. dialog({
  183. content: '您好,由于您关注的医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  184. okValue:'查看医生工作时间',
  185. ok: function (){
  186. window.location.href = "doctor-work-hours.html?doctor=" + doctor;
  187. },
  188. cancelValue: '继续新增咨询',
  189. cancel: function () {
  190. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  191. }
  192. }).showModal();
  193. }else{
  194. //跳转到新增咨询页面
  195. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  196. }
  197. }else{
  198. queryFailed(res);
  199. }
  200. });
  201. }
  202. function queryFailed(res){
  203. d.close();
  204. if (res && res.msg) {
  205. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  206. } else {
  207. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  208. }
  209. }
  210. //获取微信信息,并配置微信api接口
  211. function wxGetSign(){
  212. var params = {};
  213. params.pageUrl = window.location.href;
  214. $.ajax(server + "weixin/getSign", {
  215. data: params,
  216. dataType: "json",
  217. type: "post",
  218. success: function(res){
  219. if (res.status == 200) {
  220. var t = res.data.timestamp;
  221. var noncestr = res.data.noncestr;
  222. var signature = res.data.signature;
  223. wx.config({
  224. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  225. appId: appId, // 必填,公众号的唯一标识
  226. timestamp: t, // 必填,生成签名的时间戳
  227. nonceStr: noncestr, // 必填,生成签名的随机串
  228. signature: signature,// 必填,签名,见附录1
  229. jsApiList: [
  230. 'closeWindow'
  231. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  232. });
  233. }
  234. }
  235. });
  236. }