123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- $(document).ready(function () {
- var userid = $.cookie("userid");
- var objp = {};
- var imgUrl = "";
- var timerset;
- var oflag = false;
- var pd = false;
- loginStatus();
- $(".list_body").niceScroll({
- cursorcolor: "#999999"
- });
- $(".chat_body.clearfix").niceScroll({
- cursorcolor: "#999999"
- });
- messageList();
- setInterval(messageList,5000)
- function messageList() {
- $.ajax({
- "url": "/ajax/platform/msg/idx",
- "type": "get",
- "async": true,
- "data": {
- 'provider': userid
- },
- "success": function (data) {
- if (data.success) {
- getTotalMessage();
- unReadedCount(userid)
- $(".list_body").html("");
- var $data = data.data;
- for (var i = 0; i < $data.length; i++) {
- var num = "none"
- if ($data[i].unread) {
- num = "block";
- }
- var ostr = '<div class="list_item clearfix" data-id="' + $data[i].requestor + '">' +
- '<i class="close_icon"></i>' +
- '<div class="avatar fl">' +
- '<img src="images/default-photo.jpg">' +
- '<span class="tips_num" style="display:' + num + '">' + $data[i].unread + '</span>' +
- '</div>' +
- '<div class="list_item_info fl">' +
- '<div class="user_infos">' +
- '<span class="user_name"> </span><em class="authiconNew"></em>' +
- '</div>' +
- '<span class="time">' + commenTime($data[i].opTime) + '</span><span class="last_news">' + ($data[i].cnt).replace(/\n/g, "<br />") + '</span>' +
- '</div>' +
- '</div>'
- var $str = $(ostr);
- if(oflag) {
- if (objp.requestor === $data[i].requestor) {
- $str.addClass('active');
- }
- }
- $(".list_body").append($str);
- var oMess = {
- "provider": $data[i].provider,
- "pid": $data[i].pid,
- "requestor": $data[i].requestor
- }
- $str.attr("dataobj", JSON.stringify(oMess))
- personMess($data[i].requestor, $str.find('img'), $str.find(".user_name"), $str.find(".authiconNew"));
- }
- if ($data.length === 0) {
- $(".list_body").html('<div class="list_item clearfix" style="text-align:center;margin-top:15px;">暂无消息</div>');
- }
- }
- },
- "error": function () {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
-
- function personMess(id, pImg, pName, pTitle) {
- $.ajax({
- "url": platUrl + "/ajax/sys/user/get",
- "data": {
- id: id
- },
- "type": "GET",
- "traditional": true,
- "dataType": "json",
- "success": function (data) {
- if (data.success) {
- var $data = data.data;
- var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
- pTitle.attr("title", userType.title).addClass(userType.sty);
- pName.text($data.name || $data.account);
- var img="";
- if ($data.head) {
- pImg.attr("src", $data.head);
- img = $data.head;
- } else {
- pImg.attr("src", '/images/default-photo.jpg');
- img = '/images/default-photo.jpg';
- }
- var str = ''
- if ( $data.comp) {
- if ($data.job) {
- str = $data.comp+","+ $data.job;
- } else {
- str = $data.comp
- }
- } else {
- if ($data.job) {
- str = $data.job;
- }
- }
- var oMess = {
- "name": $data.name || $data.account,
- "idf": userType,
- "id": $data.id,
- "duties": str,
- "img":img
- }
- pImg.parents(".list_item").attr("data", JSON.stringify(oMess))
- }
- },
- "error": function (err) {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
- function ci(e) {
- var elem = e.target;
- if (elem.tagName.toLowerCase() === 'img') {
- var $this = $(elem);
- $this.attr("src", "/images/default-photo.jpg");
- }
- }
- document.addEventListener("error", ci, true );
-
- $(".list_body").on("click", ".list_item", function () {
- oflag = true;
- pd = true;
- if(timerset) {
- clearInterval(timerset);
- }
- $(this).addClass("active").siblings().removeClass("active");
- if ($(this).find(".tips_num").css("display") == "block") {
- $('.mymessage .badge').text(Number($('.mymessage .badge').text()) - Number($(this).find(".tips_num").text()));
- if ($('.mymessage .badge').text() == 0) {
- $(".mymessage .badge").text("");
- }
- }
- $(this).find(".tips_num").text(0).hide();
- if ($(".usepro .user_name").css("display") == "block") {
- if ($(this).find(".user_name").text() == $(".usepro .user_name").text()) {
- return;
- }
- }
- $(".chat_content_nodata").hide();
- $(".chat_content").show();
- var pro = JSON.parse($(this).attr("data"));
- $(".usepro").find(".user_name").text(pro.name).siblings(".authiconNew").addClass(pro.idf.sty).attr("title", pro.idf.title).parent().siblings(".chating_resume_status").text(pro.duties);
- var dataobj = JSON.parse($(this).attr('dataobj'));
- objp = dataobj;
- imgUrl = JSON.parse($(this).attr('data')).img;
- if (Number($(this).find(".tips_num").text())) {
- angleMessageList(dataobj, true);
- } else {
- angleMessageList(dataobj);
- }
- getPlatName(objp.pid)
- timerset=setInterval(function() {
- angleMessageList(dataobj);
- },5000)
- });
- function getPlatName(pid) {
- $.ajax({
- url: "/ajax/platform/info",
- type: "GET",
- timeout: 10000,
- dataType: "json",
- traditional:true,
- data:{
- id: pid
- },
- success: function(data) {
- if(data.success) {
- $('#cUserPage').text('来自:'+data.data.name);
- }
- },
- error: function() {
- $.MsgBox.Alert('提示', '链接服务器超时')
- }
- })
- }
- getKexiuTotal()
- function getKexiuTotal() {
- $.ajax({
- url: "ajax/webMsg/unReadedCount",
- type: "GET",
- timeout: 10000,
- dataType: "json",
- traditional:true,
- data:{
- id: userid
- },
- success: function(data) {
- if(data.success) {
- if(data.data) {
- $('.kexiuTotal').text('('+data.data+')');
- } else {
- $('.kexiuTotal').text('');
- }
- }
- },
- error: function() {
- $.MsgBox.Alert('提示', '链接服务器超时')
- }
- })
- }
- function getTotalMessage() {
- $.ajax({
- url: "/ajax/platform/msg/unread",
- type: "GET",
- timeout: 10000,
- dataType: "json",
- traditional:true,
- data:{
- provider: userid
- },
- success: function(data) {
- if(data.success) {
- if(data.data) {
- $('.mesTotal').text('('+data.data+')');
- } else {
- $('.mesTotal').text('');
- }
- }
- },
- error: function() {
- $.MsgBox.Alert('提示', '链接服务器超时')
- }
- })
- }
- function angleMessageList(info) {
- $.ajax({
- "url": "/ajax/platform/msg/rec",
- "type": "get",
- "async": true,
- "data": info,
- "success": function (data) {
- if (data.success) {
- $(".chat_body_list").html("")
- var $data = data.data;
- if ($data.length) {
- if (arguments[1]) {
- setRead(info);
- }
- for (var i = $data.length - 1; i >= 0; i--) {
- var le = "";
- var flo = 'fl';
- var wei = "";
- var fCo = "C_end";
- var timeG = '';
- var headImg = '';
- if ($data[i].msgType) {
- le = "me";
- flo = "fr";
- if ($data[i].readed) {
- wei = '<em class="is_readed"></em>';
- } else {
- wei = '<em class="is_readed"></em>';
- }
- fCo = "B_end";
- headImg = '/images/head/' + userid + '_l.jpg';
- } else {
- headImg = imgUrl;
- }
- if (i == 0) {
- timeG = anTime($data[i].opTime);
- } else {
- timeG = compareTime($data[i].opTime, $data[i - 1].opTime)
- }
- var oStr = '<span class="time" data-createtime="' + $data[i].opTime + '">' + timeG + '</span>' +
- '<div class="chat_item ' + le + '">' +
- '<div class="clearfix">' +
- '<div class="item_avatar fl">' +
- '<img src="'+headImg+'">' +
- '</div>' +
- '<div class="item_content ' + flo + '">' +
- wei +
- '<div class="bubble message ' + fCo + '">' + ($data[i].cnt).replace(/\n/g, "<br />") + '</div>' +
- '</div>' +
- '</div>' +
- '</div>'
- $(".chat_body_list").append(oStr);
- }
- $(".chat_body.clearfix").getNiceScroll().hide().show().resize();
- if (pd) {
- $(".chat_body.clearfix").getNiceScroll(0).doScrollTop($(".chat_body_list").height(), 100);
- pd = false;
- }
- }
- }
- },
- "error": function () {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
-
- function setRead(data) {
- $.ajax({
- "url": "/ajax/platform/msg/readed",
- "type": "POST",
- "traditional": true,
- "data": data,
- "dataType": "json",
- "success": function (data) {
- if (data.success) {
- }
- },
- "error": function () {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
-
- function timeC(startTime) {
- var startdate = new Date(); 20190124155759
- startdate.setFullYear(parseInt(startTime.substring(0, 4)));
- startdate.setMonth(parseInt(startTime.substring(4, 6)) - 1);
- startdate.setDate(parseInt(startTime.substring(6, 8)));
- startdate.setHours(parseInt(startTime.substring(8, 10)));
- startdate.setMinutes(parseInt(startTime.substring(10, 12)));
- startdate.setSeconds(parseInt(startTime.substring(12, 14)));
- return startdate.getTime();
- }
- function compareTime(startTime, secondTime) {
- var date3 = timeC(secondTime) - timeC(startTime);
- if (date3 >= 600000) {
- if (new Date().getFullYear() == secondTime.substring(0, 4)) {
- return secondTime.substring(4, 6).replace(/\b(0+)/gi, "") + "月" + secondTime.substring(6, 8).replace(/\b(0+)/gi, "") + "日 " + secondTime.substring(8, 10) + ":" + secondTime.substring(10, 12);
- } else {
- return secondTime.substring(0, 4) + "年" + secondTime.substring(4, 6).replace(/\b(0+)/gi, "") + "月" + secondTime.substring(6, 8).replace(/\b(0+)/gi, "") + "日 " + secondTime.substring(8, 10) + ":" + secondTime.substring(10, 12);
- }
- } else {
- return '';
- }
- }
- function anTime(secondTime) {
- if (new Date().getFullYear() == secondTime.substring(0, 4)) {
- return secondTime.substring(4, 6).replace(/\b(0+)/gi, "") + "月" + secondTime.substring(6, 8).replace(/\b(0+)/gi, "") + "日 " + secondTime.substring(8, 10) + ":" + secondTime.substring(10, 12);
- } else {
- return secondTime.substring(0, 4) + "年" + secondTime.substring(4, 6).replace(/\b(0+)/gi, "") + "月" + secondTime.substring(6, 8).replace(/\b(0+)/gi, "") + "日 " + secondTime.substring(8, 10) + ":" + secondTime.substring(10, 12);
- }
- }
-
- function sendMessage(par) {
- par.cnt = $('.messContent').val();
- $.ajax({
- "url": "/ajax/platform/msg/send",
- "type": "POST",
- "traditional": true,
- "data": par,
- "dataType": "json",
- "success": function (data) {
- if (data.success) {
- $(".btnModel").attr("disabled", "disabled");
- angleMessageList(objp)
- $(".messContent").val("");
- pd = true;
- }
- },
- "error": function () {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
- $(".btnModel").click(function () {
- sendMessage(objp);
- })
- $(".messContent").on("input", function () {
- if ($.trim($(this).val()) == "") {
- $('.btnModel').attr("disabled", "disabled");
- } else {
- $('.btnModel').removeAttr("disabled");
- }
- })
-
- var $that;
- $(".list_body").on("click", ".close_icon", function() {
- var dataobj = JSON.parse($(this).parents('.list_item').attr('dataobj'));
- objp = dataobj;
- if(timerset) {
- clearInterval(timerset);
- }
- oflag = false;
- $that = $(this)
- $.MsgBox.Confirm("提示", "确定删除?", deleChat);
- return false;
- })
-
- function deleChat() {
- $.ajax({
- "url": "/ajax/platform/msg/delete",
- "type": "POST",
- "traditional": true,
- "data": objp,
- "context": $that.parents(".list_item"),
- "dataType": "json",
- "success": function(data) {
- if(data.success) {
- $(this).remove();
- $(".chat_content_nodata").show();
- $(".chat_content").hide();
- getTotalMessage();
- unReadedCount(userid)
- }
- },
- "error": function() {
- $.MsgBox.Alert('提示', '服务器连接超时');
- }
- });
- }
- })
|