...
|
...
|
@@ -11,6 +11,7 @@ import {time} from './time'; |
|
|
import {api} from './store';
|
|
|
import {RatingView, LeaveMSGView, OrderListView } from './view';
|
|
|
import tip from 'plugin/tip';
|
|
|
import dialog from 'plugin/dialog';
|
|
|
|
|
|
let FastClick = require('yoho-fastclick');
|
|
|
|
...
|
...
|
@@ -112,7 +113,6 @@ let chat = { |
|
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
|
cmEntity.encryptedUid = encryptedUid;
|
|
|
|
|
|
self.fetchHistoryMsg().always(function() {
|
...
|
...
|
@@ -167,7 +167,7 @@ let chat = { |
|
|
onOpen: $.noop,
|
|
|
sendFailCallback: function() {
|
|
|
self._sysInfo('<p>连接断开,请尝试<span class="blue">重连</span></p>')
|
|
|
.one('click', function() {
|
|
|
.one('touchend', function() {
|
|
|
self.connect();
|
|
|
});
|
|
|
},
|
...
|
...
|
@@ -184,8 +184,49 @@ let chat = { |
|
|
*/
|
|
|
bindEvents: function() {
|
|
|
let self = this;
|
|
|
let $dialog;
|
|
|
|
|
|
this.$chat
|
|
|
.on('click.Queue.quit', '[data-trigger=quit-queue]', function() {
|
|
|
dialog.showDialog({
|
|
|
dialogText: '确认结束排队吗?',
|
|
|
hasFooter: {
|
|
|
leftBtnText: '继续等待',
|
|
|
rightBtnText: '结束排队'
|
|
|
}
|
|
|
}, function() {
|
|
|
cmEntity.type = socketConf.recType.QUIT_QUEUE;
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
dialog.hideDialog();
|
|
|
});
|
|
|
|
|
|
$dialog = $('.dialog-wrapper .dialog-box');
|
|
|
$dialog.css({
|
|
|
background: 'hsla(100, 100%, 100%, 1)'
|
|
|
});
|
|
|
|
|
|
})
|
|
|
.on('click.Chat.end', '[data-trigger=end-chat]', function() {
|
|
|
dialog.showDialog({
|
|
|
dialogText: '确认结束本次服务吗?',
|
|
|
hasFooter: {
|
|
|
leftBtnText: '继续咨询',
|
|
|
rightBtnText: '结束服务'
|
|
|
}
|
|
|
}, function() {
|
|
|
cmEntity.type = socketConf.recType.USER_END_CHAT;
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
dialog.hideDialog();
|
|
|
});
|
|
|
|
|
|
$dialog = $('.dialog-wrapper .dialog-box');
|
|
|
$dialog.css({
|
|
|
background: 'hsla(100, 100%, 100%, 1)'
|
|
|
});
|
|
|
})
|
|
|
.on('click.Chat.end', '[data-action=re-connect]', function() {
|
|
|
self.connect();
|
|
|
})
|
|
|
.on('click.Rating.toggle', '[data-trigger=rating]', function() {
|
|
|
if (self.canEvalute) {
|
|
|
self.ratingView.toggle();
|
...
|
...
|
@@ -268,12 +309,14 @@ let chat = { |
|
|
conversationId: cmEntity.conversationId,
|
|
|
});
|
|
|
}).on('rating-success', function(e, data) {
|
|
|
const state = (window.socket || {}).readyState;
|
|
|
|
|
|
self._sysInfo(`您对我们的服务评价为:${data}`);
|
|
|
self.canEvalute = false;
|
|
|
cmEntity.type = socketConf.recType.EVALUTE_SUCCESS;
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
|
|
|
// resizeFooter();
|
|
|
if (state === WebSocket.OPEN) {
|
|
|
socket.send(JSON.stringify(cmEntity));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
...
|
...
|
@@ -322,12 +365,12 @@ let chat = { |
|
|
disconnect(content) {
|
|
|
let self = this;
|
|
|
|
|
|
self.renderHeader('offline');
|
|
|
this.canLeaveMSG = true;
|
|
|
|
|
|
this.$chat.toggleClass('online', false);
|
|
|
this.toggleMenu(false);
|
|
|
this._sysInfo(`<p>${content}<span class="blue">连接客服</span></p>`)
|
|
|
.one('click', function() {
|
|
|
.one('touchend', function() {
|
|
|
self.connect();
|
|
|
});
|
|
|
},
|
...
|
...
|
@@ -576,6 +619,7 @@ let chat = { |
|
|
// ------------------------------------------
|
|
|
// 用户进入
|
|
|
case allTypes.ENTER:
|
|
|
this.renderHeader('robot');
|
|
|
chatMessage.newContent && this._sysInfo(chatMessage.newContent);
|
|
|
break;
|
|
|
|
...
|
...
|
@@ -590,6 +634,11 @@ let chat = { |
|
|
this._sysInfo(chatMessage.content);
|
|
|
break;
|
|
|
|
|
|
case allTypes.QUIT_QUEUE:
|
|
|
this.renderHeader('robot');
|
|
|
this._sysInfo(chatMessage.content);
|
|
|
break;
|
|
|
|
|
|
// 客服邀请评价
|
|
|
case allTypes.EVAL_INVITE:
|
|
|
this._sysInfo('<p data-trigger="rating">请对我们的服务进行<span class="blue">评价</span></p>');
|
...
|
...
|
@@ -636,7 +685,6 @@ let chat = { |
|
|
*/
|
|
|
_manualState(state, cmEntity) { // eslint-disable-line
|
|
|
const self = this;
|
|
|
const $chatHeader = self.$header;
|
|
|
const $chat = self.$chat;
|
|
|
const sysInfo = self._sysInfo.bind(this);
|
|
|
const chatMessage = cmEntity.chatMessage;
|
...
|
...
|
@@ -670,12 +718,13 @@ let chat = { |
|
|
|
|
|
// state 1: 排队中
|
|
|
function inQueue() {
|
|
|
self.renderHeader('queue');
|
|
|
whetherLeaveMsg(cmEntity);
|
|
|
}
|
|
|
|
|
|
// state 2: 人工客服进入
|
|
|
function linkSuccess() {
|
|
|
$chatHeader.find('.js-service-txt').text('YOHO客服');
|
|
|
self.renderHeader('human');
|
|
|
|
|
|
$chat
|
|
|
.toggleClass('online', true)
|
...
|
...
|
@@ -825,7 +874,7 @@ let chat = { |
|
|
},
|
|
|
|
|
|
switchService: function(type) {
|
|
|
this.renderHeader(type);
|
|
|
this.renderHeader(`switch-${type}`);
|
|
|
|
|
|
if (type === 'human') {
|
|
|
cmEntity.type = socketConf.recType.MANUAL_SERVICE;
|
...
|
...
|
@@ -843,9 +892,25 @@ let chat = { |
|
|
title: '智能小YO',
|
|
|
right: '<span data-action="change-human">人工客服</span>'
|
|
|
},
|
|
|
queue: {
|
|
|
title: '<i class="chat-status"></i><span class="js-service-txt">队列中...</span>',
|
|
|
right: '<span data-trigger="quit-queue">结束排队</span>'
|
|
|
},
|
|
|
human: {
|
|
|
title: '<i class="chat-status"></i><span class="js-service-txt">YOHO客服</span>',
|
|
|
right: '<span data-trigger="end-chat">结束服务</span>'
|
|
|
},
|
|
|
offline: {
|
|
|
title: '<i class="chat-status"></i><span class="js-service-txt">YOHO客服</span>',
|
|
|
right: '<span data-action="re-connect">重新连接</span>'
|
|
|
},
|
|
|
'switch-robot': {
|
|
|
title: '<i class="chat-status"></i><span class="js-service-txt">正在连接...</span>',
|
|
|
right: '<span class="chat-rating-trigger" data-trigger="rating">评价</span>'
|
|
|
right: '<span></span>'
|
|
|
},
|
|
|
'switch-human': {
|
|
|
title: '<i class="chat-status"></i><span class="js-service-txt">连接人工...</span>',
|
|
|
right: ''
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|