<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css"rel="stylesheet" type="text/css" />
<title>修改商品</title>
</head>
<body>
<div class="pd-20">
	<form action="${pageContext.request.contextPath }/admin/goods/updateGoods" class="form form-horizontal" id="form-addGoods" method="POST" enctype="multipart/form-data">
	<input name="goodsInfoId" type="hidden" value="${goodsGoodinfo.goodsInfoId }">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>商品名称：</label>
			<div class="formControls col-10">
				<input id="goodsInfoGoodname" name="goodsInfoGoodname" value="${goodsGoodinfo.goodsInfoGoodname }" type="text" class="input-text" value="" placeholder="" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">商品简称：</label>
			<div class="formControls col-10">
				<input id="goodsInfoDescname" name="goodsInfoDescname" value="${goodsGoodinfo.goodsInfoDescname }" type="text" class="input-text"  placeholder="">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>商品类型：</label>
			<div class="formControls col-2"> <span class="select-box">
				<select id="goodstype" name="goodsInfoType" class="select" onchange="showHidden();">
				<option value="1" ${goodsGoodinfo.goodsInfoType==1?'selected':''}>销售产品</option>
				<option value="2" ${goodsGoodinfo.goodsInfoType==2?'selected':''}>积分产品</option>
				</select>
				</span> 
			</div>
			<label id="integralLabel" class="form-label col-2" style="display: none">所需积分：</label>
			<div id="integralDiv" class="formControls col-2" style="display: none">
				<input id="integral" name="goodsInfoIntegralNum" type="text" value="${goodsGoodinfo.goodsInfoIntegralNum }" class="input-text" placeholder="" >
			</div>
		</div>
		<div class="row cl">
		<label class="form-label col-2"><span class="c-red">*</span>所属分类：</label>
			<div class="formControls col-2"> <span class="select-box">
				<select id="" name="goodsInfoTId" class="select" >
					<c:forEach items="${typeNameList }" var="infolist">
					<option value="${infolist.goodTypeId }" ${goodsGoodinfo.goodsInfoType==infolist.goodTypeId?'selected':''}>${infolist.goodTypename }</option>
				</c:forEach>
				</select>
				</span> 
			</div>
			<label class="form-label col-2">商品重量：</label>
			<div class="formControls col-4">
				<input id="goodsInfoWeight"  type="text" name="goodsInfoWeight" value="${goodsGoodinfo.goodsInfoWeight }" id="" placeholder="" class="input-text" style="width:90%">kg</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">商品原价：</label>
			<div class="formControls col-2">
				<input id="goodsInfoPrice" type="text" name="goodsInfoPrice" id="" placeholder="" value="${goodsGoodinfo.goodsInfoPrice }" class="input-text" style="width:90%">元</div>
			<label class="form-label col-2">商品优惠价：</label>
			<div class="formControls col-2">
				<input id="goodsInfoDiscount" type="text" name="goodsInfoDiscount" id="" placeholder="" value="${goodsGoodinfo.goodsInfoDiscount }" class="input-text" style="width:90%">元</div>
		</div>
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2">品牌：</label>
			<div id="integralDiv" class="formControls col-2">
				<input id="goodsInfoBrand" name="goodsInfoBrand" type="text" class="input-text" value="${goodsGoodinfo.goodsInfoBrand }" placeholder="">
			</div>
			<label id="integralLabel" class="form-label col-2">商品原料：</label>
			<div id="integralDiv" class="formControls col-2">
				<input id="goodsInfoIngredients" name="goodsInfoIngredients" type="text" class="input-text" value="${goodsGoodinfo.goodsInfoIngredients }" placeholder="">
			</div>
		</div>
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2">是否推荐上首页：</label>
			<div class="formControls col-2"> <span class="select-box">
				<select id="goodsInfoIndex" name="goodsInfoIndex" class="select">
						<option value="1" ${goodsGoodinfo.goodsInfoIndex==1?'selected':''} >推荐到首页</option>
						<option value="2" ${goodsGoodinfo.goodsInfoIndex==2?'selected':''}>不推荐到首页</option>
				</select>
				</span> 
			</div>
			<label class="form-label col-2">产地：</label>
			<div  class="formControls col-2">
				<input id="goodsInfoOrigin" name="goodsInfoOrigin" value="${goodsGoodinfo.goodsInfoOrigin }" type="text" class="input-text" value="" placeholder="">
			</div>
		</div>
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2">安装方式：</label>
			<div  class="formControls col-2">
				<input id="goodsInfoInstallation" name="goodsInfoInstallation" value="${goodsGoodinfo.goodsInfoInstallation }" type="text" class="input-text" value="" placeholder="">
			</div>
			<label class="form-label col-2">寿命：</label>
			<div  class="formControls col-2">
				<input id="goodsInfoLife" name="goodsInfoLife" value="${goodsGoodinfo.goodsInfoLife }" type="text" class="input-text" value="" placeholder="">
			</div>
		</div>
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2">是否属于净水机：</label>
			<div class="formControls col-2"> <span class="select-box">
				<select id="goodsInfoIs" name="goodsInfoIs" class="select">
						<option value="1" ${goodsGoodinfo.goodsInfoIs==1?'selected':''}>属于净水机</option>
						<option value="2" ${goodsGoodinfo.goodsInfoIs==2?'selected':''}>滤芯</option>
						<option value="3" ${goodsGoodinfo.goodsInfoIs==3?'selected':''}>其他</option>
				</select>
				</span> 
			</div>
		</div>
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2">保质期：</label>
			<div id="integralDiv" class="formControls col-2">
				<input id="goodsInfoShelf" name="goodsInfoShelf" type="text" class="input-text" value="${goodsGoodinfo.goodsInfoShelf }" placeholder="">天
			</div>
			<label id="integralLabel" class="form-label col-2">备注：</label>
			<div id="integralDiv" class="formControls col-2">
				<textarea id="" name="goodsInfoNote" class="textarea-text" placeholder="">${goodsGoodinfo.goodsInfoNote }</textarea>
			</div>
		</div>
		<div class="row cl">
		<label class="form-label col-2"><span class="c-red">*</span>包装类型：</label>
			<div id="integralDiv" class="formControls col-2">
				<input id="goodsInfoPackagingType" name="goodsInfoPackagingType" type="text" class="input-text" value="${goodsGoodinfo.goodsInfoPackagingType }" placeholder="">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">商品介绍：</label>
			<div class="formControls col-5"> 
				<textarea id="goodsInfoGooddesc" name="goodsInfoGooddesc" cols="" rows="" class="textarea">${goodsGoodinfo.goodsInfoGooddesc }</textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">商品封面图：</label>
			<div class="col-10 ">
				<input type="file" name="file" size="50"><img style="border:2px solid #0A6999;" id="goodsimage" src="${pageContext.request.contextPath }${goodsGoodinfo.goodsInfoDescImage }" width="50" height="50"></img>
				<input type="hidden" name="goodsInfoDescImage" value="${goodsGoodinfo.goodsInfoDescImage } " >
			</div>
			
			<label class="form-label col-2">商品介绍图：</label>
			<input id="goodsImaLength" type="hidden" value="${fn:length(goodsImage)}">
			<input name="goodsimages" class="urlClass1" type="text" id="url" value="" /> <i class="Hui-iconfont">&#xe642;</i> <input type="button" class="addImagesClass btn btn-primary radius upload-btn" id="imageFile1" value="选择图片" />
				<c:forEach items="${goodsImage }" var="infolist">
					<img style="border:2px solid #0A6999;"  src="${infolist.goodsImageUrl }" onclick="deleteImg(${infolist.goodsImageId },this)" width="50" height="50"></img>
				</c:forEach>
		</div>
		<div id="spots" class="row cl">
		<label class="form-label col-2"></label> 
			<input id="addimages" type="button" class="btn btn-primary radius upload-btn" value="新增介绍图" />
		</div>
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button id="submit" onClick="return admin_updateGoods();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/tips.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/ueditor.all.min.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/ueditor.config.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/common/js/utils/tools.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/js/utils/jquery-1.9.1.min.js"></script>
<script charset="utf-8" src="/ratfw/common/other/kingedit/kindeditor-min.js"></script>
<script charset="utf-8" src="/ratfw/common/other/kingedit/lang/zh_CN.js"></script> 	
<script type="text/javascript">
	KindEditor.ready(function(K) {
        window.editor = K.create('#goodsInfoGooddesc',{
        	fileManagerJson : '/ratfw/common/other/kingedit/jsp/file_manager_json.jsp',
            uploadJson : '/ratfw/common/other/kingedit/jsp/upload_json.jsp',
             allowFileManager : true,
             width : '920px'
         });
	});
