|
|
/**
|
|
|
* 我的评论
|
|
|
* @author: yyqing<yanqing.yang@yoho.cn>
|
|
|
* @date: 2016/3/1
|
|
|
* @author: liuchuanyang<chuanyang.liu@yoho.cn>
|
|
|
* @date: 2016/10/28
|
|
|
*/
|
|
|
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
|
|
|
var preview = new ImgPreview();
|
|
|
|
|
|
require('../common/ajaxfileupload');
|
|
|
|
|
|
$('.comment-add').on('click', '.btn-submit', function() {
|
|
|
|
|
|
var $f = $(this).closest('.comment-add');
|
|
|
var param = {
|
|
|
productSkn: $f.find('input[name=productSkn]').val(),
|
|
|
productId: $f.find('input[name=productId]').val(),
|
|
|
goodsId: $f.find('input[name=goodsId]').val(),
|
|
|
orderCode: $f.find('input[name=orderCode]').val(),
|
|
|
orderId: $f.find('input[name=orderId]').val(),
|
|
|
erpSkuId: $f.find('input[name=erpSkuId]').val(),
|
|
|
content: $f.find('[name=goodsComment]').val(),
|
|
|
url: $f.find('[name=imgUrl]').val(),
|
|
|
|
|
|
height: $f.find('input[name=height]').val(),
|
|
|
weight: $f.find('input[name=weight]').val(),
|
|
|
satisfied: $f.find('[data-role="star"]').find('.active[data-star]').attr('data-star'),
|
|
|
size: $f.find('[data-role="size"]').find('.active[data-size]').attr('data-size')
|
|
|
};
|
|
|
dialog.maxtop = pageH - $dialog.outerHeight();
|
|
|
dialog.maxleft = pageW - $dialog.outerWidth();
|
|
|
});
|
|
|
|
|
|
$(document).mousemove(function(e) {
|
|
|
var mtop, mleft;
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/home/comment/saveComment',
|
|
|
data: param
|
|
|
}).then(function(jsonData) {
|
|
|
|
|
|
if (!dialog.canmove) {
|
|
|
return;
|
|
|
}
|
|
|
if (jsonData.code === 200) {
|
|
|
//console.log(JSON.stringify(jsonData));
|
|
|
|
|
|
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
|
|
|
} else {
|
|
|
alert(jsonData.message);
|
|
|
}
|
|
|
});
|
|
|
}).mouseup(function() {
|
|
|
dialog.canmove = false;
|
|
|
});
|
|
|
|
|
|
$('.img-preview').on('click', 'i.view', function() {
|
|
|
// 图片预览
|
|
|
$('.img-preview').on('click', 'i.view', function(e) {
|
|
|
|
|
|
var url = $(this).closest('.img-preview').find('img').attr('src');
|
|
|
|
|
|
e.stopPropagation();
|
|
|
preview.preview(url);
|
|
|
});
|
|
|
|
|
|
$dialog.on('click', '.dialog-save-btn', function() {
|
|
|
var remark = $.trim($commentArea.val()),
|
|
|
param;
|
|
|
// 图片删除
|
|
|
$('.img-preview').on('click', 'i.del', function(e) {
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
var $p = $(this).closest('.img-preview');
|
|
|
|
|
|
$dialog.on('click', '.dialog-close-btn', function() {
|
|
|
$optDom.length = 0;
|
|
|
$dialog.addClass('hide');
|
|
|
e.stopPropagation();
|
|
|
$p.removeClass('selected');
|
|
|
$p.find('input[name=imgUrl]').val('');
|
|
|
$p.find('img').attr('src', '');
|
|
|
});
|
|
|
|
|
|
$('.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-add').on('change', 'input[type=file]', function() {
|
|
|
|
|
|
var $f = $(this);
|
|
|
var $p = $f.closest('.img-preview');
|
|
|
|
|
|
if ($f.val()) {
|
|
|
$.ajaxFileUpload({
|
|
|
url: '/common/upload/image',
|
|
|
secureuri: false,
|
|
|
fileElementId: $f,
|
|
|
data: {
|
|
|
bucket: 'sns'
|
|
|
},
|
|
|
dataType: 'json',
|
|
|
success: function(data /* , status */) {
|
|
|
|
|
|
var url, relaUrl;
|
|
|
|
|
|
if (data && data.code === 200 && data.data && data.data.images && data.data.images[0]) {
|
|
|
url = data.data.images[0];
|
|
|
relaUrl = data.data.imagesList[0];
|
|
|
$p.find('img').attr('src', url);
|
|
|
$p.find('input[name=imgUrl]').val(relaUrl);
|
|
|
$p.addClass('selected');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
error: function() { /** data, status, e **/
|
|
|
alert('上传失败,请稍后再试!');
|
|
|
},
|
|
|
complete: function() {
|
|
|
$f.clone().replaceAll($f);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// comment form
|
...
|
...
|
|