p2dzixun.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. mui.openWindow('../../jkjy/html/article-store.html', 'jiankangjiaoyu', {
  318. extras: {
  319. patient: consultInfo.patient,
  320. patientName: consultInfo.name
  321. }
  322. });
  323. }
  324. /**
  325. * 健康指导
  326. */
  327. function jkzd() {
  328. mui.openWindow('../../hzzd/html/guidance_list.html', 'jkzd', {
  329. extras: {
  330. code: otherCode
  331. }
  332. });
  333. }
  334. /**
  335. * 临时随访
  336. */
  337. function lssf() {
  338. var url = "../../suifang/html/choose_suifang.html";
  339. mui.openWindow(url, 'choose_suifang', {
  340. extras: {
  341. patiCode: otherCode
  342. }
  343. });
  344. }
  345. //判断咨询类型各种情况
  346. var quankeCode = ""; //全科code
  347. var jianguanCode = ""; //建管code
  348. function PDZiXuanLieXing() {
  349. if(self.type != "1") { // 家庭医生咨询或三师咨询才能请求doctor/family_contract/patient_team_doctors接口
  350. return ;
  351. }
  352. sendPost("/doctor/family_contract/patient_team_doctors", {
  353. sessionId: self.sessionId
  354. }, null, function(res) {
  355. // console.error(JSON.stringify(res))
  356. if(res.status == 200) {
  357. var curConsultType = consultInfo.type; //当前的咨询类型 1:三师签约 2:家庭签约
  358. var curDoctorCode = docInfo.code;
  359. var data = res.data;
  360. var qianyueData = null;
  361. if(curConsultType == 1) { //三师签约
  362. qianyueData = data.ssSign;
  363. } else if(curConsultType == 2) { //家庭签约
  364. qianyueData = data.jtSign;
  365. }
  366. if(qianyueData) {
  367. quankeCode = qianyueData.doctor.doctor;
  368. jianguanCode = qianyueData.doctorHealth.doctor;
  369. }
  370. //当前医生既是全科,也是建管:显示求助专科
  371. if(curDoctorCode == jianguanCode && curDoctorCode == quankeCode) {
  372. $("#qiuzhuico p").html("求助");
  373. }
  374. //当前医生是建管,不是全科:显示邀请全科
  375. else if(curDoctorCode == jianguanCode && curDoctorCode != quankeCode) {
  376. $("#qiuzhuico p").html("邀请全科");
  377. }
  378. //当前医生不是建管,是全科:显示求助专科
  379. else if(curDoctorCode != jianguanCode && curDoctorCode == quankeCode) {
  380. $("#qiuzhuico p").html("求助");
  381. }
  382. } else {
  383. mui.toast("获取患者和医生咨询类型失败!");
  384. }
  385. })
  386. }
  387. /**
  388. * 求助/邀请全科
  389. */
  390. function qiuzhu() {
  391. plus.nativeUI.showWaiting();
  392. if($("#qiuzhuico p").html() == "邀请全科") {
  393. if(isYaoQingQk) { //已邀请全科
  394. mui.toast("已邀请全科");
  395. plus.nativeUI.closeWaiting();
  396. } else { //去邀请全科
  397. var userAgent = plus.storage.getItem("userAgent");
  398. //记录观察者模式
  399. if(JSON.parse(userAgent).teamCode == "1"){
  400. mui.toast("观察者模式无法进行增删改操作");
  401. plus.nativeUI.closeWaiting();
  402. return;
  403. }
  404. imClient.Sessions.addParticipant(sessionId, quankeCode, function(res) {
  405. mui.toast("邀请成功!");
  406. isYaoQingQk = true;
  407. imClient.Sessions.sendMessage(sessionId, docInfo.code, "系统", docInfo.name + "已邀请全科医生一起参与咨询", 13,
  408. function(data) {
  409. showMsg(data.messages, false, false, true);
  410. plus.nativeUI.closeWaiting();
  411. },
  412. function(data) {
  413. console.log("sendFail" + JSON.stringify(data));
  414. })
  415. }, function(res) {
  416. console.error(JSON.stringify(res));
  417. mui.toast('邀请失败,请稍后重试!');
  418. })
  419. }
  420. } else { //求助医生
  421. mui.openWindow('../../qzys/html/select_doctor.html', 'qzys-select_doctor', {
  422. extras: {
  423. consultInfo: consultInfo,
  424. sessionId:self.sessionId,
  425. accessData: {
  426. consultCode: consultInfo.consult,
  427. patient: consultInfo.patient
  428. }
  429. }
  430. });
  431. }
  432. }
  433. function jieshu() {
  434. dialog({
  435. content: '<div><div class="c-f16 c-333">结束咨询后,居民及医生均无法再次回复,是否确认继续结束?</div></div>',
  436. okValue: '继续结束',
  437. cancelValue: '我再看看',
  438. cancel: function () {
  439. return;
  440. },
  441. ok: function() {
  442. sendPost("doctor/consult/finish_consult", {
  443. consult: notEndConsultId
  444. }, null, function(res) {
  445. if(res.status == 200) {
  446. isJieshuCaozuo = true;
  447. $('.topmsg').html("咨询求助已结束");
  448. $('#input_div').hide();
  449. if(qyRelation == 1 && !observer) {
  450. $('#wrapper1').css({
  451. bottom: '52px'
  452. });
  453. $('.xzzd').show();
  454. } else {
  455. $('#wrapper1').css({
  456. bottom: '0px'
  457. });
  458. $('.xzzd').hide();
  459. }
  460. myScroll.refresh();
  461. mui.toast("已结束该咨询");
  462. } else {
  463. mui.toast(res.msg)
  464. }
  465. })
  466. }
  467. }).showModal()
  468. }
  469. window.addEventListener('getMember', function(e) {
  470. if(e.detail.group2)
  471. consultInfo.group2 = e.detail.group2;
  472. });
  473. $('#contain').on('tap', '.qiuzhu5', function() {
  474. var code = $(this).attr('data-code');
  475. mui.openWindow('../../message/html/p2p.html', 'p2p', {
  476. extras: {
  477. otherCode: code,
  478. otherName: $(this).attr('data-name')
  479. }
  480. });
  481. })
  482. $('.xzzd').on('tap', function() {
  483. mui.openWindow("../../hzzd/html/guidance_list.html", 'jkzd', {
  484. extras: {
  485. code: otherCode
  486. }
  487. });
  488. })
  489. //增加监听,设置状态为已求助
  490. window.addEventListener('setAsk', function(e) {
  491. isYaoQingQk = e.detail.value;
  492. })