p2dzixun.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. var lastId = 0;
  2. var prevImage,
  3. offTop = 46,
  4. offBot = 0;
  5. var consultInfo;
  6. var isJieshuCaozuo = false;
  7. var notEndConsultId;
  8. var isNotQzQkys = false;
  9. var isYaoQingQk = true; //是否建管已邀请全科 true:已邀请 ;false:未邀请
  10. mui.plusReady(function() {
  11. self = plus.webview.currentWebview();
  12. $('#title').html(self.otherName);
  13. getMineInfo(); //初始化个人信息
  14. consultInfo = self.consultInfo;
  15. createSession(self.type, getMembersExt);
  16. prevImage = mui.previewImage();
  17. var opener = self.opener();
  18. if(opener && opener.id == "faqizixun") {
  19. mui.back = backToWebviewById("mingyizixunliebiao", false, function() {
  20. var mainWebview = plus.webview.getWebviewById("mingyizixunliebiao");
  21. mui.fire(mainWebview, "activeItem");
  22. });
  23. }else if(opener && (opener.id == "zixunxiangqing")) {
  24. var zxxq = plus.webview.getWebviewById("zixunxiangqing");
  25. zxxq.close('none');
  26. backToZdzx();
  27. } else if(opener && (opener.id == "zuyuanziliao")) {
  28. function closeOpener(cur) {
  29. if(cur.id != "xiaoxi.html" && cur.id != "main" && cur.id != "../../tuandui/html/tuandui.html" &&
  30. cur.id != "mine.html" && cur.id != "home1.html" && cur.id != "home2.html" && cur.id != "huanzhe.html") {
  31. var opener = cur.opener();
  32. cur.close();
  33. closeOpener(opener);
  34. }
  35. }
  36. mui.back = function() {
  37. closeOpener(self.opener());
  38. self.close();
  39. var mainWebview = plus.webview.getWebviewById("main");
  40. mui.fire(mainWebview, "activeXiaoxi");
  41. mainWebview.show();
  42. }
  43. } else {
  44. backToParent();
  45. }
  46. });
  47. function getMembersExt() {
  48. getMembers(function() {
  49. for(var k in members) {
  50. if(members[k].role == 1) { //全科还没有被邀请
  51. isNotQzQkys = true;
  52. isYaoQingQk = false; //未被邀请
  53. }
  54. }
  55. isSign();
  56. });
  57. }
  58. var qyRelation = 0;
  59. function isSign() {
  60. sendPost("doctor/family_contract/doctor_patient_sign_exist", {
  61. doctor: docInfo.code,
  62. patient: otherCode
  63. }, null, function(res) {
  64. if(res.status == 200) {
  65. if(res.data.status != -1 && res.data.status != 0) {
  66. //没有签约关系
  67. qyRelation = 1;
  68. }
  69. consultInfo ? initPage() : getConsultInfo();
  70. } else {
  71. mui.toast("获取签约关系失败!");
  72. }
  73. })
  74. }
  75. function backToZdzx() {
  76. var old_back = mui.back;
  77. mui.back = function() {
  78. if(isJieshuCaozuo) {
  79. wv = plus.webview.getWebviewById("zixunjilu");
  80. if(wv) {
  81. wv.reload(true);
  82. }
  83. }
  84. var wv = plus.webview.getWebviewById("zhidingzixun");
  85. if(wv) {
  86. mui.fire(wv, "refresh");
  87. }
  88. old_back();
  89. }
  90. }
  91. //标签数目影响的轮播事件
  92. function bindSlider() {
  93. $('.notmy').hide();
  94. $('#muiSliderIndicator').hide();
  95. $('.mui-slider-group').removeClass('.mui-slider-group');
  96. var slider = mui('#other_div').slider();
  97. slider.stopped = true; //关闭滑动切换
  98. }
  99. /**
  100. * 获取咨询信息
  101. */
  102. function getConsultInfo() {
  103. plus.nativeUI.showWaiting();
  104. imClient.Sessions.isTopicEnded(sessionId, "current", function(res) {
  105. if(isEmptyObject(res)) { //患者和医生建立了会话,但是患者没有发送任何咨询信息
  106. $('#input_div').hide();
  107. consultInfo = {
  108. patient: otherCode
  109. }
  110. //getNewMsgs(true);
  111. if(!observer) {
  112. $('#wrapper1').css({
  113. top: '16px',
  114. bottom: '52px'
  115. });
  116. $('.xzzd').show();
  117. } else {
  118. $('#wrapper1').css({
  119. top: '16px',
  120. bottom: '0px'
  121. });
  122. $('.xzzd').hide();
  123. }
  124. getFirstMsgs();
  125. } else {
  126. if(res.status == 10) { //咨询已结束
  127. if(qyRelation == 1 && !observer) {
  128. $('#wrapper1').css({
  129. top: '16px',
  130. bottom: '52px'
  131. });
  132. $('.xzzd').show();
  133. } else {
  134. $('#wrapper1').css({
  135. top: '16px',
  136. bottom: '0px'
  137. });
  138. $('.xzzd').hide();
  139. }
  140. $('#input_div').hide();
  141. consultInfo = {
  142. patient: otherCode
  143. }
  144. //getNewMsgs(true);
  145. getFirstMsgs();
  146. } else { //咨询未结束
  147. $('#wrapper1').css('bottom', '52px');
  148. offBot = 52;
  149. if(myScroll) myScroll.refresh();
  150. notEndConsultId = res.id;
  151. $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
  152. sendPost("/doctor/talkgroup/getConsultByGroupCode", {
  153. consultCode: res.id
  154. }, null, function(res) {
  155. console.log(JSON.stringify(res))
  156. consultInfo = res.data;
  157. if(consultInfo) {
  158. if(consultInfo.type == 7 || consultInfo.type == 6) {
  159. bindSlider()
  160. }
  161. }
  162. //getNewMsgs(true);
  163. getFirstMsgs();
  164. PDZiXuanLieXing();
  165. })
  166. }
  167. }
  168. plus.nativeUI.closeWaiting();
  169. }, function(res) {
  170. plus.nativeUI.closeWaiting();
  171. mui.toast("判断是否存在未结束咨询失败")
  172. })
  173. }
  174. //判断object是否为空
  175. function isEmptyObject(e) {
  176. var t;
  177. for(t in e)
  178. return !1;
  179. return !0
  180. }
  181. /**
  182. * 初始化页面
  183. */
  184. function initPage() {
  185. if(consultInfo.type == 7 || consultInfo.type == 6) {
  186. bindSlider()
  187. }
  188. console.log(docInfo.code)
  189. console.log(consultInfo.patient)
  190. sendPost("/doctor/consult/is_consult_unfinished", {//?
  191. doctor: docInfo.code,
  192. patient: consultInfo.patient
  193. }, undefined,
  194. function(res) {
  195. console.log(res)
  196. if(res.status == 200) {
  197. consultInfo.hasOver = res.data;
  198. if(res.data != "") { //咨询未结束
  199. notEndConsultId = res.data;
  200. $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
  201. $('#wrapper1').css('bottom', '52px');
  202. offBot = 52;
  203. if(myScroll) myScroll.refresh();
  204. PDZiXuanLieXing();
  205. } else { //咨询已结束
  206. if(qyRelation == 1 && !observer) {
  207. $('#wrapper1').css({
  208. top: '16px',
  209. bottom: '52px'
  210. });
  211. $('.xzzd').show();
  212. } else {
  213. $('#wrapper1').css({
  214. top: '16px',
  215. bottom: '0px'
  216. });
  217. $('.xzzd').hide();
  218. }
  219. $('#input_div').hide();
  220. }
  221. //getNewMsgs(true);
  222. getFirstMsgs();
  223. } else {
  224. mui.toast("获取信息失败");
  225. }
  226. }
  227. )
  228. }
  229. /**
  230. * 点击查看好友详细信息
  231. */
  232. $('#qun_detail').on("tap", function() {
  233. mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', {
  234. extras: {
  235. patiCode: consultInfo.patient
  236. }
  237. });
  238. })
  239. /**
  240. * 获取聊天图片列表
  241. */
  242. function getImgMsgList(handle) {
  243. im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) {
  244. console.log("imgs:" + JSON.stringify(data));
  245. chatCache.imgs = data.records.reverse();
  246. appendPrevImgs(chatCache.imgs);
  247. if(handle) handle(data);
  248. }, 2);
  249. }
  250. /**
  251. * 发送消息
  252. */
  253. function uploadMsg(type, content, locSrc, isNotSend, callBack) {
  254. service.isConsultFinished(notEndConsultId, function(res) {
  255. if(res.data == 0) {
  256. //作用: 更新咨询状态
  257. // sendPost("doctor/consult/reply", {
  258. // patient: otherCode,
  259. // consult: consultInfo.consult,
  260. // type: type,
  261. // content: content
  262. // }, null, function(res) {
  263. //
  264. // })
  265. uploadMsgBase(type, content, locSrc, isNotSend, callBack);
  266. } else if(res == "timeout" && type == 1) {
  267. var tim = new Date().getTime();
  268. var id = "loc" + tim;
  269. var d = [{
  270. "sender_id": docInfo.code,
  271. "sender_name": docInfo.name,
  272. "content_type": 1,
  273. "content": content,
  274. "timestamp": tim,
  275. "id": id,
  276. local_src: "",
  277. beforeSend: true
  278. }];
  279. showMsg(d, false, false, true);
  280. addMsgToCache(d, true);
  281. $('#contain dl[data-code="' + id + '"]').find('.c-msg').prepend("<i data-info='" + JSON.stringify(d[0]) + "' class='c-tips'></i>");
  282. } else {
  283. $('.topmsg').hide();
  284. if(qyRelation == 1 && !observer) {
  285. $('#wrapper1').css({
  286. top: '16px',
  287. bottom: '52px'
  288. });
  289. $('.xzzd').show();
  290. } else {
  291. $('#wrapper1').css({
  292. top: '16px',
  293. bottom: '0px'
  294. });
  295. $('.xzzd').hide();
  296. }
  297. $('#input_div').hide();
  298. myScroll.refresh();
  299. }
  300. })
  301. }
  302. /**
  303. * 代预约
  304. */
  305. function dyyjl() {
  306. mui.openWindow('../../wdyy/html/appointment-register.html', 'appointment-register', {
  307. extras: {
  308. patient: consultInfo.patient
  309. }
  310. });
  311. }
  312. /**
  313. * 健康教育
  314. */
  315. function jkjy() {
  316. // mui.openWindow('../../jkjy/html/jiankangjiaoyu.html', 'jiankangjiaoyu', {
  317. var self = plus.webview.currentWebview();
  318. mui.openWindow('../../jkjy/html/article-store.html', 'jiankangjiaoyu', {
  319. extras: {
  320. patient: consultInfo.patient,
  321. patientName: consultInfo.name,
  322. referrer: self.id
  323. }
  324. });
  325. }
  326. /**
  327. * 健康指导
  328. */
  329. function jkzd() {
  330. mui.openWindow('../../hzzd/html/guidance_list.html', 'jkzd', {
  331. extras: {
  332. code: otherCode
  333. }
  334. });
  335. }
  336. /**
  337. * 临时随访
  338. */
  339. function lssf() {
  340. var url = "../../suifang/html/choose_suifang.html";
  341. mui.openWindow(url, 'choose_suifang', {
  342. extras: {
  343. patiCode: otherCode
  344. }
  345. });
  346. }
  347. //判断咨询类型各种情况
  348. var quankeCode = ""; //全科code
  349. var jianguanCode = ""; //建管code
  350. function PDZiXuanLieXing() {
  351. if(self.type != "1") { // 家庭医生咨询或三师咨询才能请求doctor/family_contract/patient_team_doctors接口
  352. return ;
  353. }
  354. sendPost("/doctor/family_contract/patient_team_doctors", {
  355. sessionId: self.sessionId
  356. }, null, function(res) {
  357. // console.error(JSON.stringify(res))
  358. if(res.status == 200) {
  359. var curConsultType = consultInfo.type; //当前的咨询类型 1:三师签约 2:家庭签约
  360. var curDoctorCode = docInfo.code;
  361. var data = res.data;
  362. var qianyueData = null;
  363. if(curConsultType == 1) { //三师签约
  364. qianyueData = data.ssSign;
  365. } else if(curConsultType == 2) { //家庭签约
  366. qianyueData = data.jtSign;
  367. }
  368. if(qianyueData) {
  369. quankeCode = qianyueData.doctor.doctor;
  370. jianguanCode = qianyueData.doctorHealth.doctor;
  371. }
  372. //当前医生既是全科,也是建管:显示求助专科
  373. if(curDoctorCode == jianguanCode && curDoctorCode == quankeCode) {
  374. $("#qiuzhuico p").html("求助");
  375. }
  376. //当前医生是建管,不是全科:显示邀请全科
  377. else if(curDoctorCode == jianguanCode && curDoctorCode != quankeCode) {
  378. $("#qiuzhuico p").html("邀请全科");
  379. }
  380. //当前医生不是建管,是全科:显示求助专科
  381. else if(curDoctorCode != jianguanCode && curDoctorCode == quankeCode) {
  382. $("#qiuzhuico p").html("求助");
  383. }
  384. } else {
  385. mui.toast("获取患者和医生咨询类型失败!");
  386. }
  387. })
  388. }
  389. /**
  390. * 求助/邀请全科
  391. */
  392. function qiuzhu() {
  393. plus.nativeUI.showWaiting();
  394. if($("#qiuzhuico p").html() == "邀请全科") {
  395. if(isYaoQingQk) { //已邀请全科
  396. mui.toast("已邀请全科");
  397. plus.nativeUI.closeWaiting();
  398. } else { //去邀请全科
  399. var userAgent = plus.storage.getItem("userAgent");
  400. //记录观察者模式
  401. if(JSON.parse(userAgent).teamCode == "1"){
  402. mui.toast("观察者模式无法进行增删改操作");
  403. plus.nativeUI.closeWaiting();
  404. return;
  405. }
  406. imClient.Sessions.addParticipant(sessionId, quankeCode, function(res) {
  407. mui.toast("邀请成功!");
  408. isYaoQingQk = true;
  409. imClient.Sessions.sendMessage(sessionId, docInfo.code, "系统", docInfo.name + "已邀请全科医生一起参与咨询", 13,
  410. function(data) {
  411. showMsg(data.messages, false, false, true);
  412. plus.nativeUI.closeWaiting();
  413. },
  414. function(data) {
  415. console.log("sendFail" + JSON.stringify(data));
  416. })
  417. }, function(res) {
  418. console.error(JSON.stringify(res));
  419. mui.toast('邀请失败,请稍后重试!');
  420. })
  421. }
  422. } else { //求助医生
  423. mui.openWindow('../../qzys/html/select_doctor.html', 'qzys-select_doctor', {
  424. extras: {
  425. consultInfo: consultInfo,
  426. sessionId:self.sessionId,
  427. accessData: {
  428. consultCode: consultInfo.consult,
  429. patient: consultInfo.patient
  430. }
  431. }
  432. });
  433. }
  434. }
  435. function jieshu() {
  436. dialog({
  437. content: '<div><div class="c-f16 c-333">结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?</div></div>',
  438. okValue: '继续结束',
  439. cancelValue: '我再看看',
  440. cancel: function () {
  441. return;
  442. },
  443. ok: function() {
  444. sendPost("doctor/consult/finish_consult", {
  445. consult: notEndConsultId
  446. }, null, function(res) {
  447. if(res.status == 200) {
  448. isJieshuCaozuo = true;
  449. $('.topmsg').html("咨询求助已结束");
  450. $('#input_div').hide();
  451. if(qyRelation == 1 && !observer) {
  452. $('#wrapper1').css({
  453. bottom: '52px'
  454. });
  455. $('.xzzd').show();
  456. } else {
  457. $('#wrapper1').css({
  458. bottom: '0px'
  459. });
  460. $('.xzzd').hide();
  461. }
  462. myScroll.refresh();
  463. mui.toast("已结束该咨询");
  464. } else {
  465. mui.toast(res.msg)
  466. }
  467. })
  468. }
  469. }).showModal()
  470. }
  471. window.addEventListener('getMember', function(e) {
  472. if(e.detail.group2)
  473. consultInfo.group2 = e.detail.group2;
  474. });
  475. $('#contain').on('tap', '.qiuzhu5', function() {
  476. var code = $(this).attr('data-code');
  477. mui.openWindow('../../message/html/p2p.html', 'p2p', {
  478. extras: {
  479. otherCode: code,
  480. otherName: $(this).attr('data-name')
  481. }
  482. });
  483. })
  484. $('.xzzd').on('tap', function() {
  485. // mui.openWindow('../../hzzd/html/xinzengzhidao.html', 'jkzd', {
  486. // extras: {
  487. // code: consultInfo.patient
  488. // }
  489. // });
  490. mui.openWindow("../../hzzd/html/guidance_list.html", 'jkzd', {
  491. extras: {
  492. code: otherCode
  493. }
  494. });
  495. })
  496. //增加监听,设置状态为已求助
  497. window.addEventListener('setAsk', function(e) {
  498. isYaoQingQk = e.detail.value;
  499. });