Commit f47d5204 by 施宇

1111

parent c82f6320
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
<script type="text/html" id="zqTpl"> <script type="text/html" id="zqTpl">
<div class="my_xj_list clr "> <div class="my_xj_list clr ">
{{# layui.each(d, function(index, item){ }} {{# layui.each(d, function(index, item){ }}
<div class="my_xj_item fl boxsiz" style="cursor:pointer" userid="{{item.inquiry_items_id}}" <div class="my_xj_item fl boxsiz" style="cursor:pointer" userid="{{item.inquiry_items_id}}">
offerid="{{item.offer_id}}">
<div class="item_top clr"> <div class="item_top clr">
<div class="fl num ellipsis">{{item.goods_name}}</div> <div class="fl num ellipsis">{{item.goods_name}}</div>
</div> </div>
......
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
<script type="text/html" id="xjhtml"> <script type="text/html" id="xjhtml">
<div class="my_xj_list clr "> <div class="my_xj_list clr ">
{{# layui.each(d, function(index, item){ }} {{# layui.each(d, function(index, item){ }}
<div class="my_xj_item fl boxsiz"> <div class="my_xj_item fl boxsiz xj_item" style="cursor:pointer" userid="{{item.inquiry_items_id}}">
<div class="item_top clr"> <div class="item_top clr">
<div class="fl num ellipsis">{{item.goods_name}}</div> <div class="fl num ellipsis">{{item.goods_name}}</div>
</div> </div>
......
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
} }
.chat_content .content .content_div .notice_right .edit_img { .chat_content .content .content_div .notice_right .edit_img {
cursor: pointer; cursor: pointer;
max-width: 100%;
} }
.chat_content .content .content_div .notice_right .chat_item { .chat_content .content .content_div .notice_right .chat_item {
display: none; display: none;
......
...@@ -108,6 +108,7 @@ ...@@ -108,6 +108,7 @@
.edit_img { .edit_img {
cursor: pointer; cursor: pointer;
max-width: 100%;
} }
.chat_item { .chat_item {
......
...@@ -3,106 +3,64 @@ $(function () { ...@@ -3,106 +3,64 @@ $(function () {
conn: {}, conn: {},
orgName: "1113190618181018", orgName: "1113190618181018",
appName: "icsales", appName: "icsales",
// defaultName:"18664936975", defaultName: "18664936975",
defaultName: "18589050841", templateObj: JSON.parse(Util.getCookie('template') || "{}"),
eleTarget: "18589050841", isLoginSuccess: false,
init: function () { init: function () {
this.ieFun() this.ieFun();
this.connection(); this.connection();
this.connListen(); this.connListen();
this.bindFunction(); this.bindFunction();
this.getUserInfo(); this.getHistoryUsers();
}, },
getUserInfo: function () { //获取用户的基本信息 getUserInfo: function () { //获取用户的基本信息
var self = this; var self = this;
IcController.getData(apis.authme, 'POST', null, function (res) { IcController.getData(apis.authme, 'POST', {
"token": Util.getCookie('token') || '',
}, function (res) {
if (res.err_code == 0) { if (res.err_code == 0) {
self.login(res.data.im_username, res.data.im_password) self.login(res.data.im_username, res.data.im_password)
} else { } else {
console.log('获取用户名失败'); console.log('获取用户名失败');
layer.msg('聊天系统出错'); layer.msg('聊天系统出错');
} }
}, undefined, true) }, true, true)
}, },
getHistoryData: function (id, isCustomer) { getHistoryUsers: function () {
//获取用户聊天的成员记录
var self = this; var self = this;
this.conn.fetchHistoryMessages({ IcController.getData(apis.listrecord, 'GET', {
queue: id, "token": Util.getCookie('token') || '',
count: "10", }, function (res) {
success: function (data) { if (res.errcode === 0) {
self.renderHistory(isCustomer, data, id) self.rendChatSection(res.data);
}, self.getUserInfo();
fail: function (e) {
console.log(e)
layer.msg('获取历史纪录失败');
}
})
},
renderHistory: function (isCustomer, data, id) {
var len = data.length;
var arr = [];
for (var i = 0; i < len; i++) {
var fromId = data[i].from, //发送者的id
toId = data[i].to; //接收者的id
if (fromId == '18271408717') { //自己发送的
this.historyHtml(1, data[i])
} else { //自己接收的
this.historyHtml(2, data[i]);
if (data.action == 'action') {
arr.push({
type: 1,
data: {
ext: data.ext
}
})
} else {
if (typeof (data.data) == 'string') {
arr.push({
type: 3,
data: {
ext: data.ext
}
})
} else { } else {
arr.push({ layer.msg('获取历史纪录失败');
type: 3,
data: {
ext: data.ext
}
})
}
}
}
}
},
historyHtml: function (leftOrRight, data) { //1右边 2左边
if (leftOrRight == 1) {
} else {
} }
});
}, },
defaultUser: function () { rendChatSection: function (data) {
//默认客服 this.addUser(this.defaultName);
this.addUser(this.defaultName, true) for (var key in data) {
this.addUser(data[key]);
};
}, },
singleChat: function () { singleChat: function () {
var templateObj = JSON.parse(Util.getCookie('template') || "{}") if (JSON.stringify(this.templateObj) == '{}') {
if (JSON.stringify(templateObj) !== '{}') { $(".notice_classify[userid=" + this.defaultName + "]").click();
this.addUser(templateObj.userId, false) } else {
this.sendCmd(templateObj); this.addUser(this.templateObj.userId);
$(".notice_classify[userid=" + this.templateObj.userId + "]").click();
this.sendCmd(this.templateObj);
Util.delCookie('template', cookieHostname); Util.delCookie('template', cookieHostname);
} }
}, },
addUser: function (id, isCustom) { addUser: function (id) {
var userLen = $('.chat_item_content').find('#' + id).length; var userLen = $('.chat_item_content').find('#' + id).length;
if (userLen) { //用户存在 if (userLen) { //用户存在
$(".notice_classify[userid=" + id + "]").click(); return;
} else { //用户不存在 } else { //用户不存在
var lefthtml = '<div class="notice_classify" userid="' + id + '">' + this.userHtml(0, id, '') + '</div>';; var lefthtml = '<div class="notice_classify" userid="' + id + '">' + this.userHtml(0, id, '') + '</div>';;
var righthtml = '<div class="chat_item" id="' + id + '">' + var righthtml = '<div class="chat_item" id="' + id + '">' +
...@@ -119,16 +77,10 @@ $(function () { ...@@ -119,16 +77,10 @@ $(function () {
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
if (isCustom) { //是客服
$('.notice_left_content').prepend(lefthtml);
$('.chat_item_content').prepend(righthtml)
} else { //不是客服
$('.notice_left_content').append(lefthtml); $('.notice_left_content').append(lefthtml);
$('.chat_item_content').append(righthtml) $('.chat_item_content').append(righthtml)
} }
$(".notice_classify[userid=" + id + "]").click();
}
}, },
connection: function () { connection: function () {
WebIM.config = config; WebIM.config = config;
...@@ -279,6 +231,7 @@ $(function () { ...@@ -279,6 +231,7 @@ $(function () {
'<div class="notice_content">' + '<div class="notice_content">' +
htmlp + htmlp +
'<div>' + this.curentTime() + '</div>' + '<div>' + this.curentTime() + '</div>' +
'</div>'+
'</div>' '</div>'
} else { } else {
return '' return ''
...@@ -291,6 +244,7 @@ $(function () { ...@@ -291,6 +244,7 @@ $(function () {
'<div class="notice_content">' + '<div class="notice_content">' +
htmlp + htmlp +
'<div>' + this.curentTime() + '</div>' + '<div>' + this.curentTime() + '</div>' +
'</div>'+
'</div>' '</div>'
} else { } else {
return '' return ''
...@@ -396,9 +350,8 @@ $(function () { ...@@ -396,9 +350,8 @@ $(function () {
self.conn.listen({ self.conn.listen({
onOpened: function (message) { onOpened: function (message) {
console.log('登入成功') console.log('登入成功')
self.defaultUser(); self.isLoginSuccess = true;
self.singleChat(); self.singleChat();
self.getHistoryData(self.defaultName, true);
}, },
onTextMessage: function (message) { onTextMessage: function (message) {
...@@ -444,17 +397,19 @@ $(function () { ...@@ -444,17 +397,19 @@ $(function () {
}, },
login: function (user, password) { login: function (user, password) {
// open,登录; // open,登录;
var options = { var options = {
apiUrl: WebIM.config.apiURL, apiUrl: WebIM.config.apiURL,
user: '18271408717', user: user,
pwd: '123456', pwd: password,
appKey: WebIM.config.appkey appKey: WebIM.config.appkey
}; };
try { try {
this.conn.open(options); this.conn.open(options);
} catch (e) { } catch (e) {
console.log('登入失败'); console.log(e);
layer.msg('登入失败'); layer.msg('登入失败');
} }
}, },
...@@ -493,7 +448,9 @@ $(function () { ...@@ -493,7 +448,9 @@ $(function () {
msg: 'template', msg: 'template',
to: userId, to: userId,
action: "template", action: "template",
ext: templateObj, ext: $.extend({}, templateObj, {
time: self.curentTime()
}),
success: function () { success: function () {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, $('#' + userId).find('.notice_item_content').append(self.messageHtml(1,
templateObj, true)); templateObj, true));
...@@ -588,13 +545,69 @@ $(function () { ...@@ -588,13 +545,69 @@ $(function () {
$(this).addClass('active').siblings('.notice_classify').removeClass('active'); $(this).addClass('active').siblings('.notice_classify').removeClass('active');
var contentHeight = $('#' + id).find('.notice_item_content').height(); var contentHeight = $('#' + id).find('.notice_item_content').height();
$('#' + id).find('.notice_list').scrollTop(contentHeight); $('#' + id).find('.notice_list').scrollTop(contentHeight);
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id)
} else {
layer.msg('获取聊天记录失败');
return;
}
}); });
$('.notice_right ').on('click', '.edit_img', function () { $('.notice_right ').on('click', '.edit_img', function () {
}) })
},
getHistoryData: function (id) {
var self = this;
this.conn.fetchHistoryMessages({
queue: id,
count: "50",
success: function (data) {
self.rendHistoryMessage(id, data)
},
fail: function (e) {
console.log(e)
layer.msg('获取历史纪录失败');
}
})
},
rendHistoryMessage: function (id, data) {
var chatCon = "";
for (var i = 0; i < data.length; i++) {
var fromId = data[i].from;
var rightOrLeft = 1; //默认右边
var emojiTxt = "";
if (fromId == id) { //接收的 左边
rightOrLeft = 2;
}
if (data[i].data) { //消息或者表情
if (typeof (data[i].data) == 'string') {
chatCon += this.messageHtml(rightOrLeft, data[i].data);
} else {
for (var j = 0; j < data[i].data.length; j++) {
if (data[i].data[j].type == "txt") {
emojiTxt += data[i].data[j].data
} else {
emojiTxt += '<img src ="' + data[i].data[j].data + '" width=25 height=25/>';
}
}
chatCon += this.messageHtml(rightOrLeft, emojiTxt);
}
} else if (data[i].url) { //图片
chatCon += this.messageHtml(rightOrLeft, '<img src ="' + data[i].url + '" class="edit_img"/>');
} else if (data.action) { //模板
}
} }
$('#' + id).find('.notice_item_content').prepend(chatCon);
var contentHeight = $('#' + id).find('.notice_item_content')
.height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
},
}; };
chatObj.init(); chatObj.init();
}) })
\ No newline at end of file
This diff could not be displayed because it is too large.
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
}); });
} else { } else {
typeof callback == 'function' && callback(data); typeof callback == 'function' && callback(data);
layer.close(index); layer.close(index);
......
...@@ -86,7 +86,11 @@ $(function () { ...@@ -86,7 +86,11 @@ $(function () {
time = new Date(Util.getDay(-7)); time = new Date(Util.getDay(-7));
self.getData(spOrXj, 1,time.getTime() / 1000) self.getData(spOrXj, 1,time.getTime() / 1000)
} }
}) });
$('.goods_data_list').on('click','.xj_item',function(){
var userid = $(this).attr('userid');
window.location.href = "/quotedetail?id=" + userid
});
} }
}; };
search.init(); search.init();
......
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