view.js
6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
var $ = require('yoho-jquery');
var send = require('./socket/send');
var serviceApi = require('./service-api');
var socketConf = require('./socket/config');
var conMsg = socketConf.conversationMessage;
// 过程标示
var processSign = {
encryptedUid: '',
hasMore: true, // 更多消息
manual: false, // 人工客服
promoter: 1, // 评论发起者 1:客户自己 2:客服
savedEval: false, // 是否保存过评论
scrollLoad: false, // 滚动加载
completeClose: false, // 评价完成后关闭
loadingHistory: false // 加载消息
};
/**
* 获取评价原因
*/
var _fetchReason = (function() {
var cache;
return function(render) {
// 1:企业端 2:YOHO在线客服
// 3:BLK在线客服 4:MARS在线客服 5:机器人
var YOHO_CS = 2;
if (cache) {
return render(cache);
}
serviceApi.reason({
type: YOHO_CS
})
.done(function(res) {
if (res && res.code === 401) {
window.onbeforeunload = null;
return location.href = '//www.yohobuy.com/signin.html?refer=' + // eslint-disable-line
encodeURIComponent(location.href);
}
if (res.code === 200) {
cache = res.data;
render(cache);
}
});
};
}());
/**
* 评价客服view
* @constructor
*/
function Evaluate() {
this.isOpen = false; // 是否已经开启
this.$view = $('#makeEvaluation');
this.disTpl = require('hbs/service/discontent-row.hbs');
this.bindEvents();
this.submitting = false;
}
/**
* 星评
*/
function _starChange(e) {
var i;
var len;
var $el;
var self = this,
$ct = $(e.currentTarget),
index = $ct.index(),
$reason = self.$view.find('.detail-reason'),
$text = self.$view.find('.star-text'),
$list = self.$view.find('.star');
var starText = {
0: '非常不满意',
1: '不满意',
2: '一般',
3: '满意',
4: '非常满意'
};
for (i = 0, len = $list.length; i < len; i++) {
$el = $($list[i]);
$el.index() <= index && $el.addClass('positive');
$el.index() > index && $el.removeClass('positive');
}
index < 3 && $reason.show();
index >= 3 && $reason.hide();
$text.text(starText[index]);
}
/**
* 评价提交
*/
function _evalSubmit() {
var data,
reasonIds,
idArray = [],
self = this,
$btnEval = $('.icon.evaluate'),
$modal = $('#makeEvaluation'),
reason = $modal.find('textarea').val().trim(),
star = $modal.find('.star.positive').length,
reasonTypes = $modal.find('.dis-row .type.chosen');
if (self.submitting) {
return;
}
self.submitting = true;
data = {
conversationId: conMsg.conversationId,
encryptedUid: processSign.encryptedUid,
promoter: processSign.promoter,
stars: star
};
if (star < 4) {
$.each(reasonTypes, function(index, item) {
idArray.push($(item).data('id'));
});
reasonIds = idArray.join(':');
data.reasonIds = reasonIds;
data.reasonMsg = reason;
}
serviceApi.evaluate(data)
.done(function(res) {
$btnEval.hide();
processSign.savedEval = true;
if (res && res.code === 401) {
window.onbeforeunload = null;
return location.href = '//www.yohobuy.com/signin.html?refer=' + // eslint-disable-line
encodeURIComponent(location.href);
}
if (res && res.code === 200) {
send.completeEval();
self.close();
setTimeout(function() {
if (processSign.completeClose) {
window.close();
}
}, 500);
}
})
.always(function() {
self.submitting = false;
});
}
Evaluate.prototype = {
bindEvents: function() {
var self = this;
this.$view.on('click', '.star', _starChange.bind(self))
.on('click', '.submit', _evalSubmit.bind(self))
.on('click', '.dis-row .type', function(e) {
$(e.target).toggleClass('chosen');
})
.on('click', '.close', function() {
self.close();
});
},
open: function(close) {
var self = this;
var _resetEval;
var _show;
if (self.isOpen) {
return;
}
processSign.completeClose = close;
if (!processSign.manual) {
return;
}
_resetEval = function() {
var btnText = close ? '提交并关闭' : '提交';
self.$view.find('.star-text').html('非常满意');
self.$view.find('.star').addClass('positive');
self.$view.find('.other-reason').val('');
self.$view.find('.detail-reason').hide();
self.$view.find('.submit').html(btnText);
};
_show = function(data) {
var i;
var len;
var dom = '';
_resetEval();
self.isOpen = true;
if (!data || !data.length) {
return self.$view.modal('show');
}
for (i = 0, len = data.length; i < len; i = i + 2) {
dom += self.disTpl({
id1: data[i].id,
id1Content: data[i].content,
id2: data[i + 1] && data[i + 1].id,
id2Content: data[i + 1] && data[i + 1].content
});
}
self.$view.find('.discontent').empty().append(dom);
self.$view.modal('show');
};
_fetchReason(_show);
},
close: function() {
this.isOpen = false;
this.$view.modal('hide');
}
};
Evaluate.prototype.constructor = Evaluate;
module.exports = {
processInfo: processSign,
Evaluate: Evaluate
};