...
|
...
|
@@ -5,22 +5,13 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
import {
|
|
|
time
|
|
|
} from './time';
|
|
|
import {
|
|
|
tip
|
|
|
} from './tip';
|
|
|
import {
|
|
|
RatingView,
|
|
|
LeaveMSGView,
|
|
|
OrderListView
|
|
|
} from './view';
|
|
|
import {time} from './time';
|
|
|
import {RatingView, LeaveMSGView, OrderListView } from './view';
|
|
|
|
|
|
var socket = require('./socket-chat'),
|
|
|
socketConf = require('./socket-config'),
|
|
|
cmEntity = socketConf.conversationMessage,
|
|
|
lastTimeShow = 0;
|
|
|
socketConf = require('./socket-config');
|
|
|
|
|
|
var cmEntity = socketConf.conversationMessage;
|
|
|
|
|
|
const chatBox = $('#chat-window'),
|
|
|
encryptedUid = $('#encrypteduid').val();
|
...
|
...
|
@@ -38,12 +29,15 @@ const resizeFooter = () => { |
|
|
chatBox[0].scrollTop = chatBox[0].scrollHeight;
|
|
|
};
|
|
|
|
|
|
// 配置
|
|
|
const msgTypeMap = {
|
|
|
1: 'text',
|
|
|
2: 'picture',
|
|
|
10: 'order'
|
|
|
};
|
|
|
|
|
|
let lastServiceType = 'robot';
|
|
|
let lastMSGTime = null;
|
|
|
|
|
|
var userAvatar = socketConf.defaultUserHead;
|
|
|
|
...
|
...
|
@@ -53,10 +47,6 @@ var chat = { |
|
|
$netTip: null,
|
|
|
|
|
|
msgArr: [],
|
|
|
|
|
|
state: {
|
|
|
lastMSGTime: ''
|
|
|
},
|
|
|
$ratingView: $('#chat-comment'),
|
|
|
|
|
|
|
...
|
...
|
@@ -142,8 +132,9 @@ var chat = { |
|
|
content: $.trim(event.target.value)
|
|
|
}
|
|
|
};
|
|
|
console.log(content)
|
|
|
|
|
|
self.sendMSG(content);
|
|
|
event.target.value = '';
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -165,7 +156,7 @@ var chat = { |
|
|
conversationId: cmEntity.conversationId,
|
|
|
});
|
|
|
}).on('rating-success', function(e, data) {
|
|
|
append(tip(`您对我们的服务评价为:${data}`).onLine());
|
|
|
self._sysInfo(`您对我们的服务评价为:${data}`);
|
|
|
resizeFooter();
|
|
|
});
|
|
|
|
...
|
...
|
@@ -230,7 +221,6 @@ var chat = { |
|
|
|
|
|
let $msg = this._drawMSG(msg);
|
|
|
|
|
|
this.msgArr.push($msg);
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
|
|
|
return this;
|
...
|
...
|
@@ -317,18 +307,31 @@ var chat = { |
|
|
break;
|
|
|
|
|
|
// 系统消息
|
|
|
case allTypes.OFFLINE: break;
|
|
|
case allTypes.TRANSFER: break;
|
|
|
case allTypes.MANUAL_SERVICE: break;
|
|
|
case allTypes.CS_CHANGE_STATE: break;
|
|
|
|
|
|
// ------------------------------------------
|
|
|
// 1. 客服进入
|
|
|
case allTypes.CS_ENTER:
|
|
|
this.sysInfo('客服小YO正在为您服务');
|
|
|
break;
|
|
|
case allTypes.OFFLINE:
|
|
|
this.sysInfo('TODO');
|
|
|
break;
|
|
|
case allTypes.TRANSFER:
|
|
|
this.sysInfo('TODO');
|
|
|
break;
|
|
|
case allTypes.MANUAL_SERVICE:
|
|
|
this.sysInfo('TODO');
|
|
|
break;
|
|
|
case allTypes.CS_CHANGE_STATE:
|
|
|
this.sysInfo('TODO');
|
|
|
break;
|
|
|
default: break;
|
|
|
}
|
|
|
|
|
|
return this;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 订单消息
|
|
|
* 对话消息
|
|
|
* @param 【object|array] viewData 订单消息模版数据
|
|
|
*/
|
|
|
_drawMSG: function(viewData) {
|
...
|
...
|
@@ -341,6 +344,7 @@ var chat = { |
|
|
console.log(viewData);
|
|
|
let $html = $(this.messageT(viewData));
|
|
|
|
|
|
this.checkTime();
|
|
|
$html.appendTo(this.$chatWin);
|
|
|
chatWin.scrollTop = chatWin.scrollHeight;
|
|
|
|
...
|
...
|
@@ -348,6 +352,32 @@ var chat = { |
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 系统消息
|
|
|
*/
|
|
|
_sysInfo: function(msg) {
|
|
|
|
|
|
let $chatWin = this.$chatWin;
|
|
|
let chatWin = $chatWin[0];
|
|
|
|
|
|
if (msg) {
|
|
|
msg = `<div class="change-mm">
|
|
|
<span class="leave-msg">${msg}</span>
|
|
|
</div>`;
|
|
|
} else {
|
|
|
msg = `<div class="leave-msg-wraper">
|
|
|
<span class="leave-msg">您可以选择<a href="javascript:;" data-trigger="leave-msg">留言</a>,客服会以短信形式回复您</span>
|
|
|
</div>`;
|
|
|
}
|
|
|
|
|
|
this.checkTime();
|
|
|
$chatWin.append(msg);
|
|
|
|
|
|
chatWin.scrollTop = chatWin.scrollHeight;
|
|
|
},
|
|
|
|
|
|
checkTime: $.noop,
|
|
|
|
|
|
/**
|
|
|
* method: 根据网络状态 处理动作
|
|
|
* @param {boolean} isSick
|
|
|
*/
|
...
|
...
|
@@ -388,6 +418,13 @@ var chat = { |
|
|
|
|
|
switchService: function(type) {
|
|
|
this.renderHeader(type);
|
|
|
|
|
|
if (type === 'human') {
|
|
|
cmEntity.type = socketConf.recType.MANUAL_SERVICE;
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
} else {
|
|
|
//TODO 切换rebot
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -422,51 +459,8 @@ var chat = { |
|
|
// 刚进入提示
|
|
|
enterSuccess: function(message) {
|
|
|
append(time(Date.now()).show());
|
|
|
append(tip().offLine());
|
|
|
append(tip(message.content).onLine());
|
|
|
},
|
|
|
|
|
|
// 连线人工客服
|
|
|
linkSuccess: function(type, message) {
|
|
|
var status = $('.chat-status'),
|
|
|
name = $('.service-name'),
|
|
|
comment = $('.chat-comment');
|
|
|
|
|
|
if (type === 2 || type === 3) {
|
|
|
status.css('background', '#85be4a');
|
|
|
name.text('YOHO!客服');
|
|
|
comment.css('display', 'inline-block');
|
|
|
append(tip(message.content).onLine());
|
|
|
} else {
|
|
|
name.text('YOHO!客服');
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 用户发消息
|
|
|
handleCusMsg: function(rec, msgType, message) {
|
|
|
// 消去状态
|
|
|
},
|
|
|
|
|
|
// 客服发消息
|
|
|
handleCsMsg: function(rec, msgType, message) {
|
|
|
let cfg = {
|
|
|
style: 'recevied-msg',
|
|
|
avatar: cmEntity.userHead,
|
|
|
};
|
|
|
|
|
|
if (msgType === 2) {
|
|
|
cfg.type = 'picture';
|
|
|
cfg.data = {
|
|
|
src: message.content,
|
|
|
};
|
|
|
} else {
|
|
|
cfg.type = 'text';
|
|
|
cfg.data = {
|
|
|
msg: message.content,
|
|
|
};
|
|
|
}
|
|
|
this._drawMSG(cfg);
|
|
|
resizeFooter();
|
|
|
self._sysInfo();
|
|
|
self._sysInfo(message.content);
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -497,3 +491,4 @@ $('#chat-window').on('click', '.chat-image', function() { |
|
|
|
|
|
window.$ = $;
|
|
|
window.chat = chat;
|
|
|
window.cmEntity = cmEntity |
...
|
...
|
|