doctor-homepage.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. isdetailfull()
  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. docInfo.sign = 1;
  103. if(addConsult){
  104. isdetailfull();
  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. docInfo.sign = -1;
  133. $("#isFocus").text("关注");
  134. $("#isFocus").addClass("grey");
  135. $("#isFocus").removeClass("disabled");
  136. //修改关注数
  137. var count = $("#concern").text();
  138. $("#concern").text(parseInt(count) - 1);
  139. }else{
  140. $("#isFocus").removeClass("disabled");
  141. queryFailed(res);
  142. }
  143. })
  144. }
  145. //判断是否有未结束的咨询
  146. function is_consult_finished(isCancelConcern){
  147. var url = 'patient/consult/is_consult_unfinished',
  148. params = {doctor: docInfo.doctor};
  149. sendPost(url, params, 'json', 'post', function(res){
  150. queryFailed(res, '获取是否存在咨询失败');
  151. },function(res){
  152. if(res.status == 200){
  153. if(res.data == ""){
  154. if(isCancelConcern){
  155. cancelConcern();
  156. }else{
  157. checkDocInWork();
  158. // window.location.href = "add-consult.html?doctorCode="+docInfo.doctor+"&doctorName="+docInfo.name+"&jobName="+docInfo.jobName;
  159. }
  160. } else {
  161. d.close();
  162. $("#isFocus").removeClass("disabled");
  163. var content = '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,';
  164. if(isCancelConcern){
  165. content += '需结束咨询后才能取消关注';
  166. }else{
  167. content += '无法发起新的咨询';
  168. }
  169. dialog({
  170. content: content,
  171. okValue:'前往查看',
  172. ok: function (){
  173. var url = "../../qygl/html/sign_info.html?consult="+res.data+"&doctor="+docInfo.doctor;
  174. window.location.href = url;
  175. },
  176. cancelValue: '我知道了',
  177. cancel: function () {
  178. return;
  179. }
  180. }).showModal();
  181. }
  182. } else {
  183. queryFailed(res)
  184. }
  185. });
  186. }
  187. //获取签约医生的工作时间
  188. function checkDocInWork(){
  189. var url = 'patient/consult/isDoctorWorkWhenconsult',
  190. params = {
  191. doctor: doctor
  192. };
  193. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  194. $("#isFocus").removeClass("disabled");
  195. if(res.status == 200){
  196. d.close();
  197. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  198. if(!(res.data == "1")){
  199. dialog({
  200. content: '您好,由于您关注的医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  201. okValue:'查看医生工作时间',
  202. ok: function (){
  203. window.location.href = "doctor-work-hours.html?doctor=" + doctor;
  204. },
  205. cancelValue: '继续新增咨询',
  206. cancel: function () {
  207. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor;
  208. }
  209. }).showModal();
  210. }else{
  211. //跳转到新增咨询页面
  212. window.location.href = "add-consult.html?doctorCode="+docInfo.doctor;
  213. }
  214. }else{
  215. queryFailed(res);
  216. }
  217. });
  218. }
  219. function isdetailfull(){
  220. d.show();
  221. var reqParams = [{
  222. url: "patient/baseinfo",
  223. data: {},
  224. reqType: 'post'
  225. }]
  226. getReqPromises(reqParams).then(function(ress){
  227. d.close();
  228. if (ress[0].status == 200) {
  229. if(ress[0].data.label){
  230. is_consult_finished();
  231. }else{
  232. dialog({
  233. content: '请完善您的资料',
  234. okValue:'前往完善',
  235. ok: function (){
  236. window.location.href = "../../grzx/html/my-detail.html";
  237. // window.location.href = "../../grzx/html/updateService.html?doctor="+doctor;
  238. },
  239. cancelValue: '暂不咨询',
  240. cancel: function () {
  241. }
  242. }).showModal();
  243. }
  244. }
  245. });
  246. }
  247. function queryFailed(res){
  248. d.close();
  249. if (res && res.msg) {
  250. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  251. } else {
  252. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  253. }
  254. }
  255. //获取微信信息,并配置微信api接口
  256. function wxGetSign(){
  257. var params = {};
  258. params.pageUrl = window.location.href;
  259. $.ajax(server + "weixin/getSign", {
  260. data: params,
  261. dataType: "json",
  262. type: "post",
  263. success: function(res){
  264. if (res.status == 200) {
  265. var t = res.data.timestamp;
  266. var noncestr = res.data.noncestr;
  267. var signature = res.data.signature;
  268. wx.config({
  269. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  270. appId: appId, // 必填,公众号的唯一标识
  271. timestamp: t, // 必填,生成签名的时间戳
  272. nonceStr: noncestr, // 必填,生成签名的随机串
  273. signature: signature,// 必填,签名,见附录1
  274. jsApiList: [
  275. 'closeWindow'
  276. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  277. });
  278. }
  279. }
  280. });
  281. }