</script>
<script type="text/javascript">
$(document).ready(function(){
	//回显商品类型
	showHidden();
	//绑定上传事件
	addBtnEvent(1);
	var imagelength =  $("#goodsImaLength").val();
	var ids = document.getElementsByName('goodsimages').length;
		if(Number(imagelength)+Number(ids)>=10) {
			$("input#addimages").hide();
		}
		$("input#addimages").click(function(){     
			  addSpot(this);
		});
})

function addSpot(obj) {
		var goodsimagess = document.getElementsByName('goodsimages').length;
		var sm = (10 - $("#goodsImaLength").val());
		var ids = "imageFile"+(goodsimagess+1);
		var urls = "url"+(goodsimagess+1);
		var imagesClass = "urlClass"+(goodsimagess+1);
		$('div#spots').before(
			'<div class="row cl">'+
			'<label class="form-label col-2"></label>'+
		    '<input name="goodsimages" class='+imagesClass+' type="text" id='+urls+'/>'+
		    '&nbsp;<i class="Hui-iconfont">&#xe642;</i>&nbsp;'+
		    '<input type="button" class="addImagesClass btn btn-primary radius upload-btn" id='+ids+' value="选择图片" />' +
		    '&nbsp;<input type="button" class="remove btn btn-primary radius upload-btn" onclick="removes(this)" value="删除" /></div>')
		//新增完成后在获取上传组件的个数
		var goodsimage = document.getElementsByName('goodsimages').length;
		  if(goodsimage >= sm) {
			  	$("input#addimages").hide();
			  }
			//给新增的按钮绑定事件
			addBtnEvent((goodsimagess+1));
		};
		//删除新增的按钮
		function removes(obj){
			$(obj).parent().remove();
			$("input#addimages").show();
		}
		
		function addBtnEvent(goodsimagess){
			KindEditor.ready(function(K) {
				var editor = K.editor({
		        	fileManagerJson : '/ratfw/common/other/kingedit/jsp/file_manager_json.jsp',
		            uploadJson : '/ratfw/common/other/kingedit/jsp/upload_json.jsp',
					allowFileManager : true
				});
				K('#imageFile'+goodsimagess).click(function() {
				     var imgid = $(this).attr("id");//获取当前ID
				   var imagesClass =  "urlClass"+imgid.substr(imgid.length-1,1);
					editor.loadPlugin('image', function() {
						editor.plugin.imageDialog({
							showRemote : false,
							imageUrl : K('.'+imagesClass).val(),
							clickFn : function(url, title, width, height, border, align) {
								K('.'+imagesClass).val(url);
								editor.hideDialog();
								return false; 
							}
						});
					});
				}); 
				
			});
        }
//控制所需积分显示或隐藏
function showHidden(){
	var showhidden = $("#goodstype").val();
	if(showhidden == "2"){
		document.getElementById("integralDiv").style.display="";//隐藏
		document.getElementById("integralLabel").style.display="";//隐藏
		$("#integralLabel").val("");//清空所需积分的值
	}else{
		document.getElementById("integralDiv").style.display="none";//显示
		document.getElementById("integralLabel").style.display="none";//显示
	}
}
function deleteImg(imgId,obj){
	layer.confirm('确定要删除吗？',function(index){
		var _this = $(obj);
		$.ajax({
	        url: '${pageContext.request.contextPath }/admin/goods/deleteGoodsImage',
	        type: "POST",
	        dataType: "json",
	        data: {objVal : imgId},
	        error:function(){
	      	  layer.msg(data.status,{icon: 5,time:1000});
	        },
	        success:  function(data){
	      	  layer.msg(data.status,{icon: 1,time:1000});
	      		_this.remove();
	      		var goodsimagess = document.getElementsByName('goodsimages').length;
	      		var imagelength =  (Number($("#goodsImaLength").val())-1);//将当前的图片个数减一并添加到该隐藏域
	      		$("#goodsImaLength").val(imagelength);
	      		if(Number(goodsimagess)+Number(imagelength)<10){
	      			$("input#addimages").show();//显示图片新增按钮
	      		}
	        }
	    	});
		});
}
/*商品-添加*/
function admin_updateGoods(){
			 //商品名称数据验证
			if(!commonLengthJdg('goodsInfoGoodname',1,30,null,true)){
				layer.msg("商品名称长度为1-30位",{icon: 5,time:3000});
				return;
			}
			 //商品简称数据验证
			if(!commonLengthJdg('goodsInfoDescname',1,10,null,true)){
				layer.msg("商品简称长度为1-10位",{icon: 5,time:3000});
				return;
			}
			 //商品简称数据验证
			if(!commonLengthJdg('goodsInfoDescname',1,10,null,true)){
				layer.msg("商品简称长度为1-10位",{icon: 5,time:3000});
				return;
			}
			if($("#goodstype").val() == 2){
				//所需积分数据验证
				if(!commonLengthJdg('integral',1,9,null,true)){
					layer.msg("所需积分长度为1-9位",{icon: 2,time:3000});
					return false;
				}
				if(!commonTypeJdg('integral','money',null,true)){
					layer.msg("积分不能为空或格式错误",{icon: 2,time:3000});
					return false;
				}
			}
			 //商品重量数据验证
			if(!commonLengthJdg('goodsInfoWeight',1,100,null,true)){
				layer.msg("商品重量长度为1-100位",{icon: 5,time:3000});
				return;
			}
			 //商品原价数据验证
			if(!commonTypeJdg('goodsInfoPrice','money',null,true)){
				layer.msg("商品原价须为金钱格式",{icon: 5,time:3000});
				return;
			}
			 //商品优惠价数据验证
			if(!commonTypeJdg('goodsInfoDiscount','money',null,true)){
				layer.msg("商品优惠价须为金钱格式",{icon: 5,time:3000});
				return;
			}
			 //品牌数据验证
			if(!commonLengthJdg('goodsInfoBrand',1,100,null,true)){
				layer.msg("品牌长度为1-50位",{icon: 5,time:3000});
				return;
			}
			 //商品原料数据验证
			if(!commonLengthJdg('goodsInfoIngredients',1,500,null,true)){
				layer.msg("商品原料长度为1-250位",{icon: 5,time:3000});
				return;
			}
			 //保质期数据验证
			if(!commonLengthJdg('goodsInfoShelf',1,10,null,true)){
				layer.msg("保质期长度为1-5位",{icon: 5,time:3000});
				return;
			}
			//商品包装数据验证
			if(!commonLengthJdg('goodsInfoPackagingType',1,10,null,true)){
				layer.msg("商品包装长度为1-5位",{icon: 2,time:3000});
				return false;
			}
			//场地数据验证
			if(!commonLengthJdg('goodsInfoOrigin',1,10,null,true)){
				layer.msg("场地长度为1-5位",{icon: 2,time:2000});
				return false;
			}
			//安装方式数据验证
			if(!commonLengthJdg('goodsInfoInstallation',1,10,null,true)){
				layer.msg("安装方式长度为1-5位",{icon: 2,time:2000});
				return false;
			}
			//寿命数据验证
			if(!commonLengthJdg('goodsInfoLife',1,10,null,true)){
				layer.msg("寿命长度为1-5位",{icon: 2,time:2000});
				return false;
			}
}
</script>
</body>
</html>