evalute.js
8.4 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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">' +
'<img src="../img/10拷贝2@2x_59.png" />' +
'</div>' +
'</div>'
$(".addimg").append(text);
if(imgurl.length == 3) {
$(".imgone").css("display", "none");
}
$("#imghead").attr("src","../img/3@2x.png");
},
error: function() {
}
});
}
//图片2
//function previewImage1(file) {
// var MAXWIDTH = 60;
// var MAXHEIGHT = 60;
// var div = document.getElementById('preview1');
// if(file.files && file.files[0]) {
// div.innerHTML = '<img id=imghead1 onclick=$("#previewImg1").click()>';
// var img = document.getElementById('imghead1');
// 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);
// pic1=res.data;
// console.log(pic1);
// $(".pic1").val(pic1);
// imgurl.push(pic1);
//
// },
// error: function() {
//
// }
// });
//}
//
////图片3
//function previewImage2(file) {
// var MAXWIDTH = 60;
// var MAXHEIGHT = 60;
// var div = document.getElementById('preview2');
// if(file.files && file.files[0]) {
// div.innerHTML = '<img id=imghead2 onclick=$("#previewImg2").click()>';
// var img = document.getElementById('imghead2');
// 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);
// pic2=res.data;
// console.log(pic2);
// $(".pic2").val(pic2);
// imgurl.push(pic1);
// },
// 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.reload();
} else {
alert(res.msg);
}
})
})