|
@ -26,13 +26,11 @@ var userAgent = window.localStorage.getItem(agentName);
|
|
var userInfo = '',
|
|
var userInfo = '',
|
|
patientName = "";
|
|
patientName = "";
|
|
|
|
|
|
$(function() {
|
|
|
|
if(!userAgent) {
|
|
|
|
localStorage.setItem("toUser",toUser);
|
|
|
|
localStorage.setItem("consultCode",consult);
|
|
|
|
window.location.href = "../../home/html/login.html?openid=" + openid+"&type="+pagetype;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
$(function(){
|
|
|
|
checkUserAgent();
|
|
|
|
})
|
|
|
|
|
|
|
|
function queryInit() {
|
|
|
|
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName))
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName))
|
|
patientcode = userInfo.represented?userInfo.represented:userInfo.uid;
|
|
patientcode = userInfo.represented?userInfo.represented:userInfo.uid;
|
|
@ -40,87 +38,10 @@ $(function() {
|
|
var userAgent1 = JSON.parse(window.localStorage.getItem(agentName1));
|
|
var userAgent1 = JSON.parse(window.localStorage.getItem(agentName1));
|
|
patientName = userAgent1.name;
|
|
patientName = userAgent1.name;
|
|
|
|
|
|
//判断关系
|
|
|
|
function hasFamilyRelation(a,b){
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var data={
|
|
|
|
patient:a,
|
|
|
|
familyMember:b
|
|
|
|
}
|
|
|
|
sendPost("patient/family/is_authorize", data, "json", "get", function(res){
|
|
|
|
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
|
|
|
|
}, function(res){
|
|
|
|
if(res.status == 200) {
|
|
|
|
window.localStorage.setItem('nowPatientName',res.data.name);
|
|
|
|
resolve(res)
|
|
|
|
}else if(res.status == 100) {
|
|
|
|
dialog({
|
|
|
|
content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
|
|
|
|
okValue:'切换账号',
|
|
|
|
ok: function() {
|
|
|
|
window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
|
|
|
|
window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
|
|
|
|
},
|
|
|
|
cancelValue: '我不看了',
|
|
|
|
cancel: function () {
|
|
|
|
wx.closeWindow();
|
|
|
|
}
|
|
|
|
}).showModal();
|
|
|
|
}else{
|
|
|
|
relogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//重新登录操作
|
|
|
|
function relogin(){
|
|
|
|
dialog({
|
|
|
|
content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
|
|
|
|
okValue:'切换账号',
|
|
|
|
ok: function() {
|
|
|
|
window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
|
|
|
|
window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
|
|
|
|
},
|
|
|
|
cancelValue: '我不看了',
|
|
|
|
cancel: function () {
|
|
|
|
wx.closeWindow();
|
|
|
|
}
|
|
|
|
}).showModal();
|
|
|
|
}
|
|
|
|
//保存信息
|
|
|
|
function saveUserInfo(a,b){
|
|
|
|
Promise.all([hasFamilyRelation(a,b)]).then(function () {
|
|
|
|
newUaObj.represented = represented;
|
|
|
|
window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
|
|
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName));
|
|
|
|
bindEvents();
|
|
|
|
checkStatus();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function initFamilyData () {
|
|
|
|
//从微信模板消息进入
|
|
|
|
if(represented && userAgent && toUser){
|
|
|
|
if(toUser == represented){
|
|
|
|
saveUserInfo(represented,newUaObj.uid)
|
|
|
|
}else if(toUser != represented && represented == newUaObj.uid){
|
|
|
|
//本人代理
|
|
|
|
saveUserInfo(represented,newUaObj.uid)
|
|
|
|
}else if(toUser != represented && toUser == newUaObj.uid){
|
|
|
|
//需要判定关系 200有授权 100家人 1无关系
|
|
|
|
saveUserInfo(represented,newUaObj.uid)
|
|
|
|
}else{
|
|
|
|
//重新登录
|
|
|
|
relogin();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName));
|
|
|
|
bindEvents();
|
|
|
|
checkStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initFamilyData();
|
|
|
|
|
|
getWeixinSign();
|
|
|
|
// initFamilyData();
|
|
|
|
bindEvents();
|
|
|
|
checkStatus();
|
|
|
|
|
|
//点击内容区域输入框失焦
|
|
//点击内容区域输入框失焦
|
|
$('#talkwrap').click(function(){
|
|
$('#talkwrap').click(function(){
|
|
@ -131,90 +52,129 @@ $(function() {
|
|
$("#reply a").click(function() {
|
|
$("#reply a").click(function() {
|
|
send();
|
|
send();
|
|
});
|
|
});
|
|
//从后台那边获取签名等信息
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//获取sessionId
|
|
|
|
sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed2, function(res){
|
|
|
|
if(res.status==200){
|
|
|
|
var sessionId = JSON.parse(res.msg)[0].session_id;
|
|
|
|
//加载socket组件
|
|
|
|
jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
|
|
|
|
var socket = io.connect(imurl);
|
|
|
|
socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.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)){
|
|
|
|
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) {
|
|
|
|
// console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('ack', function (data) {
|
|
|
|
// console.log(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 hasFamilyRelation(a,b){
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var data={
|
|
|
|
patient:a,
|
|
|
|
familyMember:b
|
|
|
|
}
|
|
|
|
sendPost("patient/family/is_authorize", data, "json", "get", function(res){
|
|
|
|
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
|
|
|
|
}, function(res){
|
|
|
|
if(res.status == 200) {
|
|
|
|
window.localStorage.setItem('nowPatientName',res.data.name);
|
|
|
|
resolve(res)
|
|
|
|
}else if(res.status == 100) {
|
|
|
|
dialog({
|
|
|
|
content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
|
|
|
|
okValue:'切换账号',
|
|
|
|
ok: function() {
|
|
|
|
window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
|
|
|
|
window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
|
|
|
|
},
|
|
|
|
cancelValue: '我不看了',
|
|
|
|
cancel: function () {
|
|
|
|
wx.closeWindow();
|
|
|
|
}
|
|
|
|
}).showModal();
|
|
|
|
}else{
|
|
|
|
relogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//重新登录操作
|
|
|
|
function relogin(){
|
|
|
|
dialog({
|
|
|
|
content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
|
|
|
|
okValue:'切换账号',
|
|
|
|
ok: function() {
|
|
|
|
window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
|
|
|
|
window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
|
|
|
|
},
|
|
|
|
cancelValue: '我不看了',
|
|
|
|
cancel: function () {
|
|
|
|
wx.closeWindow();
|
|
|
|
}
|
|
|
|
}).showModal();
|
|
|
|
}
|
|
|
|
//保存信息
|
|
|
|
function saveUserInfo(a,b){
|
|
|
|
Promise.all([hasFamilyRelation(a,b)]).then(function () {
|
|
|
|
userInfo.represented = represented;
|
|
|
|
window.localStorage.setItem(agentName,JSON.stringify(userInfo));
|
|
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName));
|
|
|
|
bindEvents();
|
|
|
|
checkStatus();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function initFamilyData () {
|
|
|
|
//从微信模板消息进入
|
|
|
|
if(represented && userAgent && toUser){
|
|
|
|
if(toUser == represented){
|
|
|
|
saveUserInfo(represented,userInfo.uid)
|
|
|
|
}else if(toUser != represented && represented == userInfo.uid){
|
|
|
|
//本人代理
|
|
|
|
saveUserInfo(represented,newUaObj.uid)
|
|
|
|
}else if(toUser != represented && toUser == userInfo.uid){
|
|
|
|
//需要判定关系 200有授权 100家人 1无关系
|
|
|
|
saveUserInfo(represented, userInfo.uid)
|
|
|
|
}else{
|
|
|
|
//重新登录
|
|
|
|
relogin();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
userInfo = JSON.parse(window.localStorage.getItem(agentName));
|
|
|
|
bindEvents();
|
|
|
|
checkStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTopic(){
|
|
|
|
//获取sessionId
|
|
|
|
sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed2, function(res){
|
|
|
|
if(res.status==200){
|
|
|
|
var sessionId = JSON.parse(res.msg)[0].session_id;
|
|
|
|
//加载socket组件
|
|
|
|
/*jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
|
|
|
|
var socket = io.connect(imurl);
|
|
|
|
socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.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)){
|
|
|
|
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) {
|
|
|
|
// console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('ack', function (data) {
|
|
|
|
// console.log(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 sendBtn() {
|
|
function sendBtn() {
|
|
var tval = $(".talk-input input").val();
|
|
var tval = $(".talk-input input").val();
|
|
@ -1293,4 +1253,51 @@ Date.prototype.format = function(fmt) { //author: meizz
|
|
if (new RegExp("(" + k + ")").test(fmt))
|
|
if (new RegExp("(" + k + ")").test(fmt))
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
return fmt;
|
|
return fmt;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWeixinSign(){
|
|
|
|
//从后台那边获取签名等信息
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|