Authored by 李奇

评价原因添加

... ... @@ -206,4 +206,33 @@ exports.queryGlobalOrder = (req, res) => {
});
};
/**
* Request: 获取评价原因
* type: GET
* params:
* cvId 会话id
*/
exports.queryReasons = (req, res) => {
let uid = req.user.uid;
if (!uid) {
uid = req.body.uid;
}
const cvId = req.query.conversationId;
console.log('body', cvId);
imApi.queryReasons(cvId)
.then(result=> {
res.json(result);
})
.catch(() => {
return res.json({
code: 500,
message: '拉取评价原因失败'
});
});
};
... ...
... ... @@ -133,3 +133,15 @@ exports.queryGlobalOrder = uid => {
return ImService.get('/api/order/queryGlobalOrder', params);
};
/**
* 获取评价原因
* @param cvId 会话ID
*/
exports.queryReasons = cvId => {
let params = {
conversationId: cvId
};
return ImService.get('/api/evalute/queryReasonByConversationId', params);
};
... ...
... ... @@ -24,6 +24,7 @@ router.get('/im/fetchHistory', chat.fetchHistory);
router.get('/getOrders', chat.getOrders);
router.get('/im/global-list', chat.queryGlobalOrder);
router.get('/im/order-list', chat.fetchOrders);
router.get('/im/queryReasons', chat.queryReasons);
router.post('/leavemsg/save.json', chat.saveMSG);
router.post('/im/saveEvalute', chat.saveEvalute);
... ...
... ... @@ -9,8 +9,15 @@
<i></i>
<i></i>
</div>
<div class="rank"> </div>
<textarea class="words-to-say" maxlength="50" placeholder="还想吐槽下(选填)"></textarea>
<div class="rank"></div>
<div class="more-comment">
<div class="cause">
{{#each causeList}}
<span>{{value}}</span>
{{/each}}
</div>
<textarea class="words-to-say" maxlength="50" placeholder="还想吐槽下(选填)"></textarea>
</div>
<button class="submit">提交</button>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -109,7 +109,7 @@ var chat = {
// 组件
this.leaveMSGView = new LeaveMSGView('#leave-msg');
this.orderListView = new OrderListView('#order-list');
this.ratingView = new RatingView('#chat-comment');
this.ratingView = new RatingView('#chat-comment', cmEntity);
const self = this;
... ...
... ... @@ -86,6 +86,11 @@ let api = {
saveEvalute: function(data) {
data.uid = uid;
return $.post('/service/im/saveEvalute', data);
},
// 获取评价原因
queryReasons: function(data) {
return $.get('/service/im/queryReasons', data);
}
};
... ...
... ... @@ -87,14 +87,16 @@ LeaveMSGView.prototype.constructer = LeaveMSGView;
/*
评价view
*/
const RatingView = function(elem, socket) {
const RatingView = function(elem, cmEntity) {
this.elem = $(elem);
this.$ranks = this.elem.find('.stars i');
this.$label = this.elem.find('.rank');
this.$more = this.elem.find('.more-comment');
this.cmEntity = cmEntity;
this.rank = 3;
this.bindEvents();
this.socket = socket;
this.isSending = false;
this.reasonsRendered = false;
};
RatingView.prototype = $.extend({}, EventEmitter.prototype, {
... ... @@ -110,7 +112,66 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
self.rating(starVal);
})
.on('click.RatingView.close', '.close', $.proxy(this.toggle, this, false));
.on('click.RatingView.close', '.close', $.proxy(this.toggle, this, false))
.on('moreComment.toggle', '.more-comment', function(event, starVal) {
let $this = $(this);
let visible = $this.is(':visible');
if (starVal < 3 && visible) {
return;
}
$this.find('.words-to-say').val('');
$this.find('.cause span').removeClass('select');
if (starVal < 3) {
let cvId = self.cmEntity.conversationId;
return self.renderReasons(cvId);
}
$this.hide();
})
.on('click.CauseItem.SelectToggle', '.cause span', function() {
let $this = $(this);
$this.toggleClass('select');
});
},
renderReasons(cvId) {
let self = this;
if (self.reasonsRendered) {
self.$more.show();
return;
}
// 评价原因渲染
api.queryReasons({
conversationId: cvId
})
.done(res => {
if (res && res.code === 200) {
let $html;
let cause = [];
res.data.forEach((item) => {
cause.push(`<span data-id="${item.id}">${item.content}</span>`);
});
$html = cause.join('');
self.$more.find('.cause').append($html);
self.reasonsRendered = true;
self.$more.show();
return;
}
tip.show('拉取评价原因失败');
})
.fail(()=> {
tip.show('拉取评价原因失败');
});
},
rating(starVal) {
... ... @@ -130,6 +191,9 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
this.$ranks.toggleClass(index => {
return index <= starVal ? 'rated' : null;
});
// added for customer service v1.2 optimization
this.$more.trigger('moreComment.toggle', starVal);
},
post(data) {
... ... @@ -144,9 +208,18 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
var params = {
stars: ++this.rank,
promoter: 1,
reasonIds: '',
reasonMsg: elem.find('.words-to-say').val(),
};
let temp = [];
let $select = self.$more.find('.cause span.select');
[].forEach.call($select, (item) => {
temp.push($(item).data('id'));
});
params.reasonIds = temp.join(':');
Object.assign(params, data);
api.saveEvalute(params)
... ...
... ... @@ -12,7 +12,6 @@
&-inner {
position: absolute;
bottom: 0;
height: 586px;
width: 100%;
background: #fff;
padding: 0 30px;
... ... @@ -61,10 +60,39 @@
color: #b0b0b0;
}
.cause {
font-size: 0;
span {
position: relative;
display: inline-block;
margin: 10px;
width: 328px;
width: calc(50% - 20px);
font-size: 28px;
border: 1px solid #000;
line-height: 70px;
text-align: center;
border-radius: 5px;
}
.select:after {
position: absolute;
bottom: -1px;
right: -1px;
width: 30px;
height: 30px;
content: "";
display: inline-block;
background: resolve("service/chat/cause-select.png");
background-size: cover;
}
}
.words-to-say {
height: 110px;
width: 100%;
margin: 50px 0 0;
margin: 10px 0 0;
padding: 16px;
resize: none;
border: 1px solid #e0e0e0;
... ... @@ -74,7 +102,7 @@
.submit {
height: 85px;
width: 100%;
margin: 25px 0 0;
margin: 25px 0;
color: #fff;
background: #444;
font-size: 32px;
... ...