evalute.js
4.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
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
var pic = '';
var pic1 = '';
var pic2 = '';
var oid = GetQueryString('oid');
console.log(oid);
var imgurl = [];
//图片1
function previewImage(file) {
var MAXWIDTH = 50;
var MAXHEIGHT = 50;
var div = document.getElementById('preview');
if(file.files && file.files[0]) {
div.innerHTML = '<img id=imghead onclick=$("#previewImg").click()>';
var img = document.getElementById('imghead');
img.onload = function() {
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
img.width = rect.width;
img.height = rect.height;
// img.style.marginLeft = rect.left+'px';
img.style.marginTop = rect.top + 'px';
}
var reader = new FileReader();
reader.onload = function(evt) {
img.src = evt.target.result;
}
reader.readAsDataURL(file.files[0]);
} else //兼容IE
{
var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
file.select();
var src = document.selection.createRange().text;
div.innerHTML = '<img id=imghead>';
var img = document.getElementById('imghead');
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);
div.innerHTML = "<div id=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;margin-top:" + rect.top + "px;" + sFilter + src + "\"'></div>";
}
var formData = new FormData();
var fileM = document.querySelector("#previewImg");
var fileObj = fileM.files[0];
formData.append("files", fileObj);
$.ajax({
url: 'http://hula.wx.bronet.cn/index.php/MyComment/upload',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(res) {
console.log(res);
pic = res.data;
console.log(pic);
imgurl.push(pic);
console.log(imgurl)
var text = '';
text += '<div class="evaluate_pic_item" style="float:left">' +
'<img src="' + pic + '" class="delimg"/>' +
'<div class="icon">' +
'</div>' +
'</div>'
$(".addimg").append(text);
if(imgurl.length == 3) {
$(".imgone").css("display", "none");
}
$("#imghead").attr("src","../img/3@2x.png");
},
error: function() {
}
});
}
function clacImgZoomParam(maxWidth, maxHeight, width, height) {
var param = {
top: 0,
left: 0,
width: width,
height: height
};
if(width > maxWidth || height > maxHeight) {
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if(rateWidth > rateHeight) {
param.width = maxWidth;
param.height = Math.round(height / rateWidth);
} else {
param.width = Math.round(width / rateHeight);
param.height = maxHeight;
}
}
param.left = Math.round((maxWidth - param.width) / 2);
param.top = Math.round((maxHeight - param.height) / 2);
return param;
}
//删除图片
$(".addimg").on("click",".icon",function(){
var url=$(this).siblings(".delimg").attr("src");
for(var i=0;i<imgurl.length;i++){
if(url==imgurl[i]){
imgurl.splice(i, 1);
console.log(imgurl)
}
}
$(this).parent().remove();
if(imgurl.length==0){
console.log($(".imgone"))
$(".imgone").css("display","block");
$("#imghead").attr("src","../img/3@2x.png");
$("#imghead").css("width","50px");
$("#imghead").css("height","50px");
}
})
//提交按钮
$(".footer").click(function() {
var comment_content = $(".evalutecontent").val();
if(comment_content == '') {
alert("请填写评价内容");
return false;
}
//if(imgurl == '') {
// alert("请选择图片");
// return false;
//}
console.log(imgurl.join(','));
// var img = JSON.stringify(imgurl);
var url = '/MyComment/comment'
var params = {
oid: oid,
unique_id: localStorage.getItem('unique_id'),
comment_content: comment_content,
comment_photo: imgurl.join(',')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.status == true) {
alert("评论成功");
window.location.href='/index.php?g=&m=template&a=finishdetails&oid='+oid;
} else {
alert(res.msg);
}
})
})