123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- var lastId = 0;
- var prevImage,
- offTop = 46,
- offBot = 0;
- var consultInfo;
- var isJieshuCaozuo = false;
- var notEndConsultId;
- var isNotQzQkys = false;
- var isYaoQingQk = true; //是否建管已邀请全科 true:已邀请 ;false:未邀请
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- $('#title').html(self.otherName);
- getMineInfo(); //初始化个人信息
- consultInfo = self.consultInfo;
- createSession(self.type, getMembersExt);
- prevImage = mui.previewImage();
- var opener = self.opener();
- if(opener && opener.id == "faqizixun") {
- mui.back = backToWebviewById("mingyizixunliebiao", false, function() {
- var mainWebview = plus.webview.getWebviewById("mingyizixunliebiao");
- mui.fire(mainWebview, "activeItem");
- });
- }else if(opener && (opener.id == "zixunxiangqing")) {
- var zxxq = plus.webview.getWebviewById("zixunxiangqing");
- zxxq.close('none');
- backToZdzx();
- } else if(opener && (opener.id == "zuyuanziliao")) {
- function closeOpener(cur) {
- if(cur.id != "xiaoxi.html" && cur.id != "main" && cur.id != "../../tuandui/html/tuandui.html" &&
- cur.id != "mine.html" && cur.id != "home1.html" && cur.id != "home2.html" && cur.id != "huanzhe.html") {
- var opener = cur.opener();
- cur.close();
- closeOpener(opener);
- }
- }
- mui.back = function() {
- closeOpener(self.opener());
- self.close();
- var mainWebview = plus.webview.getWebviewById("main");
- mui.fire(mainWebview, "activeXiaoxi");
- mainWebview.show();
- }
- } else {
- backToParent();
- }
- });
- function getMembersExt() {
- getMembers(function() {
- for(var k in members) {
- if(members[k].role == 1) { //全科还没有被邀请
- isNotQzQkys = true;
- isYaoQingQk = false; //未被邀请
- }
- }
- isSign();
- });
- }
- var qyRelation = 0;
- function isSign() {
- sendPost("doctor/family_contract/doctor_patient_sign_exist", {
- doctor: docInfo.code,
- patient: otherCode
- }, null, function(res) {
- if(res.status == 200) {
- if(res.data.status != -1 && res.data.status != 0) {
- //没有签约关系
- qyRelation = 1;
- }
- consultInfo ? initPage() : getConsultInfo();
- } else {
- mui.toast("获取签约关系失败!");
- }
- })
- }
- function backToZdzx() {
- var old_back = mui.back;
- mui.back = function() {
- if(isJieshuCaozuo) {
- wv = plus.webview.getWebviewById("zixunjilu");
- if(wv) {
- wv.reload(true);
- }
- }
- var wv = plus.webview.getWebviewById("zhidingzixun");
- if(wv) {
- mui.fire(wv, "refresh");
- }
- old_back();
- }
- }
- //标签数目影响的轮播事件
- function bindSlider() {
- $('.notmy').hide();
- $('#muiSliderIndicator').hide();
- $('.mui-slider-group').removeClass('.mui-slider-group');
- var slider = mui('#other_div').slider();
- slider.stopped = true; //关闭滑动切换
- }
- /**
- * 获取咨询信息
- */
- function getConsultInfo() {
- plus.nativeUI.showWaiting();
- imClient.Sessions.isTopicEnded(sessionId, "current", function(res) {
- if(isEmptyObject(res)) { //患者和医生建立了会话,但是患者没有发送任何咨询信息
- $('#input_div').hide();
- consultInfo = {
- patient: otherCode
- }
- //getNewMsgs(true);
- if(!observer) {
- $('#wrapper1').css({
- top: '16px',
- bottom: '52px'
- });
- $('.xzzd').show();
- } else {
- $('#wrapper1').css({
- top: '16px',
- bottom: '0px'
- });
- $('.xzzd').hide();
- }
- getFirstMsgs();
- } else {
- if(res.status == 10) { //咨询已结束
- if(qyRelation == 1 && !observer) {
- $('#wrapper1').css({
- top: '16px',
- bottom: '52px'
- });
- $('.xzzd').show();
- } else {
- $('#wrapper1').css({
- top: '16px',
- bottom: '0px'
- });
- $('.xzzd').hide();
- }
- $('#input_div').hide();
- consultInfo = {
- patient: otherCode
- }
- //getNewMsgs(true);
- getFirstMsgs();
- } else { //咨询未结束
- $('#wrapper1').css('bottom', '52px');
- offBot = 52;
- if(myScroll) myScroll.refresh();
- notEndConsultId = res.id;
- $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
- sendPost("/doctor/talkgroup/getConsultByGroupCode", {
- consultCode: res.id
- }, null, function(res) {
- console.log(JSON.stringify(res))
- consultInfo = res.data;
- if(consultInfo) {
- if(consultInfo.type == 7 || consultInfo.type == 6) {
- bindSlider()
- }
- }
- //getNewMsgs(true);
- getFirstMsgs();
- // PDZiXuanLieXing();
- })
- }
- }
- plus.nativeUI.closeWaiting();
- }, function(res) {
- plus.nativeUI.closeWaiting();
- mui.toast("判断是否存在未结束咨询失败")
- })
- }
- //判断object是否为空
- function isEmptyObject(e) {
- var t;
- for(t in e)
- return !1;
- return !0
- }
- /**
- * 初始化页面
- */
- function initPage() {
- if(consultInfo.type == 7 || consultInfo.type == 6) {
- bindSlider()
- }
- console.log(docInfo.code)
- console.log(consultInfo.patient)
- sendPost("/doctor/consult/is_consult_unfinished", {//?
- doctor: docInfo.code,
- patient: consultInfo.patient
- }, undefined,
- function(res) {
- console.log(res)
- if(res.status == 200) {
- consultInfo.hasOver = res.data;
- if(res.data != "") { //咨询未结束
- notEndConsultId = res.data;
- $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
- $('#wrapper1').css('bottom', '52px');
- offBot = 52;
- if(myScroll) myScroll.refresh();
- PDZiXuanLieXing();
- } else { //咨询已结束
- if(qyRelation == 1 && !observer) {
- $('#wrapper1').css({
- top: '16px',
- bottom: '52px'
- });
- $('.xzzd').show();
- } else {
- $('#wrapper1').css({
- top: '16px',
- bottom: '0px'
- });
- $('.xzzd').hide();
- }
- $('#input_div').hide();
- }
- //getNewMsgs(true);
- getFirstMsgs();
- } else {
- mui.toast("获取信息失败");
- }
- }
- )
- }
- /**
- * 点击查看好友详细信息
- */
- $('#qun_detail').on("tap", function() {
- mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', {
- extras: {
- patiCode: consultInfo.patient
- }
- });
- })
- /**
- * 获取聊天图片列表
- */
- function getImgMsgList(handle) {
- im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) {
- console.log("imgs:" + JSON.stringify(data));
- chatCache.imgs = data.records.reverse();
- appendPrevImgs(chatCache.imgs);
- if(handle) handle(data);
- }, 2);
- }
- /**
- * 发送消息
- */
- function uploadMsg(type, content, locSrc, isNotSend, callBack) {
- service.isConsultFinished(notEndConsultId, function(res) {
- if(res.data == 0) {
- //作用: 更新咨询状态
- // sendPost("doctor/consult/reply", {
- // patient: otherCode,
- // consult: consultInfo.consult,
- // type: type,
- // content: content
- // }, null, function(res) {
- //
- // })
- uploadMsgBase(type, content, locSrc, isNotSend, callBack);
- } else if(res == "timeout" && type == 1) {
- var tim = new Date().getTime();
- var id = "loc" + tim;
- var d = [{
- "sender_id": docInfo.code,
- "sender_name": docInfo.name,
- "content_type": 1,
- "content": content,
- "timestamp": tim,
- "id": id,
- local_src: "",
- beforeSend: true
- }];
- showMsg(d, false, false, true);
- addMsgToCache(d, true);
- $('#contain dl[data-code="' + id + '"]').find('.c-msg').prepend("<i data-info='" + JSON.stringify(d[0]) + "' class='c-tips'></i>");
- } else {
- $('.topmsg').hide();
- if(qyRelation == 1 && !observer) {
- $('#wrapper1').css({
- top: '16px',
- bottom: '52px'
- });
- $('.xzzd').show();
- } else {
- $('#wrapper1').css({
- top: '16px',
- bottom: '0px'
- });
- $('.xzzd').hide();
- }
- $('#input_div').hide();
- myScroll.refresh();
- }
- })
- }
- /**
- * 代预约
- */
- function dyyjl() {
- mui.openWindow('../../wdyy/html/appointment-register.html', 'appointment-register', {
- extras: {
- patient: consultInfo.patient
- }
- });
- }
- /**
- * 健康教育
- */
- function jkjy() {
- // mui.openWindow('../../jkjy/html/jiankangjiaoyu.html', 'jiankangjiaoyu', {
- mui.openWindow('../../jkjy/html/article-store.html', 'jiankangjiaoyu', {
- extras: {
- patient: consultInfo.patient,
- patientName: consultInfo.name
- }
- });
- }
- /**
- * 健康指导
- */
- function jkzd() {
- mui.openWindow('../../hzzd/html/guidance_list.html', 'jkzd', {
- extras: {
- code: otherCode
- }
- });
- }
- /**
- * 临时随访
- */
- function lssf() {
- var url = "../../suifang/html/choose_suifang.html";
- mui.openWindow(url, 'choose_suifang', {
- extras: {
- patiCode: otherCode
- }
- });
- }
- //判断咨询类型各种情况
- var quankeCode = ""; //全科code
- var jianguanCode = ""; //建管code
- function PDZiXuanLieXing() {
- if(self.type != "1") { // 家庭医生咨询或三师咨询才能请求doctor/family_contract/patient_team_doctors接口
- return ;
- }
- sendPost("/doctor/family_contract/patient_team_doctors", {
- sessionId: self.sessionId
- }, null, function(res) {
- // console.error(JSON.stringify(res))
- if(res.status == 200) {
- var curConsultType = consultInfo.type; //当前的咨询类型 1:三师签约 2:家庭签约
- var curDoctorCode = docInfo.code;
- var data = res.data;
- var qianyueData = null;
- if(curConsultType == 1) { //三师签约
- qianyueData = data.ssSign;
- } else if(curConsultType == 2) { //家庭签约
- qianyueData = data.jtSign;
- }
- if(qianyueData) {
- quankeCode = qianyueData.doctor.doctor;
- jianguanCode = qianyueData.doctorHealth.doctor;
- }
- //当前医生既是全科,也是建管:显示求助专科
- if(curDoctorCode == jianguanCode && curDoctorCode == quankeCode) {
- $("#qiuzhuico p").html("求助");
- }
- //当前医生是建管,不是全科:显示邀请全科
- else if(curDoctorCode == jianguanCode && curDoctorCode != quankeCode) {
- $("#qiuzhuico p").html("邀请全科");
- }
- //当前医生不是建管,是全科:显示求助专科
- else if(curDoctorCode != jianguanCode && curDoctorCode == quankeCode) {
- $("#qiuzhuico p").html("求助");
- }
- } else {
- mui.toast("获取患者和医生咨询类型失败!");
- }
- })
- }
- /**
- * 求助/邀请全科
- */
- function qiuzhu() {
- plus.nativeUI.showWaiting();
- if($("#qiuzhuico p").html() == "邀请全科") {
- if(isYaoQingQk) { //已邀请全科
- mui.toast("已邀请全科");
- plus.nativeUI.closeWaiting();
- } else { //去邀请全科
- var userAgent = plus.storage.getItem("userAgent");
- //记录观察者模式
- if(JSON.parse(userAgent).teamCode == "1"){
- mui.toast("观察者模式无法进行增删改操作");
- plus.nativeUI.closeWaiting();
- return;
- }
- imClient.Sessions.addParticipant(sessionId, quankeCode, function(res) {
- mui.toast("邀请成功!");
- isYaoQingQk = true;
- imClient.Sessions.sendMessage(sessionId, docInfo.code, "系统", docInfo.name + "已邀请全科医生一起参与咨询", 13,
- function(data) {
- showMsg(data.messages, false, false, true);
- plus.nativeUI.closeWaiting();
- },
- function(data) {
- console.log("sendFail" + JSON.stringify(data));
- })
- }, function(res) {
- console.error(JSON.stringify(res));
- mui.toast('邀请失败,请稍后重试!');
- })
- }
- } else { //求助医生
- mui.openWindow('../../qzys/html/select_doctor.html', 'qzys-select_doctor', {
- extras: {
- consultInfo: consultInfo,
- sessionId:self.sessionId,
- accessData: {
- consultCode: consultInfo.consult,
- patient: consultInfo.patient
- }
- }
- });
- }
- }
- function jieshu() {
- dialog({
- content: '<div><div class="c-f16 c-333">结束咨询后,居民及医生均无法再次回复,是否确认继续结束?</div></div>',
- okValue: '继续结束',
- cancelValue: '我再看看',
- cancel: function () {
- return;
- },
- ok: function() {
- sendPost("doctor/consult/finish_consult", {
- consult: notEndConsultId
- }, null, function(res) {
- if(res.status == 200) {
- isJieshuCaozuo = true;
- $('.topmsg').html("咨询求助已结束");
- $('#input_div').hide();
- if(qyRelation == 1 && !observer) {
- $('#wrapper1').css({
- bottom: '52px'
- });
- $('.xzzd').show();
- } else {
- $('#wrapper1').css({
- bottom: '0px'
- });
- $('.xzzd').hide();
- }
- myScroll.refresh();
- mui.toast("已结束该咨询");
- } else {
- mui.toast(res.msg)
- }
- })
- }
- }).showModal()
- }
- window.addEventListener('getMember', function(e) {
- if(e.detail.group2)
- consultInfo.group2 = e.detail.group2;
- });
- $('#contain').on('tap', '.qiuzhu5', function() {
- var code = $(this).attr('data-code');
- mui.openWindow('../../message/html/p2p.html', 'p2p', {
- extras: {
- otherCode: code,
- otherName: $(this).attr('data-name')
- }
- });
- })
- $('.xzzd').on('tap', function() {
- mui.openWindow("../../hzzd/html/guidance_list.html", 'jkzd', {
- extras: {
- code: otherCode
- }
- });
- })
- //增加监听,设置状态为已求助
- window.addEventListener('setAsk', function(e) {
- isYaoQingQk = e.detail.value;
- })
|