Commit 5c4278ed by 施宇

1111

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