Commit 5c4278ed by 施宇

1111

parent e208a022
...@@ -5,6 +5,7 @@ $(function () { ...@@ -5,6 +5,7 @@ $(function () {
appName: "icsales", appName: "icsales",
defaultName: "18664936975", defaultName: "18664936975",
templateObj: JSON.parse(Util.getCookie('template') || "{}"), templateObj: JSON.parse(Util.getCookie('template') || "{}"),
customerText: Util.getCookie('customer') || "",
isLoginSuccess: false, isLoginSuccess: false,
img: "", img: "",
name: "", name: "",
...@@ -16,6 +17,11 @@ $(function () { ...@@ -16,6 +17,11 @@ $(function () {
this.connListen(); this.connListen();
this.bindFunction(); this.bindFunction();
}, },
deleteCookie: function () {
Util.delCookie('template', cookieHostname);
Util.delCookie('templateBoolean', cookieHostname);
Util.delCookie('customer', cookieHostname);
},
getUserInfo: function () { //获取用户的基本信息 getUserInfo: function () { //获取用户的基本信息
var self = this; var self = this;
IcController.getData(apis.authme, 'GET', { IcController.getData(apis.authme, 'GET', {
...@@ -30,6 +36,7 @@ $(function () { ...@@ -30,6 +36,7 @@ $(function () {
} else { } else {
console.log('获取用户名失败'); console.log('获取用户名失败');
layer.msg('聊天系统出错'); layer.msg('聊天系统出错');
self.deleteCookie()
} }
}, true, false) }, true, false)
}, },
...@@ -44,6 +51,7 @@ $(function () { ...@@ -44,6 +51,7 @@ $(function () {
self.login(name, password); self.login(name, password);
} else { } else {
layer.msg('获取历史纪录失败'); layer.msg('获取历史纪录失败');
self.deleteCookie()
} }
}); });
}, },
...@@ -77,17 +85,21 @@ $(function () { ...@@ -77,17 +85,21 @@ $(function () {
$(".notice_classify[userid=" + this.defaultName + "]").after(html); $(".notice_classify[userid=" + this.defaultName + "]").after(html);
$(".notice_classify[userid=" + this.templateObj.userId + "]").attr('isTemplate', true); //先获取历史纪录再发送模板,否则可能出现发送的消息显示两条 $(".notice_classify[userid=" + this.templateObj.userId + "]").attr('isTemplate', true); //先获取历史纪录再发送模板,否则可能出现发送的消息显示两条
$(".notice_classify[userid=" + this.templateObj.userId + "]").click(); $(".notice_classify[userid=" + this.templateObj.userId + "]").click();
} }
}, },
customerChat: function () {
Util.delCookie('customer', cookieHostname);
$(".notice_classify[userid=" + this.defaultName + "]").attr('isCustomer', true);
},
addUser: function (obj, isDefault, isFirst) { addUser: function (obj, isDefault, isFirst) {
var id, name, img,touserid; var id, name, img, touserid;
if (isDefault) { if (isDefault) {
id = this.defaultName; id = this.defaultName;
name = this.defaultName; name = 'IC助手客服';
touserid = ""; touserid = "";
img = dist + "/images/default.jpg"; img = dist + "/images/timg.jpg";
} else { } else {
if (isFirst) { if (isFirst) {
id = this.templateObj.userId; id = this.templateObj.userId;
...@@ -107,7 +119,7 @@ $(function () { ...@@ -107,7 +119,7 @@ $(function () {
if (userLen) { //用户存在 if (userLen) { //用户存在
return; return;
} else { //用户不存在 } else { //用户不存在
var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true" touserid='+touserid+'>' + this.userHtml(0, { var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true" touserid=' + touserid + '>' + this.userHtml(0, {
name: name, name: name,
id: id, id: id,
img: img img: img
...@@ -359,10 +371,8 @@ $(function () { ...@@ -359,10 +371,8 @@ $(function () {
if (!len) { if (!len) {
//新用户 //新用户
if (Util.getCookie('templateBoolean')) {
Util.delCookie('templateBoolean', cookieHostname); Util.delCookie('templateBoolean', cookieHostname);
} var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true" touserid=' + message.touserid + '>' +
var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true" touserid='+message.touserid+'>' +
self.userHtml(0, message, regContent) + '</div>'; self.userHtml(0, message, regContent) + '</div>';
var messageStr = '<div class="chat_item active" id="' + message.from + '">' + var messageStr = '<div class="chat_item active" id="' + message.from + '">' +
messageSigleStr + '</div>' messageSigleStr + '</div>'
...@@ -404,9 +414,7 @@ $(function () { ...@@ -404,9 +414,7 @@ $(function () {
} else { } else {
//非当前用户 //非当前用户
if (Util.getCookie('templateBoolean')) {
Util.delCookie('templateBoolean', cookieHostname); Util.delCookie('templateBoolean', cookieHostname);
}
var num = Number($(this).find('.num').text()); var num = Number($(this).find('.num').text());
$(this).html(self.userHtml(num + 1, message, regContent)); $(this).html(self.userHtml(num + 1, message, regContent));
var html = $(this).clone(); var html = $(this).clone();
...@@ -422,11 +430,9 @@ $(function () { ...@@ -422,11 +430,9 @@ $(function () {
} else { } else {
if (index == len - 1) { if (index == len - 1) {
//新用户 //新用户
if (Util.getCookie('templateBoolean')) {
Util.delCookie('templateBoolean', cookieHostname); Util.delCookie('templateBoolean', cookieHostname);
}
var userStr = '<div class="notice_classify" userid="' + var userStr = '<div class="notice_classify" userid="' +
message.from + '" newMember="true" touserid='+ message.touserid+'>' + message.from + '" newMember="true" touserid=' + message.touserid + '>' +
self.userHtml(1, message, regContent) + '</div>'; self.userHtml(1, message, regContent) + '</div>';
var messageStr = '<div class="chat_item" id="' + var messageStr = '<div class="chat_item" id="' +
message.from + '">' + message.from + '">' +
...@@ -445,6 +451,7 @@ $(function () { ...@@ -445,6 +451,7 @@ $(function () {
onOpened: function (message) { onOpened: function (message) {
console.log('登入成功') console.log('登入成功')
self.isLoginSuccess = true; self.isLoginSuccess = true;
self.customerChat()
self.singleChat(); self.singleChat();
}, },
onTextMessage: function (message) { onTextMessage: function (message) {
...@@ -454,7 +461,7 @@ $(function () { ...@@ -454,7 +461,7 @@ $(function () {
img: message.ext.img || (dist + "/images/default.jpg"), img: message.ext.img || (dist + "/images/default.jpg"),
message: message.data, message: message.data,
from: message.from, from: message.from,
touserid:message.ext.touserid touserid: message.ext.touserid
}, false) }, false)
}, //收到文本消息; }, //收到文本消息;
onEmojiMessage: function (message) { onEmojiMessage: function (message) {
...@@ -464,7 +471,7 @@ $(function () { ...@@ -464,7 +471,7 @@ $(function () {
img: message.ext.img || (dist + "/images/default.jpg"), img: message.ext.img || (dist + "/images/default.jpg"),
message: message.data, message: message.data,
from: message.from, from: message.from,
touserid:message.ext.touserid touserid: message.ext.touserid
}, false) }, false)
}, //收到表情消息; }, //收到表情消息;
...@@ -483,7 +490,7 @@ $(function () { ...@@ -483,7 +490,7 @@ $(function () {
num: message.ext.num, num: message.ext.num,
hq: message.ext.hq, hq: message.ext.hq,
time: message.ext.time, time: message.ext.time,
touserid:message.ext.touserid touserid: message.ext.touserid
}, true); }, true);
self.addChatMember(message.ext.id) self.addChatMember(message.ext.id)
}, //收到命令消息; }, //收到命令消息;
...@@ -499,7 +506,7 @@ $(function () { ...@@ -499,7 +506,7 @@ $(function () {
img: message.ext.img || (dist + "/images/default.jpg"), img: message.ext.img || (dist + "/images/default.jpg"),
from: message.from, from: message.from,
url: message.url, url: message.url,
touserid:message.ext.touserid touserid: message.ext.touserid
}, false) }, false)
...@@ -535,12 +542,11 @@ $(function () { ...@@ -535,12 +542,11 @@ $(function () {
appKey: WebIM.config.appkey appKey: WebIM.config.appkey
}; };
try { try {
this.conn.open(options); this.conn.open(options);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
layer.msg('登入失败'); layer.msg('登入失败');
this.deleteCookie();
} }
}, },
...@@ -557,7 +563,7 @@ $(function () { ...@@ -557,7 +563,7 @@ $(function () {
id: self.id, id: self.id,
name: self.name, name: self.name,
img: self.img, img: self.img,
touserid:touserid touserid: touserid
}; };
msg.set({ msg.set({
msg: content, // 消息内容; msg: content, // 消息内容;
...@@ -595,11 +601,9 @@ $(function () { ...@@ -595,11 +601,9 @@ $(function () {
layer.msg('消息发送失败'); layer.msg('消息发送失败');
} }
}); });
console.log(msg.body)
this.conn.send(msg.body); this.conn.send(msg.body);
}, },
sendCmd: function (templateObj) { sendCmd: function (templateObj) {
console.log('发送模板')
var self = this; var self = this;
var userId = $('.notice_left ').find('.active').attr('userid'); var userId = $('.notice_left ').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid'); var touserid = $('.notice_left ').find('.active').attr('touserid');
...@@ -610,7 +614,7 @@ $(function () { ...@@ -610,7 +614,7 @@ $(function () {
name: self.name, name: self.name,
id: self.id, id: self.id,
img: self.img, img: self.img,
touserid:touserid touserid: touserid
}); });
msg.set({ msg.set({
msg: 'template', msg: 'template',
...@@ -645,8 +649,7 @@ $(function () { ...@@ -645,8 +649,7 @@ $(function () {
} }
}); });
this.conn.send(msg.body); this.conn.send(msg.body);
Util.delCookie('templateBoolean', cookieHostname);
}, },
sendPrivateImg: function () { sendPrivateImg: function () {
// 私聊发送图片消息; // 私聊发送图片消息;
...@@ -667,7 +670,7 @@ $(function () { ...@@ -667,7 +670,7 @@ $(function () {
id: self.id, id: self.id,
name: self.name, name: self.name,
img: self.img, img: self.img,
touserid:touserid touserid: touserid
}, },
flashUpload: WebIM.flashUpload, flashUpload: WebIM.flashUpload,
onFileUploadError: function () { onFileUploadError: function () {
...@@ -708,6 +711,7 @@ $(function () { ...@@ -708,6 +711,7 @@ $(function () {
} }
}; };
msg.set(option); msg.set(option);
console.log(msg.body)
this.conn.send(msg.body); this.conn.send(msg.body);
}, },
...@@ -754,16 +758,26 @@ $(function () { ...@@ -754,16 +758,26 @@ $(function () {
$('.notice_left').on('click', '.notice_classify', function () { $('.notice_left').on('click', '.notice_classify', function () {
var id = $(this).attr('userid'); var id = $(this).attr('userid');
var isTemplate = $(this).attr('isTemplate'); var isTemplate = $(this).attr('isTemplate');
var isCustomer = $(this).attr('iscustomer');
var firstClick = $(this).attr('firstClick'); var firstClick = $(this).attr('firstClick');
var newMember = $(this).attr('newMember'); var newMember = $(this).attr('newMember');
$('#' + id).addClass('active').siblings('.chat_item').removeClass('active'); $('#' + id).addClass('active').siblings('.chat_item').removeClass('active');
$(this).find('.num').remove(); $(this).find('.num').remove();
$(this).addClass('active').siblings('.notice_classify').removeClass('active'); $(this).addClass('active').siblings('.notice_classify').removeClass('active');
if (isCustomer) {
$(this).removeAttr('iscustomer');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, false, true)
} else {
layer.msg('聊天系统出错');
return;
}
}
if (isTemplate) { if (isTemplate) {
$(this).removeAttr('isTemplate'); $(this).removeAttr('isTemplate');
$(this).removeAttr('firstClick'); $(this).removeAttr('firstClick');
if (self.isLoginSuccess) { //登入成功 获取聊天记录 if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, isTemplate) self.getHistoryData(id, true)
} else { } else {
layer.msg('聊天系统出错'); layer.msg('聊天系统出错');
return; return;
...@@ -799,7 +813,7 @@ $(function () { ...@@ -799,7 +813,7 @@ $(function () {
}) })
}, },
getHistoryData: function (id, isTemplate) { getHistoryData: function (id, isTemplate, isCustomer) {
var self = this; var self = this;
this.conn.fetchHistoryMessages({ this.conn.fetchHistoryMessages({
queue: id, queue: id,
...@@ -809,10 +823,27 @@ $(function () { ...@@ -809,10 +823,27 @@ $(function () {
if (isTemplate) { if (isTemplate) {
self.sendCmd(self.templateObj); self.sendCmd(self.templateObj);
} }
if (isCustomer) {
if (self.customerText) {
self.sendPrivateText(self.customerText)
} else {
return
}
}
}, },
fail: function (e) { fail: function (e) {
console.log(e) console.log(e)
layer.msg('获取历史纪录失败'); layer.msg('获取历史纪录失败');
if (isTemplate) {
self.sendCmd(self.templateObj);
}
if (isCustomer) {
if (self.customerText) {
self.sendPrivateText(self.customerText)
} else {
return
}
}
} }
}) })
}, },
......
...@@ -142,7 +142,8 @@ $(function () { ...@@ -142,7 +142,8 @@ $(function () {
window.location.href = "/gooddetail?type="+ type +"&id=" + goodid window.location.href = "/gooddetail?type="+ type +"&id=" + goodid
}); });
$('.goods_data_list').on('click', '.lx_cus', function () { $('.goods_data_list').on('click', '.lx_cus', function () {
window.location.href = "/chat" Util.setCookie('customer', Util.getRequest('key') || "", 1, cookieHostname)
window.location.href = "/chat";
}); });
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment