common_product.js 8.1 KB
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+"'/>";
	}
}