doctor-homepage.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. var d1 = dialog({
  6. contentType: 'load',
  7. skin: 'bk-popup',
  8. content: '提交中...'
  9. });
  10. var doctor = "";
  11. var isQr = "";
  12. var waitSign;
  13. // 链接中是否有openid
  14. var openidInLink = false;
  15. // 存储链接中携带的wlyyPatientInviteLogCode参数,用来判断是否是从推送消息进入处理“签约邀请”
  16. var signInvitationInLink;
  17. var pagetype = 18;
  18. $(function() {
  19. var userAgent = window.localStorage.getItem(agentName);
  20. Request = GetRequest();
  21. var openid = Request["openid"];
  22. var code = Request["code"];
  23. isQr = Request["isQr"];
  24. openidInLink = openid!==undefined?true:false;
  25. signInvitationInLink = Request["wlyyPatientInviteLogCode"];
  26. if(!userAgent) {
  27. if(!openid) {
  28. sendPost("weixin/getOpenidByCode", {
  29. "code": code
  30. }, 'JSON', 'GET',
  31. function(res) {
  32. queryFailed(res);
  33. },
  34. function(res) {
  35. if(res.status == 200) {
  36. openid = res.openid;
  37. window.localStorage.setItem(pageName, "{\"pageurl\":\"" + window.location.href + "\"}");
  38. window.location.href = "../../home/html/login.html?type=0&openid=" + openid;
  39. } else {
  40. queryFailed(res);
  41. }
  42. });
  43. }
  44. }
  45. // 获取微信授权
  46. closeWindow();
  47. queryInit();
  48. });
  49. function popThanksDialog() {
  50. dialog({
  51. content: '<div class="c-t-left">感谢您签约家庭医生,您可将家庭医生推荐给更多好友,让大家一起享受家庭医生全方位的服务~</div>',
  52. okValue:'前往分享',
  53. ok: function (){
  54. location.href = 'signing-share.html'
  55. },
  56. cancelValue: '我知道了',
  57. cancel: function () {
  58. return;
  59. }
  60. }).showModal();
  61. }
  62. function closeWindow() {
  63. var Request = new Object();
  64. Request = GetRequest();
  65. var code = Request["code"];
  66. //从后台那边获取签名等信息
  67. var params = {};
  68. params.pageUrl = window.location.href;
  69. $.ajax(server + "weixin/getSign", {
  70. data: params,
  71. dataType: "json",
  72. type: "post",
  73. success: function(res) {
  74. if(res.status == 200) {
  75. var t = res.data.timestamp;
  76. var noncestr = res.data.noncestr;
  77. var signature = res.data.signature;
  78. wx.config({
  79. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  80. appId: appId, // 必填,公众号的唯一标识
  81. timestamp: t, // 必填,生成签名的时间戳
  82. nonceStr: noncestr, // 必填,生成签名的随机串
  83. signature: signature, // 必填,签名,见附录1
  84. jsApiList: [
  85. 'closeWindow'
  86. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  87. });
  88. }
  89. }
  90. });
  91. }
  92. function popOverlay(flag) {
  93. var height = document.body.scrollHeight,
  94. $pop = $('#overlay_pop');
  95. $('#introduce_guide').hide();
  96. $('#introduce_text').hide();
  97. if(flag) {
  98. $pop.one('click',function() {
  99. $('.btn-main img').attr('src','../images/geduoxuanfu_icon.png');
  100. $('.btn-item').hide();
  101. $('.btn-main').addClass('close');
  102. $('#introduce_guide').hide();
  103. $('#introduce_text').hide();
  104. $pop.hide();
  105. });
  106. $pop.height(height).show();
  107. } else {
  108. $pop.hide();
  109. }
  110. }
  111. function queryInit() {
  112. d.show();
  113. var data = {};
  114. var Request = new Object();
  115. Request = GetRequest();
  116. doctor = Request["state"];
  117. waitSign = Request["waitSign"];
  118. data.doctor = doctor;
  119. if(waitSign) {
  120. popThanksDialog();
  121. }
  122. sendPost('patient/family_contract/homepage', data, 'json', 'post', queryFailed, querySuccess);
  123. }
  124. function queryFailed(res) {
  125. d.close();
  126. if(res && res.msg) {
  127. dialog({
  128. contentType: 'tipsbox',
  129. skin: 'bk-popup',
  130. content: res.msg
  131. }).show();
  132. } else {
  133. dialog({
  134. contentType: 'tipsbox',
  135. skin: 'bk-popup',
  136. content: '加载失败'
  137. }).show();
  138. }
  139. }
  140. function querySuccess(res) {
  141. // TODO 示例数据
  142. // res = {
  143. // "msg": "医生主页查询成功!",
  144. // "data": {
  145. // "doctor": "D20160322000002",
  146. // "jobName": "主任医师",
  147. // "intro": "慢性阻塞性肺疾病、支气管扩张等能够较为熟练地结合中医辨证与西医辨病两套方法进",
  148. // "name": "聂青",
  149. // "sign": -1,
  150. // "photo": "http://172.19.103.85:8882/res/images/2016/07/27/20160727010854_298.jpeg",
  151. // "dept": "呼吸内科",
  152. // "services": [],
  153. // "job": "",
  154. // "hospital": "金山社区医疗服务中心",
  155. // "expertise": "及实验研究工作十年余,先后参加国家级、省部级多项课题的研究,在科室积极开展的中医特色疗法如穴位注射和敷贴、中药雾化等,疗效显著,对疑难疾病的诊治能坚持自己的观点,和科室同仁一道成功抢救许多肺心病、肺性脑病和呼吸衰竭等危重患。",
  156. // "group": "0"
  157. // },
  158. // "status": 200
  159. // };
  160. if(res.status == 200) {
  161. var name = res.data.name;
  162. var jobName = res.data.job;
  163. var hospitalName = res.data.hospital;
  164. var deptName = res.data.dept;
  165. var photo = res.data.photo;
  166. var expertise = res.data.expertise;
  167. var introduce = res.data.intro;
  168. var sign = Number(res.data.sign);
  169. var group = Number(res.data.group);
  170. var url2 = photo;
  171. var sex = res.data.sex;
  172. if(!photo){
  173. if(sex==1){
  174. url2 = "d-male.png";
  175. }else if(sex==2){
  176. url2 = "d-female.png";
  177. }else{
  178. url2 = "noSexDoctor.jpg";
  179. }
  180. }
  181. if(!jobName) jobName = "";
  182. if(!deptName) deptName = "";
  183. if(!expertise) expertise = "无";
  184. if(!introduce) introduce = "无";
  185. document.getElementById("photo").src = url2;
  186. document.getElementById("name").innerHTML = name;
  187. document.getElementById("jobName").innerHTML = jobName;
  188. document.getElementById("hospitalName").innerHTML = hospitalName;
  189. document.getElementById("deptName").innerHTML = deptName;
  190. document.getElementById("expertise").innerHTML = expertise;
  191. document.getElementById("introduce").innerHTML = introduce;
  192. document.getElementById("doctor_name").innerHTML = name;
  193. if(group == 1) {
  194. $("#ul-health").show();
  195. } else if(group == 2) {
  196. $("#ul-disease").show();
  197. } else if(group == 3) {
  198. $("#ul-sixfive").show();
  199. } else {
  200. $("#ul-common").show();
  201. }
  202. if(sign == 0) { // 待签约
  203. document.getElementById("btnSign").innerHTML = '<a onclick="cancelSign()" class="c-btn c-btn-E0A526 c-btn-full c-btn-radius c-f18">取消申请</a>';
  204. $('#btnSign').show();
  205. } else if(sign == 1) { // 已签约
  206. //document.getElementById("btnSign").innerHTML = '<a onclick="overSign()" class="c-btn c-btn-E0A526 c-btn-full c-btn-radius c-f18">申请解约</a>';
  207. $('#btnSign').hide();
  208. $('#btnMenu').show();
  209. $('.btn-main>img').on('click',function() {
  210. if($(this).hasClass('close')) {
  211. popOverlay(true);
  212. $('.btn-main img').attr('src','../images/xuanfuguanbi_icon.png');
  213. $('.btn-item').show();
  214. $(this).removeClass('close');
  215. } else {
  216. popOverlay(false);
  217. $('.btn-main img').attr('src','../images/geduoxuanfu_icon.png');
  218. $('.btn-item').hide();
  219. $(this).addClass('close');
  220. }
  221. });
  222. $('#btnMenu').on('click','.btn-item>img',function () {
  223. var type = $(this).attr('data-type');
  224. switch(type) {
  225. case 'break':
  226. overSign();
  227. $('.btn-main>img').click();
  228. break;
  229. case 'introduce':
  230. $('.btn-main img').attr('src','../images/geduoxuanfu_icon.png');
  231. $('.btn-item').hide();
  232. $('.btn-main').addClass('close');
  233. $('#introduce_guide').show();
  234. $('#introduce_text').show();
  235. break;
  236. case 'consultation':
  237. break;
  238. }
  239. });
  240. } else if(sign == -1) { // 患者解约
  241. // 有openid显示“申请签约”按钮
  242. if(openidInLink) {
  243. document.getElementById("btnSign").innerHTML = '<a onclick="startSign()" class="c-btn c-btn-4dcd70 c-btn-full c-btn-radius c-f18">申请签约</a>';
  244. $('#btnSign').show();
  245. }
  246. // 邀请签约时显示
  247. else if(signInvitationInLink) {
  248. document.getElementById("sign_invitation").innerHTML =
  249. '<div class="c-row">'
  250. +'<div class="c-50 c-tac height-50 lheight-50 bc-ff9526 c-fff" onclick="ignoreSignInvitation()">忽略签约邀请</div>'
  251. +'<div class="c-50 c-tac height-50 lheight-50 bc-75bf00 c-fff"><a href="javascript:void(0);" onclick="agreeSignInvitation()" class="c-fff">同意与其签约</a></div>'
  252. +'</div>';
  253. }
  254. // 否则显示医生二维码
  255. else {
  256. $('#doctor_qrcode').show();
  257. }
  258. $("#divAgree").hide();
  259. } else if(sign == 2) { // 待解约
  260. document.getElementById("btnSign").innerHTML = '<span class="c-f18" style="color: #E71F19;">您已申请了解约,流程审核中,请等待!!</span>';
  261. $('#btnSign').show();
  262. } else {
  263. document.getElementById("btnSign").innerHTML = '<span class="c-f18" style="color: #E71F19;">医生申请与您解约,流程审核中,请等待!!</span>';
  264. $('#btnSign').show();
  265. }
  266. d.close();
  267. } else {
  268. queryFailed(res);
  269. }
  270. }
  271. //申请签约
  272. function startSign() {
  273. if(isQr != false) {
  274. // sendPost('patient/family_contract/checkOpenid', {}, 'json', 'post', queryFailed, openidSuccess2);
  275. // 2016.08.31 yezehua 取消“无效的openid”错误提示
  276. sendPost('patient/family_contract/checkOpenid', {}, 'json', 'post', function() {}, openidSuccess2);
  277. } else {
  278. var doctorName = encodeURI(document.getElementById("name").innerHTML);
  279. var hospitalName = encodeURI(document.getElementById("hospitalName").innerHTML);
  280. window.location.href = "sign-agreement.html?doctor=" + doctor + "&doctorName=" + doctorName + "&hospitalName=" + hospitalName;
  281. }
  282. }
  283. function changeAgreement() {
  284. window.location.href = "sign-agreement1.html";
  285. }
  286. function cancelSign() {
  287. dialog({
  288. title: '提示',
  289. content: '您确定继续取消和' + document.getElementById("name").innerHTML + '医生的签约吗?',
  290. ok: function() {
  291. d1.showModal();
  292. var data = {};
  293. data.doctor = doctor;
  294. sendPost('patient/family_contract/unsign', data, 'json', 'post', submitFailed, submitSuccess);
  295. },
  296. cancel: function() {
  297. return;
  298. }
  299. }).showModal();
  300. }
  301. function overSign() {
  302. $("#txtInfo").hide();
  303. dialog({
  304. title: '申请解约',
  305. skin: "ui-dialog ax-popup pror",
  306. content: $("#xf-artd").get(0),
  307. ok: function() {
  308. var data = {};
  309. data.doctor = doctor;
  310. data.doctorName = document.getElementById("name").innerHTML;
  311. data.reason = $("#textReason").val();
  312. if(data.reason == "" || data.reason == null) {
  313. $("#txtInfo").show();
  314. return false;
  315. } else {
  316. $("#txtInfo").hide();
  317. d1.showModal();
  318. sendPost('patient/family_contract/surrender', data, 'json', 'post', submitFailed, submitSuccess2);
  319. return;
  320. }
  321. },
  322. cancel: function() {
  323. return;
  324. }
  325. }).showModal();
  326. }
  327. function submitFailed(res) {
  328. d1.close();
  329. if(res && res.msg) {
  330. dialog({
  331. contentType: 'tipsbox',
  332. skin: 'bk-popup',
  333. content: res.msg
  334. }).show();
  335. } else {
  336. dialog({
  337. contentType: 'tipsbox',
  338. skin: 'bk-popup',
  339. content: '操作失败'
  340. }).show();
  341. }
  342. }
  343. function submitSuccess(res) {
  344. if(res.status == 200) {
  345. d1.close();
  346. window.location.href = "choose-region.html";
  347. } else {
  348. submitFailed(res);
  349. }
  350. }
  351. function submitSuccess2(res) {
  352. if(res.status == 200) {
  353. document.getElementById("btnSign").innerHTML = '<span class="c-f18" style="color: #E71F19;">您已申请了解约,流程审核中,请等待!!</span>';
  354. d1.close();
  355. dialog({
  356. contentType: 'tipsbox',
  357. skin: 'bk-popup',
  358. content: '解约申请成功'
  359. }).show();
  360. window.scrollTo(0, 0);
  361. //window.location.href = "doctor-home-page.html?doctor=" + doctor;
  362. } else {
  363. submitFailed(res);
  364. }
  365. }
  366. //判断是否有三师信息
  367. function checkTeacter() {
  368. var data = {};
  369. sendPost('patient/teachers', data, 'json', 'post', queryFailedTeacter, querySuccessTeacter);
  370. }
  371. function querySuccessTeacter(res) {
  372. if(res.status == 200) {
  373. d.close();
  374. var list = res.data.list;
  375. if(list.length > 0) {
  376. var doctorTemp = "";
  377. var doctorName = "";
  378. for(var i = 0; i < list.length; i++) {
  379. var data = list[i];
  380. if(Number(data.type) == 2) {
  381. doctorTemp = data.code;
  382. doctorName = data.name;
  383. }
  384. }
  385. var doctorNameTemp = document.getElementById("name").innerHTML;
  386. if(doctorNameTemp != doctorName) {
  387. dialog({
  388. title: '提示',
  389. content: '您已存在三师签约,签约医生为' + doctorName + '医生,继续与' + doctorName + '医生签约家庭医生服务吗?',
  390. ok: function() {
  391. window.location.href = "doctor-home-page.html?doctor=" + doctorTemp;
  392. }
  393. }).showModal();
  394. } else {
  395. familyDoctor();
  396. }
  397. } else {
  398. familyDoctor();
  399. }
  400. } else if(res.status == 1 || res.status == 2) {
  401. d.close();
  402. familyDoctor();
  403. } else {
  404. queryFailedTeacter(res);
  405. }
  406. }
  407. //成功
  408. function openidSuccess2(res) {
  409. if(res.status == 200) {
  410. if(res.data == null || res.data == "") {
  411. checkTeacter();
  412. } else {
  413. queryDoctor(res);
  414. }
  415. } else {
  416. // 2016.08.31 yezehua 取消“无效的openid”错误提示
  417. // queryFailed(res);
  418. }
  419. }
  420. //获取家庭签约的医生信息
  421. function queryDoctor(res) {
  422. var data = {};
  423. data.doctor = res.data;
  424. sendPost('patient/family_contract/homepage', data, 'json', 'post', queryFailed, querySuccess3);
  425. }
  426. function querySuccess3(res) {
  427. if(res.status == 200) {
  428. var doctorName = document.getElementById("name").innerHTML;
  429. if(res.data.name != doctorName) {
  430. dialog({
  431. title: '提示',
  432. content: '您已存在家庭签约,签约医生为' + res.data.name + '医生,只可以签约一个家庭医生',
  433. ok: function() {
  434. wx.closeWindow();
  435. }
  436. }).showModal();
  437. } else {
  438. familyDoctor();
  439. }
  440. } else {
  441. queryFailed(res);
  442. }
  443. }
  444. function familyDoctor(querystr) {
  445. var doctorName = encodeURI(document.getElementById("name").innerHTML);
  446. var hospitalName = encodeURI(document.getElementById("hospitalName").innerHTML);
  447. window.location.href = "agreement.html?doctor=" + doctor + "&doctorName=" + doctorName + "&hospitalName=" + hospitalName+(querystr||"");
  448. }
  449. function queryFailedTeacter(res) {
  450. d.close();
  451. if(res && res.msg) {
  452. dialog({
  453. contentType: 'tipsbox',
  454. skin: 'bk-popup',
  455. content: res.msg
  456. }).show();
  457. } else {
  458. dialog({
  459. contentType: 'tipsbox',
  460. skin: 'bk-popup',
  461. content: '加载失败'
  462. }).show();
  463. }
  464. }
  465. // 忽略签约邀请
  466. function ignoreSignInvitation() {
  467. sendPost('patient/family/updatePatientInviteLog', {patientInviteLogCode:signInvitationInLink,type:2}, 'json', 'post', function(){
  468. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  469. }, function(req) {
  470. if(req.status==200) {
  471. // 关闭页面,返回公众号
  472. wx.closeWindow();
  473. } else {
  474. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'处理失败'}).show();
  475. }
  476. });
  477. }
  478. // 同意与其签约
  479. function agreeSignInvitation() {
  480. sendPost('patient/family/updatePatientInviteLog', {patientInviteLogCode:signInvitationInLink,type:1}, 'json', 'post', function(){
  481. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  482. }, function(req) {
  483. if(req.status==200) {
  484. // 跳转到协议页面
  485. familyDoctor("&signInvitationCode="+signInvitationInLink);
  486. } else {
  487. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'处理失败'}).show();
  488. }
  489. });
  490. }