1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213 |
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
- var dialroll;
- var doctorInfo;
- var content = "";
- var timeStr = "";
- var id = 1;
- var pagesize = 100;
- var Request = new Object();
- Request = GetRequest();
- var consult = Request["consult"];
- var status = Request["status"];
- var consultType = Request["type"]; //咨询类型,1-三师咨询,2-家庭咨询, 6-名医咨询, 8-续方咨询
- var doctor = Request['doctor'];
- var toUser = Request["toUser"];
- var toName = decodeURIComponent(Request["toName"]);
- var openid = Request["openid"];
- var represented = Request["represented"];
- var evaluate = localStorage.getItem("evaluate");//1为有评价 0为无评价
- var prescriptionCode;
- var docMsg = 0;
- var patientcode = '';
- var networkStatus = "";
- var userAgent = window.localStorage.getItem(agentName);
- var userInfo = JSON.parse(window.localStorage.getItem(agentName));
- //回复单条内容填写
- var defaultPhoto = "../../../images/p-default.png";
- var doctorDefaultPhoto = "../../../images/d-default.png";
- var presciptionStatus = 0; //标记续方状态
- mui.init({
- gestureConfig:{
- hold:true,//默认为false,不监听
- release:true//默认为false,不监听
- }
- });
- //页面初始化
- $(function(){
- isRepresent(function(){
- pageInit();
- })
- })
- function pageInit(){
- patientcode = userInfo.represented ? userInfo.represented : userInfo.uid;
- createSocketConnect();
- checkStatus();
- getPrescriptionDetail();
-
- getWXSign();
- bindEvents();
- }
- //im建立socket连接
- function createSocketConnect(){
- //获取sessionId
- sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed, function(res){
- if(res.status==200){
- var sessionId = JSON.parse(res.msg)[0].session_id;
- //登录IM
- sendPost('/patient/consult/intoTopic', {consult: consult}, 'json', 'get', queryFailed, function(res){});
- //加载socket组件
- jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
- var socket = io.connect(imurl);
- var userInfo = JSON.parse(window.localStorage.getItem(agentName));
- var uid = userInfo.represented ? userInfo.represented : userInfo.uid;
- socket.emit('login', {
- userId: uid,
- password: uid,
- sessionId:sessionId,
- clientType:"patient"
- });
- socket.on('message', function (data) {
- console.log(data)
- if((data.type == 1) ||(data.type == 2) || (data.type == 6) || (data.type == 12) || (data.type == 7) || (data.type == 15)){
- addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },300)
- }
- if((data.type == 16)||(data.type == 17)){
- if(data.sender_id == patientcode){
- addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
- }else{
- addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
- }
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },300)
- }
- });
- socket.on('error', function (data) {
- });
- socket.on('ack', function (data) {
- });
- // function getLocalTime(nS) {
- // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
- // }
- }).fail(function() {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
- });
- }
- });
- }
- //判断咨询记录的状态
- function checkStatus(){
- d.show();
- var url = 'patient/consult/status',
- data = {consult: consult};
- sendPost(url, data, 'json', 'get', queryFailed, queryStatusSuccess);
- }
- //获取咨询状态成功回调处理
- function queryStatusSuccess(res){
- if(res.status == 200) {
- if(res.data == 0){ //咨询未结束
- $("#divBottom").show();
- $("#finish_list").show();
- $("#input_div").show();
- winSize(165); // 110+55
- }else{ //咨询已结束
- $("#divBottom").hide();
- $("#finish_list").hide();
- $("#input_div").hide();
- winSize(75);
- //显示评价按钮
- if(evaluate == 0){
- $('#valFoot').show();
- $('#noval').show();
- $('#hasval').hide();
- }else if(evaluate == 1){
- $('#valFoot').show();
- $('#noval').hide();
- $('#hasval').show();
- }
- }
- status = res.data;
- //聊天记录填充
- queryList();
- var pulldownAction = function() {
- getPage(this);
- };
- dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
-
- d.close();
- } else {
- queryFailed(res);
- }
- }
- //获得续方详情
- function getPrescriptionDetail(){
- var url = "/patient/consult/prescriptionDetail",
- params = {consult: consult};
- sendPost(url, params, 'json', 'get', queryFailed, function(res){
- if(res.status == 200){
- res.data.statusName = getStatusName(res.data.status);
- presciptionStatus = res.data.status;
- var html = template('prescription_tmp', res.data);
- $("#prescriptionInfo").empty().append(html);
- $("#prescriptionInfo").attr("data-code", res.data.code);
- prescriptionCode = res.data.code;
- }else{
- queryFailed(res);
- }
- });
- }
- //查询咨询记录
- function queryList(){
- var url = 'patient/consult/loglist',
- data = {
- consult: consult,
- page: id,
- pagesize: pagesize
- };
-
- sendPost(url, data, 'json', 'GET', queryFailed, queryListSuccess);
- }
- //查询咨询记录成功的回调处理
- function queryListSuccess(res){
- if (res.status == 200) {
- id++;
- var data = res.list;
- var docCode;
- for(var k in data.users){
- if(data.users[k].is_patient == 0){
- docCode = data.users[k].id;
- }
- }
- var list = data.list;
- if (list && list.length > 0) {
- docMsg = list[list.length - 1].content_type;
- for (var j = list.length-1; j >=0; j--) {
- var reply = JSON.parse(list[j]);
- // console.log(reply)
- // TODO 判断咨询回复的类型,区别是否显示在患者端
- if((reply.content_type == 3) || (reply.content_type == 1) || (reply.content_type == 2) || (reply.content_type == 6) || (reply.content_type == 12) || (reply.content_type == 7)|| (reply.content_type == 15)|| (reply.content_type == 16)|| (reply.content_type == 17)){
- var date = new Date();
- date.setTime(reply.timestamp);
- var time = date.format('yyyy-MM-dd hh:mm:ss');
- var p;
-
- for(var k in data.users){
- if(data.users[k].id==reply.sender_id){
- p = data.users[k].avatar;
- }
- }
- var isSystem = reply.sender_id == 'system';
- //第一个参数为1时,医生发的
- addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p, false, isSystem);
- }
- }
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- }
- if(status==0){
- checkDoctorInWork(docCode);
- }
- d.close();
- }
- else{
- queryFailed(res);
- }
- }
- //判断医生是否在工作时间内
- function checkDoctorInWork(doctor){
- var url = 'patient/consult/is_doctor_working';
- sendPost(url, {doctor:doctor}, 'json', 'post', queryFailed, function(res){
- if(res.status==200){
- if(res.data!=1){
- var time = (new Date()).Format('yyyy-MM-dd hh:mm:ss');
- addReply(1, "医生不在工作时间,无法及时回复您的消息。<br/><a class='workhours' href='#'>查看工作时间!</a>", time, 7, "系统消息");
-
- $(".workhours").on("click",function(){
- location.href='doctor-work-hours.html?doctor='+doctor;
- });
-
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },20);
- }
- }else{
- queryFailed(res);
- }
- });
- }
- function queryFailed(res, msg){
- d.close();
- dd.close();
- if(msg){
- dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content: msg}).show();
- }else{
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'加载失败'}).show();
- }
- }
- }
- //点击发送按钮事件
- function send(){
- content = $("#input_content").text().replace(/\s+/g,"");
- if (content && content != null && content != "") {
- var now = new Date(),
- timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
-
- $("#input_content").blur();
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
-
- dd.showModal();
- var url = "patient/consult/append",
- data = {
- consult: consult,
- content: utf16toEntities(content),
- type: 1
- };
- sendPost(url, data, 'json', 'post', function(res){
- queryFailed(res, '发送失败');
- }, submitSuccess);
-
- } else {
- return;
- }
- }
- //发送文本消息成功回调
- function submitSuccess(res){
- if (res.status == 200) {
- //置空
- $("#input_content").text("");
- $(".talk-send a").addClass("disab");
- addReply(2, content, timeStr, 1, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- showSendBtn(false);
- dd.close();
- } else {
- queryFailed(res, '发送失败');
- }
- }
- /**
- * 组装信息
- * @param {number} type 消息是本人发送还是他们发送, 1-医生发送,2-自己发送
- * @param {string} content 消息内容
- * @param {string} time 时间
- * @param {string} msgType 消息类型
- * @param {string} doctorName
- * @param {string} photo 头像图片路径
- * @param {boolean} prepend 消息是否往前添加
- */
- function addReply(type, content, time, msgType, doctorName, photo, prepend, isSystem){
- //time = time.substr(10);
- var $div = $("<dl></dl>");
-
- if(msgType == 7){
- if(msgType == 7 && isSystem){
- content = "您24小时内未回复,系统自动结束咨询";
- }
- // if(msgType == 1){
- // var content1 = '您未绑定智能设备,请手动上传体征数据,绑定设备后系统将会自动将您的体征数据上报给医生<br><a href="javascript:;" class="add-equip">点击绑定</a>';
- // if(prepend){
- // $(".talk-box").prepend('<div class="time-tips"><span class="">' + content1 + '</span></div>');
- // } else{
- // $(".talk-box").append('<div class="time-tips"><span class="">' + content1 + '</span></div>');
- // }
- // return;
- // }
- if(prepend){
- $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
- } else
- $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
- return;
- }
-
- if (type == 1) {
- $div.addClass('chat-left');
- img = photo ? getImgUrl(photo) : doctorDefaultPhoto;
- doctorDefaultPhoto = img;
- name = doctorName;
- } else {
- $div.addClass('chat-right');
- img = photo ? getImgUrl(photo) : defaultPhoto;
- defaultPhoto = img;
- name = window.localStorage.getItem("nowPatientName");
- }
-
- var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
- '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
-
- switch(parseInt(msgType)) {
- case 1://信息
- temp += '<dd class="word-bread"><span>' + content + '</span></dd></dl>';
- break;
- case 6://咨询问题
- var rs = JSON.parse(content);
- var tzMsg = rs.tzMsg;
- temp += '<dd class="word-bread sys-msg">'+
- '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
- '<p class="c-333 c-f14">' + rs.title + '</p>'+
- '<p class="c-333 c-f14">体征信息:'+tzMsg+'</p>'+
- '</dd></dl>';
- break;
- case 2://图片
- temp += '<dd class="word-bread wb-img"><img width="100" height="100" src="'+ getImgUrl(content) +'" /></dd></dl>';
- break;
- case 3://语音
- var rec = JSON.parse(content);
- temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + getImgUrl(content) + "'>"+
- "<div class='soundWav'>" +
- "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
- "</div>"+
- "</dd></div>";
- break;
- case 12://视频
- var videoInfo = content.split(",");
- var shichang = formatSeconds(videoInfo[2]);//时长
- if(type == 1){
- temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
- '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
- '<img class="bofang-icon-left" src="../images/bofang_icon.png">'+
- '<img class="jianjiao-icon-left" src="../images/zuoshanjiao_bg.png">'+
- '<span class="shichang-time-left">'+shichang+'</span>'+
- '</dd>';
- }else{
- temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
- '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
- '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
- '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
- '<span class="shichang-time-right">'+shichang+'</span>'+
- '</dd>';
- }
- break;
- case 15:
- var rs = JSON.parse(content);
- var reason = "";
- if(rs.reason){
- reason = '<p class="c-333 c-f14">原因:'+rs.reason+'</p>';
- }
- temp += '<dd class="word-bread sys-msg">'+
- '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
- '<p class="c-333 c-f14">审核消息:</p>'+
- '<p class="c-333 c-f14">' + rs.title + '</p>'+
- '<p class="c-333 c-f14">审核结果:'+rs.result+'</p>'+reason+
- '<a href="javascript:void(0);" class="view-detail c-f14">点此查看详情</a>'+
- '</dd>';
- break;
- case 16:
- var rs = JSON.parse(content);
- if(type == 2){
- var bttn="";
- if(rs.needUpload == 'true'){
- if(rs.type == 1){
- bttn = ' <a href="javascript:void(0);" class="add-xy c-f14">上传血压数据</a>'
- }else{
- bttn = ' <a href="javascript:void(0);" class="add-xt c-f14">上传血糖数据</a>'
- }
- temp += '<dd class="word-bread sys-msg">'+
- '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
- '<p class="c-333 c-f14">'+rs.patientAlert+bttn+'</p>'+
- '</dd></div>';
- }else{
- temp += '<dd class="word-bread sys-msg">'+
- '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
- '<p class="c-333 c-f14">'+rs.tzMsg+'</p>'+
- '<p class="c-333 c-f14">'+rs.tzTime+'</p>'+
- '</dd></div>';
- }
- break;
- }else{
- var dev="";
- if(rs.deviceMsg){
- dev = '<p class="c-999 c-f12">'+rs.deviceMsg+' <a href="javascript:void(0);" class="add-equip c-f14">点击绑定</a></p>'
- }
- temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
- '<p class="c-333 c-f15">'+rs.text+'</p>'+dev+
- '</div></dd>';
- }
- break;
- case 17://随访调查
- var rs = JSON.parse(content);
- if(type==2){
- if(rs.sysMsg){
- temp += '<dd class="word-bread sys-msg">'+
- '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
- '<p class="c-f14 c-333">'+rs.text+
- ' <a href="javascript:void(0);" data-type="'+rs.msgType+'" class="survey c-f14">查看</a></p>'+
- '</dd></div>';
- }
- }else{
- temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
- '<p class="c-333 c-f15">'+rs.text+' <a href="javascript:void(0);" data-type="'+rs.msgType+'" class="survey c-f14">开始填写</a></p>'+
- '</div></dd><p class="xf-notice">'+rs.patientremind+'</p>';
- }
- break;
- }
-
- if(prepend){
- $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
- } else
- $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
-
- if(type != null && type != 1) {
- $(".tw-add-detail").hide(200);
- }
- }
- //下拉刷新加载数据方法
- function getPage(t){
- var url = 'patient/consult/loglist',
- data = {
- consult: consult,
- page: id,
- pagesize: pagesize
- };
-
- sendPost(url, data, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- var list = res.list;
- if (list && list.length > 0) {
- id = list[list.length - 1].id;
- for (var j = 0; j < list.length; j++) {
- var reply = list[j];
- if((reply.msgType == 1) || (reply.msgType == 3) || (reply.msgType == 2) || (reply.msgType == 6) || (reply.msgType == 12) || (reply.msgType == 7) || (reply.msgType == 15)){
- //type为1时,医生发的
- var type = (reply.sender_id==patientcode) ? 2 : 1;
- var isSystem = reply.sender_id == 'system';
- addReply(type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo, true, isSystem);
- }
- }
- }
- t.refresh();
- }else{
- queryFailed(res);
- }
- });
- }
- //结束咨询方法
- function finish(){
- //先判断是否可以结束咨询,续方申请状态为待审核时,不可以结束咨询
- if((presciptionStatus >= 0) && (presciptionStatus < 21)){
- dialog({
- contentType:'tipsbox',
- content: '续方申请未审核,不可关闭续方咨询',
- skin: 'bk-popup',
- closeTime: 2000
- }).show();
- return false;
- }
- dialog({
- content:'是否确认结束该次咨询?结束后医生将无法回复',
- ok: function (){
- var params = {}
- params.code = consult;
- //发送ajax请求, 查询设备列表信息
- sendPost("patient/consult/finish", params, "json", "post", function(res){
- queryFailed(res, '操作失败');
- },function(res){
- if (res.status == 200) {
- location.reload();
- }
- else{
- queryFailed(res, '操作失败');
- }
- });
- },
- cancel: function () {
- return;
- }
- }).showModal();
- }
- /*--------------------------- 事件监听 ------------------------------------*/
- function bindEvents(){
- //点击续方卡片,跳转去续方记录页面
- $("#prescriptionInfo").on('click', function(){
- var code = $(this).attr("data-code");
- window.location.href = "../../prescription/html/re-prescription_info.html?code="+code+'&toUser='+toUser;
- });
-
- //点击内容区域输入框失焦
- $('#talkwrap').click(function(){
- $("#input_content").blur();
- // dialroll.refresh();
- // dialroll.scrollTo(0, dialroll.maxScrollY);
- return false;
- });
-
- //发送以后定位至最底部
- $("#reply a").click(function() {
- send();
- });
-
- //立即发送
- $("#lijifasong").on("tap", function(){
- uploadVideo();
- mui('#sheet1').popover('toggle');
- return false;
- });
-
- //不再提醒
- $("#buzaitixing").on("tap", function(){
- window.localStorage.setItem("isTiXingVideoFaSong","1");
- uploadVideo();
- mui('#sheet1').popover('toggle');
- return false;
- });
-
- //查看续方详情
- $("body").on("tap", '.view-detail', function(){
- window.location.href = "../../prescription/html/re-prescription_info.html?code="+prescriptionCode+'&toUser='+toUser;
- })
- //调查问卷
- $("body").on("tap", '.survey', function(){
- var $this = $(this)
- window.location.href = "questionaires.html?prescriptionCode="+prescriptionCode+"&pro_id="+$this.attr('data-type')
- })
- $("body").on("tap", '.view-check', function(){
- window.location.href = "questionaires.html?prescriptionCode="+prescriptionCode+"&pro_id=2"
- })
- //血压血糖
- $("body").on("tap", '.j-btn', function(){
- window.location.href = "../../jkjl/html/health-index-add-bloodpressure.html?origin=suifang&prescriptionCode="+prescriptionCode
- })
- $("body").on("tap", '.add-xt', function(){
- window.location.href = "../../jkjl/html/health-index-add-bloodsugar.html?origin=suifang&prescriptionCode="+prescriptionCode
- })
- $("body").on("tap", '.add-xy', function(){
- window.location.href = "../../jkjl/html/health-index-add-bloodpressure.html?origin=suifang&prescriptionCode="+prescriptionCode
- })
- //添加设备
- $("body").on("tap", '.add-equip', function(){
- window.location.href = "../../wdsb/html/my-equipments.html?prescriptionCode="+prescriptionCode
- })
- //点击评价
- $('body').on('tap','#noval',function(){
- window.location.href = "manyidu.html?consult=" +consult;
- });
-
- $('body').on('tap','#hasval',function(){
- window.location.href = "manyidu.html?consult=" +consult;
- });
-
- var $ipt_content = $('#input_content');
- //键盘输入解决输入框被软键盘覆盖的问题
- var bfscrolltop = document.body.scrollTop;//获取软键盘唤起前浏览器滚动部分的高度
- var interval;
- $ipt_content.focus(function(){//当它获取焦点时触发事件
- $(".tw-add-detail").hide();
- interval = setInterval(function(){//设置一个计时器,时间设置与软键盘弹出所需时间相近
- document.body.scrollTop = document.body.scrollHeight;//获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
- },100)
- }).blur(function(){//设定输入框失去焦点时的事件
- clearInterval(interval);//清除计时器
- document.body.scrollTop = bfscrolltop; //将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
- });
- //显示发送按钮的事件
- $ipt_content.on('input', function(e){
- if($(this).prop('comstart')) {
- return;
- }
- var text = $.trim($(this).text());
- showSendBtn(text.length > 0)
-
- }).on('compositionstart', function(){
- $(this).prop('comstart', true);
- //console.log('中文输入:开始');
- }).on('compositionend', function(){
- $(this).prop('comstart', false);
- //console.log('中文输入:结束');
- var text = $.trim($(this).text());
- showSendBtn(text.length > 0)
- })
- .on('tap', function(){
- $(".tw-add-detail").hide();
- // $ipt_content.focus();
- })
-
- //附加功能
- $(".tw-add").click(function() {
- $(".tw-add-detail").toggle(200);
- });
- //隐藏打开的附加功能
- $('body').on('tap', '#talkwrap', function(){
- $('.tw-add-detail').hide();
- $ipt_content.blur();
- });
-
- $(".yy-add").click(function() {
- if($('#msg-sound:visible').length){
- $ipt_content.show();
- ui.boxMsgSound.style.display = 'none';
- $(this).find('img:eq(0)').show().next().hide();
- } else {
- $ipt_content.hide();
- ui.boxMsgSound.style.display = 'block';
- $(this).find('img:eq(0)').hide().next().show();
- }
- });
-
- //预览图片
- $('.talk-box').on('click', '.word-bread img', function(){
- if(!$(this).closest(".word-bread").hasClass("preview-video")){
- var urls = [];
- $.each($('.word-bread img'), function(i, v) {
- urls.push($(v).attr('src'));
- });
- wx.previewImage({
- current: $(this).attr('src'), // 当前显示图片的http链接
- urls: urls // 需要预览的图片http链接列表
- });
- }
- })
- //播放语音
- .on('touchstart', '.audio', function(){
- if($playingDom){
- aud.pause();
- //aud.stop();
- $playingDom.removeClass('active');
- if($playingDom[0] == this){
- $playingDom = null;
- return;
- }
- }
- $playingDom = $(this);
- $playingDom.addClass('active');
- var ser = JSON.parse($(this).attr('data-audio'));
- aud.src = getImgUrl(ser.path);
- aud.load();
- aud.play();
- })
- //播放视频
- .on('click','.preview-video',function() {
- $(document.body).find('video').remove();
- var url = $(this).attr('data-video');
- var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
- $(document.body).append(html);
- var video = $(document.body).find('video')[0];
- video.play();
- });
- }
- /*--------------------------- 事件监听 ------------------------------------*/
- /*--------------------------- 辅助方法 ------------------------------------*/
- //控制页面高度
- function winSize(h){
- var totH = $(window).height();
- $("#talkwrap").height(totH - h);
- if(h > 75){
- $(".c-main").css("top", '110px');
- }
- }
- //控制是否显示文本消息框
- function showSendBtn(isShow){
- if(isShow){
- $('.tw-add').hide();
- $('#reply').fadeIn('fast', 'swing');
- } else {
- $('#reply').fadeOut('fast', 'swing', function(){
- $('.tw-add').show();
- });
- }
- };
- //毫秒转换成时分秒
- function formatSeconds(value){
- var theTime = parseInt(value/1000);// 秒
- var theTime1 = 0;// 分
- var theTime2 = 0;// 小时
- if(theTime > 60) {
- theTime1 = parseInt(theTime/60);
- theTime = parseInt(theTime%60);
- if(theTime1 > 60) {
- theTime2 = parseInt(theTime1/60);
- theTime1 = parseInt(theTime1%60);
- }
- }
- var result = ""+parseInt(theTime);//秒
- if(parseInt(theTime)<=9){
- result = "0"+parseInt(theTime);//秒
- }
- if(theTime1 > 0) {//分
- if(parseInt(theTime1)>9){
- result = ""+parseInt(theTime1)+":"+result;
- }else{
- result = "0"+parseInt(theTime1)+":"+result;
- }
- }
- if(theTime2 > 0) {//小时
- if(parseInt(theTime2)>9){
- result = ""+parseInt(theTime2)+":"+result;
- }else{
- result = "0"+parseInt(theTime2)+":"+result;
- }
- }
- var resResult = "";
- if(result.split(":").length==1){//秒
- resResult = "00:"+result;
- }else if(result.split(":").length==2){//分
- resResult = "00:"+result;
- }else{//时
- resResult = result;
- }
- return resResult;
- }
- /*--------------------------- 辅助方法 ------------------------------------*/
-
- //-----------------------------【图片】处理方法-------------------------------------
- //微信上传图片
- var serverId = "";
- var images = [];
- //查看图片
- function viewImg(dom){
- var $img = $(dom);
- var thissrc = $img.attr("src");
- var mWid = $(window).width();
- var mHei = $(window).height();
- var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
- $("body").append(nHtml);
- $(".delimgpop").click(function() {
- $(this).remove()
- });
- }
- //微信选择图片
- function chooseImageWx(){
- wx.chooseImage({
- count: 3,
- success: function (res) {
- for (var i in res.localIds) {
- images.push(res.localIds[i]);
- }
- dd.showModal();
- uploadImage();
- }
- });
- }
- //上传图片到微信
- function uploadImage(){
- if (images.length == 0) {
- dd.close();
- return;
- }
- var i = 0, length = images.length;
- serverId = "";
- var faillength = 0 ;
- function upload() {
- wx.uploadImage({
- localId: images[i],
- isShowProgressTips: 0,
- success: function (res) {
- faillength= 0;
- i++;
- if(serverId.length == 0){
- serverId = res.serverId;
- }
- else{
- serverId =serverId + "," + res.serverId;
- }
- if (i < length) {
- upload();
- }
- if(i == images.length){
- sendImages();
- }
- },
- fail: function (res) {
- dd.close();
- faillength+=1;
- if(faillength<=5){
- //失败从传
- upload();
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
- }
- }
- });
- }
- upload();
- }
- //保存图片到后台
- function sendImages(){
- var now = new Date();
- timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
-
- var url = 'patient/consult/append'
- data = {
- consult: consult,
- content: '',
- mediaIds: serverId,
- type: 2,
- times: ''
- };
-
- sendPost(url, data, 'json', 'post', function(res){
- queryFailed(res, '发送失败');
- }, function(res){
- if (res.status == 200) {
- var data= JSON.parse(res.data)
- dd.close();
- addReply(2, data.content, timeStr, 2, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- queryFailed(res, '发送失败');
- }
- });
- }
- //-----------------------------【图片】处理方法-------------------------------------
- //------------------------------【语音】处理方法------------------------------------
- var aud = document.getElementById('audio');
- var $playingDom;
- //播放语音结束方法
- function playSoundEnd(){
- $playingDom.removeClass('active');
- $playingDom = null;
- }
- //播放语音错误提示方法
- function playError(){
- var src = $('#audio').attr('src');
- if(!$.trim(src)) {
- return ;
- }
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
- $playingDom.removeClass('active');
- $playingDom = null;
- }
- var recordCancel = false;
- var recorder = null;
- var audio_tips = document.getElementById("audio_tips");
- var startTimestamp = null;
- var stopTimestamp = null;
- var stopTimer = null;
- var MIN_SOUND_TIME = 500;
- var ui = {
- body: document.querySelector('body'),
- btnMsgType: document.querySelector('#msg-type'),
- boxMsgText: document.querySelector('#msg-text'),
- boxMsgSound: document.querySelector('#msg-sound'),
- btnMsgImage: document.querySelector('#msg-image'),
- areaMsgList: document.querySelector('#msg-list'),
- boxSoundAlert: document.querySelector('#sound-alert')
- };
- var recordTimer = null;
- var realStartTime = 0;
- ui.boxMsgSound.addEventListener("touchstart", function(e) {
- e.preventDefault();
- event.preventDefault();
- $(this).addClass('yy-hold');
- if(stopTimer)clearTimeout(stopTimer);
- recordCancel = false;
- audio_tips.innerHTML = "手指上划,取消发送";
- ui.boxSoundAlert.classList.remove('rprogress-sigh');
- setSoundAlertVisable(true);
- startTimestamp = new Date().getTime();
- recordTimer = setTimeout(function(){
- wx.startRecord({
- success: function(){
- realStartTime = new Date().getTime();
- },
- fail: recordErr
- });
- wx.onVoiceRecordEnd({
- // 录音时间超过一分钟没有停止的时候会执行 complete 回调
- complete: function (res) {
- serverId = res.localId;
- sendSounds(60);
- },
- fail: recordErr
- });
- },MIN_SOUND_TIME);
- }, false);
- ui.boxMsgSound.addEventListener("touchend", function(e){
- e.preventDefault();
- event.preventDefault();
- $(this).removeClass('yy-hold');
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- audio_tips.innerHTML = "手指上划,取消发送";
- }
- var endTimestamp = new Date().getTime();
-
- var times = endTimestamp - startTimestamp;
- var realTimes = endTimestamp - realStartTime;
- if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
- audio_tips.innerHTML = "录音时间太短";
- ui.boxSoundAlert.classList.add('rprogress-sigh');
- recordCancel = true;
- stopTimer=setTimeout(function(){
- setSoundAlertVisable(false);
- },500);
- startTimestamp = 0;
- realStartTime = 0;
- //小于300ms,不录音
- clearTimeout(recordTimer);
- wx.stopRecord({
- success: function (res) {
- },
- fail: function(){}
- });
- }else{
- setSoundAlertVisable(false);
- wx.stopRecord({
- success: function (res) {
- if(!recordCancel) {
- serverId = res.localId;
- sendSounds(Math.round(times/1000));
- }
- },
- fail: recordErr
- });
- }
- }, false)
-
- ui.body.addEventListener('drag', function(event) {
- if (Math.abs(event.detail.deltaY) > 50) {
- if (!recordCancel) {
- recordCancel = true;
- if (!audio_tips.classList.contains("cancel")) {
- audio_tips.classList.add("cancel");
- }
- audio_tips.innerHTML = "松开手指,取消发送";
- }
- } else {
- if (recordCancel) {
- recordCancel = false;
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- }
- audio_tips.innerHTML = "手指上划,取消发送";
- }
- }
- }, false);
- var setSoundAlertVisable=function(show){
- if(show){
- ui.boxSoundAlert.style.display = 'block';
- ui.boxSoundAlert.style.opacity = 1;
- }else{
- ui.boxSoundAlert.style.opacity = 0;
- //fadeOut 完成再真正隐藏
- setTimeout(function(){
- ui.boxSoundAlert.style.display = 'none';
- },200);
- }
- },
- //保存语音
- sendSounds = function(times){
- var now = new Date();
- timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
- var data = {};
- data.consult = consult;
- data.content = "";
- data.type = 3;
- data.times = times;
- dd.show();
- wx.uploadVoice({
- localId: serverId,
- success: function (res) {
- data.voices = res.serverId;
- sendPost('patient/consult/append', data, 'json', 'post', function(){
- queryFailed(res, '发送失败');
- },
- function submitSoundSuccess(res) {
- if (res.status == 200) {
- dd.close();
- var data = JSON.parse(res.data[0]);
- addReply(2, data.content, timeStr, 3, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- queryFailed(res, '发送失败');
- }
- });
- }
- });
- },
- //录制语音错误提示信息
- recordErr = function(res){
- if(res && res.errMsg == "stopRecord:tooshort") {
- audio_tips.innerHTML = "录音时间太短";
- ui.boxSoundAlert.classList.add('rprogress-sigh');
- recordCancel = true;
- stopTimer=setTimeout(function(){
- setSoundAlertVisable(false);
- },500);
- startTimestamp = 0;
- //小于300ms,不录音
- if(recordTimer)clearTimeout(recordTimer);
- return;
- }
- if(!recordCancel){
- dialog({
- content:'录音失败,请重试',
- okValue:'我知道了',
- ok: function() {}
- }).showModal();
- }
- };
- //------------------------------【语音】处理方法------------------------------------
- //【视频】处理方法
- //录制视频回调
- var videoFileChange = function(target){
- var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
- if(parseInt(fileSize)>30){
- dialog({
- content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
- okValue:'我知道了',
- ok: function() {
- return;
- }
- }).showModal();
- }else{
- if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
- uploadVideo();
- }else{
- $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
- mui('#sheet1').popover('toggle');
- }
- }
- },
- //上传视频
- uploadVideo = function(){
- dd.showModal();
- var fd=new FormData();
- fd.append('file',document.getElementById("upload_input").files[0]);
- $.ajax(server+"/upload/chat?type=4", {
- data: fd,
- contentType: false,
- cache: false,
- processData: false,
- type: 'post',
- success: function(resData) {
- if(resData.status==200){
- var data = {consult:consult,content:resData.urls,type:12};
- sendPost('patient/consult/append', data, 'json', 'post', function(){
- queryFailed(res, '发送失败');
- },
- function submitSoundSuccess(res) {
- if (res.status == 200) {
- dd.close();
- var data = JSON.parse(res.data[0]);
- addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- queryFailed(res, '发送失败');
- }
- });
- }else{
- dd.close();
- }
- },
- error:function (XMLHttpRequest, textStatus, errorThrown) {
- console.log(XMLHttpRequest.status);
- console.log(XMLHttpRequest.readyState);
- console.log(textStatus)
- }
- });
- };
- Date.prototype.format = function(fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt))
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- //从后台那边获取签名等信息
- function getWXSign(){
- var params = {};
- var url1 = window.location.href;
- params.pageUrl = url1;
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'chooseImage',
- 'uploadImage',
- 'startRecord',
- 'stopRecord',
- 'onVoiceRecordEnd',
- 'playVoice',
- 'pauseVoice',
- 'stopVoice',
- 'onVoicePlayEnd',
- 'uploadVoice',
- 'getNetworkType'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
- wx.ready(function(){
- wx.getNetworkType({
- success: function (res) {
- networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
- }
- });
- });
- }
- }
- });
- }
|