comment.js
3.1 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
/**
* 退换货申请
* @author: yyqing<yanqing.yang@yoho.cn>
* @date: 2016/3/1
*/
var $ = require('yoho.jquery');
var $comment = $('.comment-table'),
$remarkBtn = $comment.find('.remark-btn');
var $dialog = $('#comment-dialog-widget'),
$titleBar = $dialog.find('.dialog-titlebar'),
$commentArea = $dialog.find('textarea');
var pageW = $(document).width(),
pageH = $(document).height(),
winH = $(window).height();
var dialog = {
canmove: false,
offset: {},
maxtop: 0,
maxleft: 0
},
orderInfo = {},
$optDom;
// 处理订单数据
$remarkBtn.each(function() {
var $next = $(this).next(),
data = $next.data(),
key = data.orderid;
orderInfo[key] = {};
orderInfo[key].productSkn = data.productskn;
orderInfo[key].productId = data.productid;
orderInfo[key].goodsId = data.goodsid;
orderInfo[key].orderId = data.orderid;
orderInfo[key].erpSkuId = data.erpskuid;
$next.remove();
$(this).data('code', key);
});
$remarkBtn.click(function() {
var scrollTop = $(document).scrollTop();
$optDom = $(this);
$commentArea.val('');
$dialog.removeClass('hide').css({
top: scrollTop + (winH - $dialog.outerHeight()) / 2,
left: (pageW - $dialog.outerWidth()) / 2
});
});
// 评论弹窗
$titleBar.bind('mousedown', function(e) {
if ($(e.target).hasClass('dialog-close-btn')) {
return;
}
dialog.canmove = true;
dialog.offset = {
x: e.offsetX,
y: e.offsetY
};
dialog.maxtop = pageH - $dialog.outerHeight();
dialog.maxleft = pageW - $dialog.outerWidth();
});
$(document).mousemove(function(e) {
var mtop, mleft;
if (!dialog.canmove) {
return;
}
mtop = e.pageY - dialog.offset.y;
mleft = e.pageX - dialog.offset.x;
mtop = mtop < dialog.maxtop ? mtop : dialog.maxtop;
mleft = mleft < dialog.maxleft ? mleft : dialog.maxleft;
$dialog.css({
top: mtop > 0 ? mtop : 0,
left: mleft > 0 ? mleft : 0
});
}).mouseup(function(e) {
dialog.canmove = false;
});
$dialog.on('click', '.dialog-save-btn', function() {
var remark = $.trim($commentArea.val()),
param;
if (remark === '') {
alert('请添加评论内容');
return;
}
if ($optDom.length) {
param = orderInfo[$optDom.data().code];
param.content = remark;
$.ajax({
type: 'POST',
url: '/home/comment/saveComment',
data: param
}).then(function(jsonData) {
var $par = $optDom.parent();
if (jsonData.code === 200) {
$par.prev().text(remark);
$par.html('<span class="remarked">已评论!</span>');
$optDom.length = 0;
$dialog.addClass('hide');
} else {
alert(jsonData.message);
}
});
}
});
$dialog.on('click', '.dialog-close-btn', function() {
$optDom.length = 0;
$dialog.addClass('hide');
});