var token= $.cookie("token"); var username=$.cookie("zx_user"); $('.chat_sidebar_list ul').on('click','li',function(){ if($('.disnone').css('display')=="none"){ $('.disnone').css('display','block') } $(this).addClass("actives").siblings().removeClass("actives"); var person_name=$(this).find('.chat_name .names').html(); var person_userId=$(this).find('.chat_name .user_id').html(); $('.chat_person .chat_name').html(person_name+" "+person_userId); }) left();//角色 side(); function left(){ $.ajax({ type:"get", url:huayi.config.callcenter_url+"Index/GetRoleList", async:true, dataType:'json', data:{ token: $.cookie("token") }, success:function(data){ if(data.state.toLowerCase()=='success'){ $('.chat_left ul').html(''); var con=data.data; $('
  • '+ '

    所有人

    '+ '
  • ').appendTo('.chat_left ul'); $(con).each(function(i,n){ $('
  • '+ '

    '+n.F_RoleName +'

    '+ '
  • ').appendTo('.chat_left ul'); }) } } }); } $('.chat_left ul').on('click','li',function(){ if($('.disnone').css('display')=="none"){ $('.disnone').css('display','block') } $(this).addClass("actives").siblings().removeClass("actives"); var person_name=$(this).find('.chat_name').html(); $('.chat_person .chat_name').html(person_name); var roleId=$(this).attr("RoleId"); var userId=$(this).attr("UserId"); var IsToAll=$(this).attr("IsToAll"); $('.IsToAll').val(IsToAll); $('.RoleId').val(roleId); $('.UserId').val(userId); side(); jiShi() }) //side function side(){ $.ajax({ type:"get", url:huayi.config.callcenter_url+"Index/GetUserListByRoleId", async:true, dataType:'json', data:{ token: $.cookie("token"), roleid:$('.RoleId').val(), keyword:$('.sidebar_foot_seach').val() }, success:function(data){ if(data.state.toLowerCase()=='success'){ $('.chat_sidebar_list ul').html(''); var html=''; var con=data.data; console.log(username) $(con).each(function(i,n){ if(username==n.F_UserCode){ $('.chat_sidebar_head').find('.chat_name').html(n.F_UserName+n.F_UserCode) } html='
  • '+ // src="'+ huayi.config.callcenter_url.substr(0, huayi.config.callcenter_url.length - 1) + n.F_See +'" ''+ '

    '+n.F_UserName +'
    '+ n.F_UserCode +'

    ' if(n.counts>0){ html+='

    '+n.counts+'

    ' } html+='
  • ' $('.chat_sidebar_list ul').append(html); }) } } }); if( $('.UserId').val()!=0){ $('.chat_sidebar_list ul li').each(function(i,n){ if($(n).attr('UserId')==$('.UserId').val()){ $(this).addClass('actives'); } }) } } $('.chat_sidebar_list ul').on('click','li',function(){ var userId=$(this).attr("userid"); // var roleId=$(this).attr("roleid"); // var IsToAll=$(this).attr("IsToAll"); $('.RoleId').val(0); $('.IsToAll').val(0); $('.UserId').val(userId); jiShi(userId); }) $('.sidebar_foot_seach').on('input focus',function(){ side() }) //即时通讯 function jiShi() { helper.init.isload = 0; $.ajax({ type:"get", url:huayi.config.callcenter_url+"Index/GetChatList", async:true, dataType:'json', data: { token: $.cookie("token"), fromuserId: $('.UserId').val() }, success: function (data) { helper.init.isload = 1; $('.main_message .chatlist_con').html(''); var con=data.rows; $(con).each(function(i,n){ if($('.UserId').val()==n.FromUserId){ $('
  • '+ '

    '+ n.CreateDate +'

    '+ '
    '+ ''+ '
    '+ n.Content +'
    '+ '
    '+ '
  • ').appendTo('.main_message .chatlist_con') } else{ $('
  • '+ '

    '+ n.CreateDate +'

    '+ '
    '+ ''+ '
    '+ n.Content +'
    '+ '
    '+ '
  • ').appendTo('.main_message .chatlist_con') } }) var farTop=$(".main_message").css('height'); $(".main_message").animate({ scrollTop:farTop}); } }); } $('.sendTo').click(function(){ if($('.send_content').val()){ send() }else{ layer.msg("内容不允许为空!"); } }) function send(){ $.ajax({ type:"post", url:huayi.config.callcenter_url+"Index/SaveChatInfo", async:true, dataType:'json', data:{ token: $.cookie("token"), Content:$('.send_content').val(), IsToAll:$('.IsToAll').val(), ToRoleId:$('.RoleId').val(), ToUserId:$('.UserId').val() }, success:function(data){ if(data.state.toLowerCase()=='success'){ $('.send_content').val(''); } } }) } //键盘发送事件 $('input').bind('keypress', function(event) { if(event.keyCode == "13") { $('.sendTo').trigger("click"); } }); $(document).keydown(function(event){ if(event.keyCode==13){ $(".sendTo").click(); } }); function Ajax(){ side(); jiShi(); } setInterval(Ajax, 2000);//Ajax调用函数 /* Index/SaveChatInfo?Content=&ToUserId=&ToRoleId=&IsToAll= 注意优先级: 当IsToAll=1时群发给所有人 当ToRoleId!=0时群发给所在角色 当ToUserId!=0时发给该坐席人员ssss */