common_product.js
8.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
var modelCodeNumber;
var modelName;
var chgownerFlag;
var vhlVal;
var datalist;
var datapy;
var memnerid;
//img
// 图片预览
function productPreviewImage(file)
{
var formData = new FormData();
var fileImgs = $("#previewImg")[0].files;
if(fileImgs.length>5){
showToast('fail','最多只能选择5张图片');
return;
};
for(var i=0; i<fileImgs.length; i++){
formData.append('files[]',fileImgs[i]);
}
formData.append('path','store');
$.ajax({
url:'/products/Product/uploadFileImgs',
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (data) {
var imgarr = JSON.parse(data);
// console.log(imgarr);
$('#img111').textbox('setValue',imgarr[0]);
},
error:function(data){
console.log(data)
}
})
var MAXWIDTH = 90;
var MAXHEIGHT = 90;
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>";
}
}
function productPreviewImage1(file)
{
var formData = new FormData();
var fileImgs = $("#previewImg1")[0].files;
if(fileImgs.length>5){
showToast('fail','最多只能选择5张图片');
return;
};
for(var i=0; i<fileImgs.length; i++){
formData.append('files[]',fileImgs[i]);
}
formData.append('path','store');
$.ajax({
url:'/products/Product/uploadFileImgs',
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (data) {
var imgarr = JSON.parse(data);
// console.log(imgarr);
$('#img222').textbox('setValue',imgarr[0]);
},
error:function(data){
console.log(data)
}
})
var MAXWIDTH = 90;
var MAXHEIGHT = 90;
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=imghead1>';
var img = document.getElementById('imghead1');
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>";
}
}
function productPreviewImage2(file)
{
var formData = new FormData();
var fileImgs = $("#previewImg2")[0].files;
if(fileImgs.length>5){
showToast('fail','最多只能选择5张图片');
return;
};
for(var i=0; i<fileImgs.length; i++){
formData.append('files[]',fileImgs[i]);
}
formData.append('path','store');
$.ajax({
url:'/products/Product/uploadFileImgs',
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (data) {
var imgarr = JSON.parse(data);
// console.log(imgarr);
$('#img333').textbox('setValue',imgarr[0]);
},
error:function(data){
console.log(data)
}
})
var MAXWIDTH = 90;
var MAXHEIGHT = 90;
var div = document.getElementById('preview2');
if (file.files && file.files[0])
{
div.innerHTML ='<img id=imghead2 onclick=$("#previewImg1").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=imghead2>';
var img = document.getElementById('imghead2');
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>";
}
}
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;
}
//列表展示时间
//右侧 数据分页展示
$(function(){
var pager = $('#dg').datagrid().datagrid('getPager'); // get the pager of datagrid
})
//搜索按钮
$('#search_btn').bind('click', function() {
var name = $("#name").val();
var result = {
name
}
init_datagrid('/products/Turn_prize/prize_list', result);
});
function init_datagrid(data_url, res) {
//表头字段
var arr_columns = dg_columns();
$("#dg").datagrid({
rownumbers:true,
singleSelect:true,
pagination:true,
url:data_url,
queryParams: res,
method:'post',
columns: [arr_columns],
loadMsg: '正在加载数据',
emptyMsg: '列表为空',
onDblClickRow :function(rowIndex,rowData){
showSelectedSurveryDataOnMap(rowData);
}
});
}
function dg_columns() {
var arr = new Array();
arr.push({
field: 'name',
title: '名称',
width: 250,
align: 'center'
});
arr.push({
field: 'number',
title: '数量',
width: 200,
align: 'center'
});
arr.push({
field: 'probability',
title: '中奖概率',
width: 250,
align: 'center'
});
arr.push({
field: 'display',
title: '是否发布',
width: 200,
align: 'center'
});
arr.push({
field: 'img',
title: '图片',
width: 215,
align: 'center',
formatter:showImg
});
arr.push({
field: 'addTime',
title: '添加时间',
width: 300,
align: 'center'
});
arr.push({
field: 'addTime',
title: '操作',
width: 200,
align: 'center'
});
// console.log(arr)
return arr;
}
//显示图片
function showImg(value, row, index){
if(row.img){
console.log(row.img)
return "<img style='width:24px;height:24px;' border='1' src='"+row.img+"'/>";
}
}