comment.page.js
6 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
/**
* 我的评论
* @author: yyqing<yanqing.yang@yoho.cn>
* @date: 2016/3/1
*/
var $ = require('yoho-jquery');
var ImgPreview = require('../common/img-preview');
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(),
preview = new ImgPreview();
var dialog = {
canmove: false,
offset: {},
maxtop: 0,
maxleft: 0
},
orderInfo = {},
$optDom;
require('../plugins/jquery.qupload');
// 处理订单数据
$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() {
dialog.canmove = false;
});
$('.img-preview').on('click', 'i.view', function() {
var url = $(this).closest('.img-preview').find('img').attr('src');
preview.preview(url);
});
$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');
});
$('.comment-add input[type="file"]').each(function(i, it) {
var $this = $(it),
$par = $this.closest('.problem-description');
if (!window.location.origin) {
window.location.origin = window.location.protocol + '//' +
window.location.hostname + (window.location.port ? ':' + window.location.port : '');
}
alert(window.location.origin);
$this.qupload({
button_image_url: '',
upload_url: window.location.origin + '/home/returns/imgUpload',
file_post_name: 'fileData',
button_text: '<span class="btn_upload_text">上传图片</span>',
button_text_style: '.btn_upload_text{color: #ffffff;}',
button_width: 60,
button_height: 60,
button_text_left_padding: 32,
button_text_top_padding: 8,
button_action: window.SWFUpload.BUTTON_ACTION.SELECT_FILE,
file_size_limit: '10240',
file_types: '*.jpg;*.jpeg;*.png;*.bmp',
uploadSuccessed: function(data) {
var $imgList = $par.find('li'),
isShow = false,
img, _html;
img = JSON.parse(data).imgList[0];
_html = '<span class="btn-del" title="删除"></span>' +
'<img src="' + img[0] + '" width="126" height="126">' +
'<input type="hidden" name="imgs" value="' + img.imgRelUrl + '">';
$imgList.each(function() {
if (!isShow && !$(this).find('img').length) {
isShow = true;
$(this).html(_html);
}
});
}
});
});
// comment form
$('.comment-table').on('click', '[data-role="showCommentForm"]', function() {
// $('[data-role="showCommentForm"]).
var $ntr = $(this).closest('tr').next('tr');
if ($ntr.attr('data-role') === 'commentAddForm') {
$ntr.toggle();
}
});
// star
$('.comment-table').on('click', '.comment-star.editable > span', function() {
$(this).parent().find('span').removeClass('active');
$(this).addClass('active');
});
// btn group
$('.comment-add').on('click', ' .btn-group .btn', function() {
$(this).siblings('.btn').removeClass('active');
$(this).addClass('active');
});
// goods comment textarea
$('.comment-table').on('focus', '[data-role="goodsCommentWrap"] textarea', function() {
$(this).parent().find('.text-tip').hide();
});
$('.comment-table').on('blur', '[data-role="goodsCommentWrap"] textarea', function() {
if (!$(this).val()) {
$(this).parent().find('.text-tip').show();
}
});
$('.comment-table').on('click', '[data-role="goodsCommentWrap"] .text-tip', function() {
$(this).parent().find('textarea').focus();
});
$('.comment-table').find('[data-role="goodsCommentWrap"] textarea').trigger('blur');