Authored by 李奇

评价优化

@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 </div> 22 </div>
23 </div> 23 </div>
24 <div class="cus-footer"> 24 <div class="cus-footer">
25 - <button class="btn dark submit">提交</button> 25 + <button class="btn dark submit">提交并关闭</button>
26 <input type="hidden" name="promoter" value="1"> 26 <input type="hidden" name="promoter" value="1">
27 </div> 27 </div>
28 </div> 28 </div>
@@ -9,17 +9,18 @@ @@ -9,17 +9,18 @@
9 9
10 var $ = require('yoho-jquery'), 10 var $ = require('yoho-jquery'),
11 uuid = require('uuid'), 11 uuid = require('uuid'),
12 - editArea = require('./edit-area'),  
13 serviceApi = require('./service-api'), 12 serviceApi = require('./service-api'),
14 broswer = require('./broswer'), 13 broswer = require('./broswer'),
15 cursor = require('./cursor'), 14 cursor = require('./cursor'),
  15 + view = require('./view'),
16 send = require('./socket/send'), 16 send = require('./socket/send'),
17 edit = require('./socket/edit'), 17 edit = require('./socket/edit'),
18 receive = require('./socket/receive'), 18 receive = require('./socket/receive'),
19 util = require('./utility'), 19 util = require('./utility'),
  20 + clipPaste = require('./clip-paste'),
20 socketChat = require('./socket/chat'), 21 socketChat = require('./socket/chat'),
21 socketConf = require('./socket/config'), 22 socketConf = require('./socket/config'),
22 - clipPaste = require('./clip-paste'); 23 + processInfo = require('./view').processInfo;
23 24
24 var allRTs, 25 var allRTs,
25 endTime, 26 endTime,
@@ -52,16 +53,6 @@ var tipTpl = require('hbs/service/tip.hbs'), @@ -52,16 +53,6 @@ var tipTpl = require('hbs/service/tip.hbs'),
52 robotTpl = require('hbs/service/robot-msg.hbs'), 53 robotTpl = require('hbs/service/robot-msg.hbs'),
53 disTpl = require('hbs/service/discontent-row.hbs'); 54 disTpl = require('hbs/service/discontent-row.hbs');
54 55
55 -var processInfo = {  
56 - scrollLoad: false,  
57 - loadingHistory: false,  
58 - hasMore: true,  
59 - manual: false,  
60 - completeClose: false, // 评价完成后关闭  
61 - promoter: 1, // 评论发起者 1:客户自己 2:客服  
62 - savedEval: false // 是否保存过评论  
63 -};  
64 -  
65 require('bootstrap'); 56 require('bootstrap');
66 require('../common'); 57 require('../common');
67 require('blueimp-file-upload/js/jquery.iframe-transport'); 58 require('blueimp-file-upload/js/jquery.iframe-transport');
@@ -74,12 +65,17 @@ encryptedUid = $encryptedUid.val(); @@ -74,12 +65,17 @@ encryptedUid = $encryptedUid.val();
74 assetsPrefix = $assetsPrefix.val(); 65 assetsPrefix = $assetsPrefix.val();
75 socketConfCM = socketConf.conversationMessage; 66 socketConfCM = socketConf.conversationMessage;
76 socketConfCM.encryptedUid = encryptedUid; 67 socketConfCM.encryptedUid = encryptedUid;
  68 +processInfo.encryptedUid = encryptedUid;
