var d = dialog({contentType:'load', skin:'bk-popup'});
var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
var Request = new Object();
Request = GetRequest();
var userAgent = window.localStorage.getItem(agentName);
var toUser = Request["toUser"];
var toName = decodeURIComponent(Request["toName"]);
var openid = Request["openid"];
var represented = Request["represented"];
var consult = Request["consult"];
var pagetype = 0;
$(function() {
if(!userAgent) {
window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
window.location.href = server + "wx/html/home/html/login.html?type=" + pagetype + "&openid=" + openid;
return false;
}
var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
//判断关系
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));
})
}
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();
}
}
}
initFamilyData();
var doctorPar,//参与咨询医生信息
$starListGroup = $('#manValueList'),
reqUrl = '',
evaluateKind = 1,//实名类型
finish = 1;//提交后标志
//参与者
var data = {};
data.consult = consult;
data.page = 1;
data.pagesize = 1;
sendPost('patient/consult/loglist', data, 'json', 'GET', function(){
dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请求数据失败'}).show();
}, function(res){
if (res.status == 200) {
res = res.list;
var arr = [];//储存参与咨询的医生
for(var k in res.users){
if(res.users[k].is_patient == 0){
arr.push(res.users[k])
}
}
doctorPar=arr;
nextWork();
}else{
dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载数据失败'}).show();
}
})
function nextWork(){
if(doctorPar){
for(var k in doctorPar){
if(doctorPar[k].level == 1){
doctorPar[k].levelName = '专科医生'
}
if(doctorPar[k].level == 2){
doctorPar[k].levelName = '全科医生'
}
if(doctorPar[k].level == 3){
doctorPar[k].levelName = '健康管理师'
}
}
}
queryOldData();
bindEvents();
}
function bindEvents(){
//文本框
$starListGroup.on('keyup',"textarea",function(){
var $this = $(this);
var count = $this.val().length;
$this.parent('.text-input').find('.text_count').text(count);
});
//匿名
$('.j-niming').on('click',function(){
if(finish == 1){
var $this = $(this).parent();
if($this.hasClass('active')){
$this.removeClass('active');
evaluateKind = 1;
}else{
$this.addClass('active');
evaluateKind = 2;
}
}
})
//贴标签展开和关闭
$starListGroup.on('click','.small-title',function(){
if(finish == 1){
var $this = $(this);
if($this.hasClass('active')){
$this.removeClass('active');
$this.siblings('.j-tag-detail').animate({height:'hide'},300)
}else{
$this.addClass('active');
$this.siblings('.j-tag-detail').animate({height:'show'},300)
}
}
})
//点击显示星星
$starListGroup.on('click','.star-lists .one-star',function(){
var $this = $(this);
var $parent = $this.parent();
if(finish == 1){
$parent.find('.one-star').removeClass('active')
for(var i=0;i<=$this.index();i++){
$parent.find('.one-star').eq(i).addClass('active');
}
}
})
//贴上功能
$starListGroup.on('click','.j-submit',function(){
if(finish == 1){
var $this = $(this);
var $input = $this.siblings('.input').find('input');
var val = $input.val().trim();
if($this.parent().siblings('ul.tag-list').find('li.active').length > 3){
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'最多只能选择4个标签'}).show();
}else{
if(val){
if(val.length>8){
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'自定义标签最多8个字'}).show();
$input.blur();
return;
}else{
var html = '
'+val+'';
$this.parent().siblings('ul.tag-list').append(html);
$input.val('');
$input.blur();
}
}
}
}
})
//点击标签选取
$starListGroup.on('click','ul.tag-list li',function(){
if(finish == 1){
var $this = $(this);
if($this.hasClass('active')){
$this.removeClass('active');
}else{
if($this.closest('ul.tag-list').find('li.active').length > 3){
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'最多只能选择4个标签'}).show();
}else{
$this.addClass('active');
}
}
}
})
$('#commit').click(function(){
var data = {},
label = [],
evaluate = [],
evaluateScore = [],
$one = $starListGroup.find('.j-section');
for(var i=0;i< $one.length;i++){
var $ul = $one.eq(i).find('.star-lists').find('ul.list li.active').length;//该医生是否评价完整
var remarkValue = $one.eq(i).find('.text-input textarea').val().trim();
if($ul >0){
for(var j=0;j<3;j++){
var val = $one.eq(i).find('.star-lists').eq(j).find('ul.list li.active').length;
if(!val){
dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请完善医生评分'}).show();
return ;
}
if(val <= 3){
var isNimimg = $('.ni-select').hasClass('active');
if(isNimimg){
dialog({
content:'为了帮助医生及时发现服务中存在的问题并作出改正,当您给出三星及以下评价时,需要实名评价哦~',
okValue:'确定',
ok: function() {
// wx.closeWindow();
}
}).showModal();
return ;
}
}
if(val <= 4){
if(!remarkValue){
dialog({
content:'为帮助医生及时发现服务存在的问题,当您给出四星及以下评价时,需要说明对医生服务的意见哦~',
okValue:'确定',
ok: function() {
// wx.closeWindow();
}
}).showModal();
return ;
}
}
}
}else{
dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请完善医生评分'}).show();
return ;
}
}
dd.showModal();
for(var i=0;i< $one.length;i++){
for(var j=0;j<3;j++){
var obj = {};
obj['doctor'] = $one.eq(i).find('.down-sec').data('code');
obj['score'] = $one.eq(i).find('.star-lists').eq(j).find('ul.list li.active').length*20;
obj['type'] = evaluateKind;
obj['evaluateType'] = j+1;//匿名评价类型
evaluate.push(obj);
}
var that = $one.eq(i).find('.j-nosel .tag-list li.active');
if(that.length >0){
for(var z=0;z0){
for(var j=0;j';
$ul2.append(html);
}
}
}
}
$('.j-nosel').show();
$('.j-hassel').hide();
}
//点击修改显示文本
function showTextarea2(){
var $one = $starListGroup.find('.j-section');
for(var i=0;i<$one.length;i++){
var $ul = $one.eq(i).find('.text-input textarea'),
$ul2 = $one.eq(i).find('.show-word'),
$val = $ul2.html();
if($val){
$ul.val($val);
$ul.parent('.text-input').find('.text_count').text($ul.val().length);
}
}
$('.text-input').show();
$('.show-word').hide();
}
//正要评价的样式
function evaluating(){
finish = 1;
$('#show_text').show();
$('#no_header').show();
}
//已经评价过的样式
function evaluated(){
finish = 0;
$('#show_text').show();
$('#yes_header').show();
$('.j-nosel').hide();
$('.text-input').hide();
$('.show-word').show();
hasName();
$('#revise').show();
$('#commit').hide();
$('.small-title').removeClass('active');
$('.j-tag-detail').hide();
}
//提交评价后的样式
function committed(){
finish = 0;
localStorage.setItem("evaluate",1);
$('#commit').hide();//按钮
$('#revise').show();
$('#yes_header').show();
$('#again_header').hide();
$('#no_header').hide();
$('.small-title').removeClass('active');
$('.j-tag-detail').hide();
showTag();
showTextarea();
$('body').scrollTop(0);
}
//实匿名样式切换
function hasName(){
if(evaluateKind == 2){
$('.ni-select').addClass('active');
}else{
$('.ni-select').removeClass('active');
}
}
function submitFailed(res) {
dd.close();
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 submitSuccess(res) {
dd.close();
if(res.status==200){
dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'提交成功'}).show();
committed();
}else{
if (res && res.msg) {
dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
}
}
}
//提交后显示标签
function showTag(){
var $one = $starListGroup.find('.j-section');
for(var i=0;i<$one.length;i++){
var $ul = $one.eq(i).find('.j-nosel .tag-list');
var $li = $ul.find('li.active');
var num = $li.length;
var $ul2 = $one.eq(i).find('.j-hassel .tag-list');
if(num>0){
var html='';
for(var j=0;j'+$li.eq(j).text()+''
}
$ul2.html(html);
$one.eq(i).find('.j-hassel').show();
}
}
$('.j-nosel').hide();
}
//提交后显示文本
function showTextarea(){
var $one = $starListGroup.find('.j-section');
for(var i=0;i<$one.length;i++){
var $ul = $one.eq(i).find('.text-input'),
$val = $ul.find('textarea').val().trim(),
$ul2 = $one.eq(i).find('.show-word');
if($val){
$ul2.html($val);
$one.eq(i).find('.show-word').show();
}
}
$('.text-input').hide();
}
//请求数据看是否评价
function queryOldData(){
var params= {};
params.consult = consult;
sendPost('patient/consult/evaluate/list', params, 'json', 'get', queryFailed, querySuccess);
function queryFailed(res) {
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 querySuccess(res) {
if(res.status==200){
//显示内容
var html = template("star_list_temp", {data: doctorPar});
$starListGroup.append(html);
var list = res.data['evaluate'];
var labelTag = res.data['label'];
var content = res.data['evaluateScore'];
if(list && list.length>0){
for(var i=0;i<$('.j-section').length;i++){
for(var j=0;j0){
var that = $('.j-hassel').eq(i).find('.tag-list');
for(var z=0;z';
that.append(html);
}
}
$('.j-section').eq(i).find('.j-hassel').show();
}
//显示意见内容
if(content && content.length>0){
var that = $('.j-section').eq(i).find('.show-word');
for(var z=0;z