77 69
78 // 原始配置信息用于重新连线 70 // 原始配置信息用于重新连线
79 originConf = JSON.parse(JSON.stringify(socketConf)); 71 originConf = JSON.parse(JSON.stringify(socketConf));
80 72
81 // 页面初始化 73 // 页面初始化
82 var _loadPage = function() { 74 var _loadPage = function() {
  75 +
  76 + // 客服评价
  77 + var evalView = new view.Evaluate();
  78 +
83 /** 79 /**
84 * 添加新的消息 80 * 添加新的消息
85 */ 81 */
@@ -144,7 +140,6 @@ var _loadPage = function() { @@ -144,7 +140,6 @@ var _loadPage = function() {
144 var $area = $('.msg-area'), 140 var $area = $('.msg-area'),
145 msg = $area.val().trim(); 141 msg = $area.val().trim();
146 142
147 - // 发送前共通处理  
148 beforeSendMsg(); 143 beforeSendMsg();
149 144
150 if (!msgContent) { 145 if (!msgContent) {
@@ -220,7 +215,7 @@ var _loadPage = function() { @@ -220,7 +215,7 @@ var _loadPage = function() {
220 systemTip(message.content); 215 systemTip(message.content);
221 216
222 // 显示人工客服 217 // 显示人工客服
223 - editArea.setIcons({ 218 + edit.setIcons({
224 'manual-service': true 219 'manual-service': true
225 }); 220 });
226 } 221 }
@@ -258,7 +253,7 @@ var _loadPage = function() { @@ -258,7 +253,7 @@ var _loadPage = function() {
258 }); 253 });
259 254
260 // 隐藏人工 255 // 隐藏人工
261 - editArea.setIcons({ 256 + edit.setIcons({
262 'manual-service': false 257 'manual-service': false
263 }); 258 });
264 break; 259 break;
@@ -273,7 +268,7 @@ var _loadPage = function() { @@ -273,7 +268,7 @@ var _loadPage = function() {
273 processInfo.manual = true; 268 processInfo.manual = true;
274 269
275 // 显示评价&隐藏人工 270 // 显示评价&隐藏人工
276 - editArea.setIcons({ 271 + edit.setIcons({
277 emoji: true, 272 emoji: true,
278 image: true, 273 image: true,
279 evaluate: true, 274 evaluate: true,
@@ -287,11 +282,10 @@ var _loadPage = function() { @@ -287,11 +282,10 @@ var _loadPage = function() {
287 content: tipText 282 content: tipText
288 }); 283 });
289 284
290 - // 接入人工客服需要评价  
291 processInfo.manual = true; 285 processInfo.manual = true;
292 286
293 // 显示评价&隐藏人工 287 // 显示评价&隐藏人工
294 - editArea.setIcons({ 288 + edit.setIcons({
295 emoji: true, 289 emoji: true,
296 image: true, 290 image: true,
297 evaluate: true, 291 evaluate: true,
@@ -401,53 +395,6 @@ var _loadPage = function() { @@ -401,53 +395,6 @@ var _loadPage = function() {
401 } 395 }
402 396
403 /** 397 /**
404 - * 显示评价弹框  
405 - */  
406 - function showEvalModal(cptClose) {  
407 - var $evalModal = $('#makeEvaluation');  
408 -  
409 - // 评价完成后关闭  
410 - processInfo.completeClose = cptClose;  
411 -  
412 - // 没有接入人工  
413 - if (!processInfo.manual) {  
414 - return;  
415 - }  
416 -  
417 - // 评价原因  
418 - function discontentHtml(len, data) {  
419 - var i,  
420 - dom = '';  
421 -  
422 - for (i = 0; i < len; i = i + 2) {  
423 - dom += disTpl({  
424 - id1: data[i].id,  
425 - id1Content: data[i].content,  
426 - id2: data[i + 1] && data[i + 1].id,  
427 - id2Content: data[i + 1] && data[i + 1].content  
428 - });  
429 - }  
430 -  
431 - $evalModal.find('.discontent').empty().append(dom);  
432 - }  
433 -  
434 - // 拉取评价原因  
435 - serviceApi.reason({  
436 - conversationId: socketConfCM.conversationId  
437 - })  
438 - .done(function(res) {  
439 - var data = res.data,  
440 - len = data.length;  
441 -  
442 - if (res && res.code === 200) {  
443 - // 评价原因  
444 - len && discontentHtml(len, data);  
445 - }  
446 - $evalModal.modal('show');  
447 - });  
448 - }  
449 -  
450 - /**  
451 * 处理收到消息 398 * 处理收到消息
452 */ 399 */
453 function getMessage(rec) { 400 function getMessage(rec) {
@@ -465,7 +412,7 @@ var _loadPage = function() { @@ -465,7 +412,7 @@ var _loadPage = function() {
465 412
466 if (isHidden) { 413 if (isHidden) {
467 titleInterval = setInterval(function() { 414 titleInterval = setInterval(function() {
468 - document.title = '您有新消息'; 415 + document.title = '您有新消息';
469 setTimeout(function() { 416 setTimeout(function() {
470 document.title = docTitle; 417 document.title = docTitle;
471 }, 300); 418 }, 300);
@@ -511,10 +458,9 @@ var _loadPage = function() { @@ -511,10 +458,9 @@ var _loadPage = function() {
511 break; 458 break;
512 459
513 case allTypes.EVAL_INVITE: 460 case allTypes.EVAL_INVITE:
514 - // 客服发起  
515 if (!processInfo.savedEval) { 461 if (!processInfo.savedEval) {
516 processInfo.promoter = 2; 462 processInfo.promoter = 2;
517 - showEvalModal(); 463 + evalView.open();
518 } 464 }
519 break; 465 break;
520 466
@@ -524,7 +470,7 @@ var _loadPage = function() { @@ -524,7 +470,7 @@ var _loadPage = function() {
524 470
525 case allTypes.OP_LEAVE: 471 case allTypes.OP_LEAVE:
526 socketChat.clear(); 472 socketChat.clear();
527 - editArea.setIcons({ 473 + edit.setIcons({
528 emoji: false, 474 emoji: false,
529 image: false 475 image: false
530 }); 476 });
@@ -533,7 +479,7 @@ var _loadPage = function() { @@ -533,7 +479,7 @@ var _loadPage = function() {
533 479
534 case allTypes.OFFLINE: 480 case allTypes.OFFLINE:
535 socketChat.clear(); 481 socketChat.clear();
536 - editArea.setIcons({ 482 + edit.setIcons({
537 emoji: false, 483 emoji: false,
538 image: false 484 image: false
539 }); 485 });
@@ -578,14 +524,14 @@ var _loadPage = function() { @@ -578,14 +524,14 @@ var _loadPage = function() {
578 }, 524 },
579 525
580 onOpen: function() { 526 onOpen: function() {
581 - editArea.setIcons({ 527 + edit.setIcons({
582 evaluate: false, 528 evaluate: false,
583 'manual-service': false 529 'manual-service': false
584 }); 530 });
585 }, 531 },
586 532
587 onClose: function() { 533 onClose: function() {
588 - editArea.setIcons({ 534 + edit.setIcons({
589 emoji: false, 535 emoji: false,
590 image: false, 536 image: false,
591 evaluate: false, 537 evaluate: false,
@@ -783,57 +729,57 @@ var _loadPage = function() { @@ -783,57 +729,57 @@ var _loadPage = function() {
783 }); 729 });
784 }); 730 });
785 731
786 - // 提交评价  
787 - $makeEvalModal.find('.submit').click(function() {  
788 -  
789 - var $btnEval = $('.icon.evaluate'),  
790 - mEval = $('#makeEvaluation'),  
791 - reason = mEval.find('textarea').val().trim(),  
792 - star = mEval.find('.star.positive').length,  
793 - reasonTypes = mEval.find('.dis-row .type.chosen');  
794 -  
795 - var data = {  
796 - conversationId: socketConfCM.conversationId,  
797 - encryptedUid: encryptedUid,  
798 - promoter: processInfo.promoter,  
799 - stars: star  
800 - };  
801 -  
802 - var reasonIds,  
803 - idArray = [];  
804 -  
805 - if (star < 4) {  
806 - $.each(reasonTypes, function(index, item) {  
807 - idArray.push($(item).data('id'));  
808 - });  
809 -  
810 - reasonIds = idArray.join(':');  
811 - data.reasonIds = reasonIds;  
812 - data.reasonMsg = reason;  
813 - }  
814 -  
815 - serviceApi.evaluate(data)  
816 - .done(function(res) {  
817 - processInfo.promoter = 1;  
818 - $btnEval.hide();  
819 - processInfo.savedEval = true;  
820 -  
821 - if (res && res.code === 200) {  
822 - // 评价后通知客服  
823 - socketConfCM.type = allRTs.EVAL_NOTICE;  
824 - socketConfCM.uuid = uuid.v4();  
825 - socketChat.send(socketConfCM);  
826 -  
827 - // 完成后关闭  
828 - if (processInfo.completeClose) {  
829 - window.close();  
830 - }  
831 - }  
832 - })  
833 - .always(function() {  
834 - mEval.modal('hide');  
835 - });  
836 - }); 732 + // // 提交评价
  733 + // $makeEvalModal.find('.submit').click(function() {
  734 +
  735 + // var $btnEval = $('.icon.evaluate'),
  736 + // mEval = $('#makeEvaluation'),
  737 + // reason = mEval.find('textarea').val().trim(),
  738 + // star = mEval.find('.star.positive').length,
  739 + // reasonTypes = mEval.find('.dis-row .type.chosen');
  740 +
  741 + // var data = {
  742 + // conversationId: socketConfCM.conversationId,
  743 + // encryptedUid: encryptedUid,
  744 + // promoter: processInfo.promoter,
  745 + // stars: star
  746 + // };
  747 +
  748 + // var reasonIds,
  749 + // idArray = [];
  750 +
  751 + // if (star < 4) {
  752 + // $.each(reasonTypes, function(index, item) {
  753 + // idArray.push($(item).data('id'));
  754 + // });
  755 +
  756 + // reasonIds = idArray.join(':');
  757 + // data.reasonIds = reasonIds;
  758 + // data.reasonMsg = reason;
  759 + // }
  760 +
  761 + // serviceApi.evaluate(data)
  762 + // .done(function(res) {
  763 + // processInfo.promoter = 1;
  764 + // $btnEval.hide();
  765 + // processInfo.savedEval = true;
  766 +
  767 + // if (res && res.code === 200) {
  768 + // // 评价后通知客服
  769 + // socketConfCM.type = allRTs.EVAL_NOTICE;
  770 + // socketConfCM.uuid = uuid.v4();
  771 + // socketChat.send(socketConfCM);
  772 +
  773 + // // 完成后关闭
  774 + // if (processInfo.completeClose) {
  775 + // window.close();
  776 + // }
  777 + // }
  778 + // })
  779 + // .always(function() {
  780 + // mEval.modal('hide');
  781 + // });
  782 + // });
837 783
838 // 根节点高度设置 784 // 根节点高度设置
839 $html.css({ 785 $html.css({
@@ -944,41 +890,6 @@ var _loadPage = function() { @@ -944,41 +890,6 @@ var _loadPage = function() {
944 } 890 }
945 }); 891 });
946 892
947 - // 星评  
948 - $document.on('click', '.make-eval .star', function() {  
949 - var el,  
950 - i,  
951 - len,  
952 - tag = $(this),  
953 - index = tag.index(),  
954 - $detailReason = $('.detail-reason'),  
955 - textEl = $('.make-eval .star-text'),  
956 - startList = $('.make-eval .stars .star');  
957 -  
958 - var starText = {  
959 - 0: '非常不满意',  
960 - 1: '不满意',  
961 - 2: '一般',  
962 - 3: '满意',  
963 - 4: '非常满意'  
964 - };  
965 -  
966 - for (i = 0, len = startList.length; i < len; i++) {  
967 - el = $(startList[i]);  
968 - el.index() <= index && el.addClass('positive');  
969 - el.index() > index && el.removeClass('positive');  
970 - }  
971 -  
972 - index < 3 && $detailReason.show();  
973 - index >= 3 && $detailReason.hide();  
974 - textEl.text(starText[index]);  
975 - });  
976 -  
977 - // 选择不满意类型  
978 - $document.on('click', '.dis-row .type', function(e) {  
979 - $(e.target).toggleClass('chosen');  
980 - });  
981 -  
982 // 留言 893 // 留言
983 $msgList.on('click', '.leave-msg', leaveMsg); 894 $msgList.on('click', '.leave-msg', leaveMsg);
984 895
@@ -1008,7 +919,7 @@ var _loadPage = function() { @@ -1008,7 +919,7 @@ var _loadPage = function() {
1008 }, 919 },
1009 920
1010 2: function() { 921 2: function() {
1011 - showEvalModal(); 922 + evalView.open();
1012 }, 923 },
1013 924
1014 3: function() { 925 3: function() {
@@ -1051,7 +962,7 @@ var _loadPage = function() { @@ -1051,7 +962,7 @@ var _loadPage = function() {
1051 $close.click(function() { 962 $close.click(function() {
1052 if (processInfo.manual && !processInfo.savedEval) { 963 if (processInfo.manual && !processInfo.savedEval) {
1053 // 没有保存过评论 964 // 没有保存过评论
1054 - showEvalModal(true); 965 + evalView.open(true);
1055 } else { 966 } else {
1056 window.close(); 967 window.close();
1057 } 968 }
@@ -28,14 +28,14 @@ var $view = '<div class="mask-dialog preview-dialog">' + @@ -28,14 +28,14 @@ var $view = '<div class="mask-dialog preview-dialog">' +
28 '</div>'; 28 '</div>';
29 29
30 var $viewHbs = Handlebars.compile($view); 30 var $viewHbs = Handlebars.compile($view);
31 - 31 +
32 /** 32 /**
33 * 粘贴事件 33 * 粘贴事件
34 * @param sl 事件元素选择器 34 * @param sl 事件元素选择器
35 * @param cb 上传成功的回调 35 * @param cb 上传成功的回调
36 */ 36 */
37 function Paste(sl, cb) { 37 function Paste(sl, cb) {
38 - if(typeof sl !== 'string') { return }; 38 + if (typeof sl !== 'string') { return; }
39 this.$el = document.querySelector(sl); 39 this.$el = document.querySelector(sl);
40 this.formData = null; 40 this.formData = null;
41 this.uploadCb = cb; 41 this.uploadCb = cb;
@@ -47,33 +47,33 @@ Paste.prototype = { @@ -47,33 +47,33 @@ Paste.prototype = {
47 bindEvents: function() { 47 bindEvents: function() {
48 var self = this; 48 var self = this;
49 49
50 - this.$el.addEventListener("paste", function (e) { 50 + this.$el.addEventListener('paste', function(e) {
51 var cbd = e.clipboardData; 51 var cbd = e.clipboardData;
52 var ua = window.navigator.userAgent; 52 var ua = window.navigator.userAgent;
53 53
54 // 如果是 Safari 直接 return 54 // 如果是 Safari 直接 return
55 - if ( !(e.clipboardData && e.clipboardData.items) ) { 55 + if (!(e.clipboardData && e.clipboardData.items)) {
56 return; 56 return;
57 } 57 }
58 - 58 +
59 // Mac平台下Chrome49版本以下 复制Finder中的文件的Bug Hack掉 59 // Mac平台下Chrome49版本以下 复制Finder中的文件的Bug Hack掉
60 - if(cbd.items && cbd.items.length === 2 && cbd.items[0].kind === "string" && cbd.items[1].kind === "file" &&  
61 - cbd.types && cbd.types.length === 2 && cbd.types[0] === "text/plain" && cbd.types[1] === "Files" &&  
62 - ua.match(/Macintosh/i) && Number(ua.match(/Chrome\/(\d{2})/i)[1]) < 49){ 60 + if (cbd.items && cbd.items.length === 2 && cbd.items[0].kind === 'string' && cbd.items[1].kind === 'file' &&
  61 + cbd.types && cbd.types.length === 2 && cbd.types[0] === 'text/plain' && cbd.types[1] === 'Files' &&
  62 + ua.match(/Macintosh/i) && Number(ua.match(/Chrome\/(\d{2})/i)[1]) < 49) {
63 return; 63 return;
64 } 64 }
65 65
66 - for(var i = 0; i < cbd.items.length; i++) { 66 + for (var i = 0; i < cbd.items.length; i++) {
67 var item = cbd.items[i]; 67 var item = cbd.items[i];
68 - if(item.kind == "file"){  
69 - var file = item.getAsFile(); 68 + if (item.kind == 'file') {
  69 + var file = item.getAsFile();
70 if (file.size === 0) { return; } 70 if (file.size === 0) { return; }
71 71
72 self.formData = new FormData(); 72 self.formData = new FormData();
73 self.formData.append('files[]', file, 'clip.jpg'); 73 self.formData.append('files[]', file, 'clip.jpg');
74 74
75 var _upload = function() { 75 var _upload = function() {
76 - if(self.isSending) return; 76 + if (self.isSending) return;
77 self.isSending = true; 77 self.isSending = true;
78 78
79 $.ajax({ 79 $.ajax({
@@ -103,14 +103,14 @@ Paste.prototype = { @@ -103,14 +103,14 @@ Paste.prototype = {
103 103
104 $prev.on('click', '.head-close, .cancel-btn', self.close.bind(self)) 104 $prev.on('click', '.head-close, .cancel-btn', self.close.bind(self))
105 .on('click', '.confirm-btn', _upload); 105 .on('click', '.confirm-btn', _upload);
106 - } 106 + };
107 107
108 var _drawPreview = function(url) { 108 var _drawPreview = function(url) {
109 - var $prev = $('.preview-dialog'); 109 + var $prev = $('.preview-dialog');
110 var $img = $prev.find('.clip-img'); 110 var $img = $prev.find('.clip-img');
111 var len = $img.length; 111 var len = $img.length;
112 112
113 - if(len) { 113 + if (len) {
114 $img.attr('src', url); 114 $img.attr('src', url);
115 self.$preview = $prev; 115 self.$preview = $prev;
116 return; 116 return;
@@ -127,14 +127,14 @@ Paste.prototype = { @@ -127,14 +127,14 @@ Paste.prototype = {
127 127
128 var reader = new FileReader(); 128 var reader = new FileReader();
129 reader.onload = function(e) { 129 reader.onload = function(e) {
130 - var base64 = e.target.result; 130 + var base64 = e.target.result;
131 var image = new Image(); 131 var image = new Image();
132 image.src = base64; 132 image.src = base64;
133 image.onload = function() { 133 image.onload = function() {
134 _drawPreview(base64); 134 _drawPreview(base64);
135 - self.open();  
136 - }  
137 - } 135 + self.open();
  136 + };
  137 + };
138 138
139 reader.readAsDataURL(file); 139 reader.readAsDataURL(file);
140 } 140 }
@@ -147,10 +147,9 @@ Paste.prototype = { @@ -147,10 +147,9 @@ Paste.prototype = {
147 }, 147 },
148 148
149 close: function() { 149 close: function() {
150 - console.log(this);  
151 this.$preview.hide(); 150 this.$preview.hide();
152 } 151 }
153 -} 152 +};
154 153
155 Paste.prototype.constructor = Paste; 154 Paste.prototype.constructor = Paste;
156 155
1 -/**  
2 - * 消息编辑区  
3 - * @author: liqi <qi.li@yoho.cn>  
4 - * @date: 2016/11/26  
5 - */  
6 -  
7 -var $ = require('yoho-jquery');  
8 -  
9 -module.exports = {  
10 - /**  
11 - * 消息编辑区图标显示  
12 - * true: 显示 false: 隐藏  
13 - */  
14 - setIcons: function(opt) {  
15 - var $util = $('.msg-edit .util');  
16 -  
17 - $.each(opt, function(key, val) {  
18 - var $el = $util.find('.' + key);  
19 -  
20 - if (!$el.length || !val && val !== false) {  
21 - return;  
22 - }  
23 - val === true && $el.show();  
24 - val === false && $el.hide();  
25 - });  
26 - }  
27 -};  
28 -  
@@ -18,7 +18,10 @@ var _ajax = function(method, reqUrl, params) { @@ -18,7 +18,10 @@ var _ajax = function(method, reqUrl, params) {
18 type: method || 'GET', 18 type: method || 'GET',
19 url: reqUrl, 19 url: reqUrl,
20 data: params 20 data: params
21 - }); 21 + })
  22 + .fail(function() {
  23 + alert('服务器开小差了,请稍后重试。');
  24 + });
22 }; 25 };
23 26
24 /** 27 /**
@@ -89,7 +89,7 @@ function sendMsg(msg) { @@ -89,7 +89,7 @@ function sendMsg(msg) {
89 return; 89 return;
90 } 90 }
91 91
92 - if (socket.readyState === WebSocket.OPEN) { 92 + if (socket && socket.readyState === WebSocket.OPEN) {
93 socket.send(JSON.stringify(msg)); 93 socket.send(JSON.stringify(msg));
94 } else { 94 } else {
95 options.socketClosedCb(); 95 options.socketClosedCb();
@@ -97,6 +97,14 @@ function sendMsg(msg) { @@ -97,6 +97,14 @@ function sendMsg(msg) {
97 } 97 }
98 98
99 /** 99 /**
  100 + * 链接可用
  101 + * @returns {*|boolean}
  102 + */
  103 +function isOpen() {
  104 + return socket && socket.readyState === WebSocket.OPEN;
  105 +}
  106 +
  107 +/**
100 * 关闭socket 108 * 关闭socket
101 */ 109 */
102 function clearSocket() { 110 function clearSocket() {
@@ -109,6 +117,7 @@ module.exports = { @@ -109,6 +117,7 @@ module.exports = {
109 socket: socket, 117 socket: socket,
110 init: socketInit, 118 init: socketInit,
111 clear: clearSocket, 119 clear: clearSocket,
112 - send: sendMsg 120 + send: sendMsg,
  121 + isOpen: isOpen
113 }; 122 };
114 123
@@ -13,7 +13,7 @@ exports.setEmoji = function(e) { @@ -13,7 +13,7 @@ exports.setEmoji = function(e) {
13 var $em = $('.emoji-component'); 13 var $em = $('.emoji-component');
14 14
15 $.each(emMap, function(i, v) { 15 $.each(emMap, function(i, v) {
16 - if(v.file === emId + "") { 16 + if (v.file === emId + '') {
17 emText = v.text; 17 emText = v.text;
18 } 18 }
19 }); 19 });
@@ -21,3 +21,21 @@ exports.setEmoji = function(e) { @@ -21,3 +21,21 @@ exports.setEmoji = function(e) {
21 $em.hide(); 21 $em.hide();
22 }; 22 };
23 23
  24 +/**
  25 + * 消息编辑区图标控制
  26 + * true: 显示 false: 隐藏
  27 + */
  28 +exports.setIcons = function(opt) {
  29 + var $util = $('.msg-edit .util');
  30 +
  31 + $.each(opt, function(key, val) {
  32 + var $el = $util.find('.' + key);
  33 +
  34 + if (!$el.length || !val && val !== false) {
  35 + return;
  36 + }
  37 + val === true && $el.show();
  38 + val === false && $el.hide();
  39 + });
  40 +};
  41 +
@@ -28,3 +28,14 @@ exports.image = function(path) { @@ -28,3 +28,14 @@ exports.image = function(path) {
28 conMSG.uuid = uuid.v4(); 28 conMSG.uuid = uuid.v4();
29 _send(conMSG); 29 _send(conMSG);
30 }; 30 };
  31 +
  32 +/**
  33 + * 评价完成
  34 + */
  35 +exports.completeEval = function() {
  36 + if (chat.isOpen()) {
  37 + conMSG.type = recTypes.EVAL_NOTICE;
  38 + conMSG.uuid = uuid.v4();
  39 + _send(conMSG);
  40 + }
  41 +};
  1 +var $ = require('yoho-jquery');
  2 +var send = require('./socket/send');
  3 +var serviceApi = require('./service-api');
  4 +var socketConf = require('./socket/config');
  5 +var conMsg = socketConf.conversationMessage;
  6 +
  7 +
  8 +// 过程标示
  9 +var processSign = {
  10 + encryptedUid: '',
  11 + hasMore: true, // 更多消息
  12 + manual: false, // 人工客服
  13 + promoter: 1, // 评论发起者 1:客户自己 2:客服
  14 + savedEval: false, // 是否保存过评论
  15 + scrollLoad: false, // 滚动加载
  16 + completeClose: false, // 评价完成后关闭
  17 + loadingHistory: false // 加载消息
  18 +};
  19 +
  20 +/**
  21 + * 评价客服view
  22 + * @constructor
  23 + */
  24 +function Evaluate() {
  25 + this.$view = $('#makeEvaluation');
  26 + this.disTpl = require('hbs/service/discontent-row.hbs');
  27 + this.bindEvents();
  28 +}
  29 +
  30 +/**
  31 + * 获取评价原因
  32 + */
  33 +var _fetchReason = (function() {
  34 + var cache;
  35 +
  36 + return function(render) {
  37 + if (cache) return render(cache);
  38 + serviceApi.reason({
  39 + conversationId: conMsg.conversationId
  40 + })
  41 + .done(function(res) {
  42 + if (res.code === 200) {
  43 + cache = res.data;
  44 + render(cache);
  45 + } else {
  46 + alert(res.message);
  47 + }
  48 + });
  49 + };
  50 +})();
  51 +
  52 +/**
  53 + * 星评
  54 + */
  55 +var _starChange = function(e) {
  56 + var self = this,
  57 + $ct = $(e.currentTarget),
  58 + index = $ct.index(),
  59 + $reason = self.$view.find('.detail-reason'),
  60 + $text = self.$view.find('.star-text'),
  61 + $list = self.$view.find('.star');
  62 +
  63 + var starText = {
  64 + 0: '非常不满意',
  65 + 1: '不满意',
  66 + 2: '一般',
  67 + 3: '满意',
  68 + 4: '非常满意'
  69 + };
  70 +
  71 + for (var i = 0, len = $list.length; i < len; i++) {
  72 + var $el = $($list[i]);
  73 + $el.index() <= index && $el.addClass('positive');
  74 + $el.index() > index && $el.removeClass('positive');
  75 + }
  76 +
  77 + index < 3 && $reason.show();
  78 + index >= 3 && $reason.hide();
  79 + $text.text(starText[index]);
  80 +};
  81 +
  82 +/**
  83 + * 评价提交
  84 + */
  85 +var _evalSubmit = function() {
  86 + var $btnEval = $('.icon.evaluate'),
  87 + mEval = $('#makeEvaluation'),
  88 + reason = mEval.find('textarea').val().trim(),
  89 + star = mEval.find('.star.positive').length,
  90 + reasonTypes = mEval.find('.dis-row .type.chosen');
  91 +
  92 + var data = {
  93 + conversationId: conMsg.conversationId,
  94 + encryptedUid: processSign.encryptedUid,
  95 + promoter: processSign.promoter,
  96 + stars: star
  97 + };
  98 +
  99 + var reasonIds,
  100 + idArray = [];
  101 +
  102 + if (star < 4) {
  103 + $.each(reasonTypes, function(index, item) {
  104 + idArray.push($(item).data('id'));
  105 + });
  106 +
  107 + reasonIds = idArray.join(':');
  108 + data.reasonIds = reasonIds;
  109 + data.reasonMsg = reason;
  110 + }
  111 +
  112 + serviceApi.evaluate(data)
  113 + .done(function(res) {
  114 + $btnEval.hide();
  115 + processSign.savedEval = true;
  116 +
  117 + if (res && res.code === 200) {
  118 + send.completeEval();
  119 +
  120 + // 完成后关闭
  121 + if (processSign.completeClose) {
  122 + window.close();
  123 + }
  124 + }
  125 + })
  126 + .always(function() {
  127 + mEval.modal('hide');
  128 + });
  129 +};
  130 +
  131 +Evaluate.prototype = {
  132 + bindEvents: function() {
  133 + var self = this;
  134 +
  135 + this.$view.on('click', '.star', _starChange.bind(self))
  136 + .on('click', '.submit', _evalSubmit)
  137 + .on('click', '.dis-row .type', function(e) {
  138 + $(e.target).toggleClass('chosen');
  139 + });
  140 + },
  141 +
  142 + open: function(close) {
  143 + var self = this;
  144 +
  145 + processSign.completeClose = close;
  146 + if (!processSign.manual) {
  147 + return;
  148 + }
  149 +
  150 + var _resetEval = function() {
  151 + self.$view.find('.star-text').html('非常满意');
  152 + self.$view.find('.star').addClass('positive');
  153 + self.$view.find('.other-reason').val('');
  154 + self.$view.find('.detail-reason').hide();
  155 + };
  156 +
  157 + var _show = function(data) {
  158 + var dom = '';
  159 +
  160 + _resetEval();
  161 + if (!data || !data.length) return self.$view.modal('show');
  162 + for (var i = 0, len = data.length; i < len; i = i + 2) {
  163 + dom += self.disTpl({
  164 + id1: data[i].id,
  165 + id1Content: data[i].content,
  166 + id2: data[i + 1] && data[i + 1].id,
  167 + id2Content: data[i + 1] && data[i + 1].content
  168 + });
  169 + }
  170 +
  171 + self.$view.find('.discontent').empty().append(dom);
  172 + self.$view.modal('show');
  173 + };
  174 +
  175 + _fetchReason(_show);
  176 + },
  177 +
  178 + close: function() {
  179 + this.$view.modal('hide');
  180 + }
  181 +};
  182 +
  183 +Evaluate.prototype.constructor = Evaluate;
  184 +
  185 +
  186 +module.exports = {
  187 + processInfo: processSign,
  188 + Evaluate: Evaluate
  189 +};