{include file="page_header.htm"}
{insert_scripts files="../js/utils.js,../js/DatePicker/WdatePicker.js"}

<div id="tabbody-div">
	<form enctype="multipart/form-data" name="theForm" action="product.php" method="post" onsubmit="return validate()">
	{foreach from=$product_info item=list name=product}
	<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="table_form1" {if $smarty.foreach.product.index>0} style="display:none" {/if} id="language_{$list.language_id}-table">	
		<tr>
		<td class="label" width="120">产品名称:</td>
    <td width="310">
			<input name="name_{$list.language_id}" type="text" value="{$list.name|escape}" class="FormSmall" style="width:200px;"  />
			<span class="required">&nbsp;</span>
		</td>
		
		<td class="label" width="110">产品分类:</td>
		<td width="310">
			<select name="category_id_{$list.language_id}" class="category_select" id="category_id_{$list.language_id}" style="padding-top:3px; padding-bottom:3px;">
			<option value="0">--选择产品分类--</option>
				{foreach from=$list.category_tree item=val}
				<option value="{$val.category_id}"{if $val.category_id == $product.category_id} selected{/if}>{'--'|str_repeat:$val.level}{$val.name}</option>
				{/foreach}
			</select>
			<span class="required">&nbsp;</span>
		</td>
		</tr>
		
		{if $smarty.foreach.product.index == 0}
		<tr>
		<td class="label">型号:</td>
		<td><input name="model" type="text" value="{$product.model|escape}"  class="FormSmall" style="width:100px;" /></td>
		<td class="label">最小订单量:</td>
		<td><input name="minimum" type="text" value="{$product.minimum|escape}" class="FormSmall"  style="width:100px;" />（请填写整数）</td>
		</tr>
			
		<tr>
		<td class="label">市场价格:</td>
		<td><input name="market_price" type="text" value="{$product.market_price|escape}" class="FormSmall" style="width:100px;" />（请填写价格，如：598.00）</td>
		<td class="label">销售价格:</td>
		<td><input name="shop_price" type="text" value="{$product.shop_price|escape}" class="FormSmall" style="width:100px;" />（请填写价格，如：598.00）</td>
		</tr>			

		<tr>
		<td class="label">库存:</td>
		<td><input name="quantity" type="text" value="{$product.quantity|escape}" class="FormSmall" style="width:100px;" />（请填写整数）</td>
		<td class="label">重量:</td>
		<td>
		<input name="weight" type="text" value="{$product.weight|escape}" class="FormSmall" style="width:80px;" />
		<select name="weight_unit" style="width:70px;" class="select_input">
		<option value="1" {if $weight_unit == 1} selected="selected"{/if}>千克</option>
		<option value="0.001" {if $weight_unit == 0.001} selected="selected"{/if}>克</option>
		</select>
		</td>		
		</tr>
		
		<tr>
		<td class="label"><a href="#" title="产品是自主研发或生产的，还是代理的？"><img src="images/help.gif" border="0" /></a>&nbsp;产品性质:</td>
		<td>
		<select name="product_nature" class="select_input">
		<option value="">--选择--</option>
		<option value="independent" {if $product.product_nature == 'independent'} selected="selected"{/if}>自主</option>
		<option value="agent" {if $product.agent == 'agent'} selected="selected"{/if}>代理</option>
		</select>
		</td>
		<td class="label"><a href="#" title="您的产品主要针对哪里的客户？"><img src="images/help.gif" border="0" /></a>&nbsp;主要针对的客户市场:</td>
		<td>
		<select name="customer_market" class="select_input">
		<option value="">--选择--</option>
		{foreach from=$country item=c_item}
		<option value="{$c_item.region_id}" {if $product.customer_market == $c_item.region_id}} selected="selected"{/if}>{$c_item.region_name}</option>
		{/foreach}
		</select>		
		</td>		
		</tr>		
		
		<tr>
		<td class="label"><a href="#" title="产品与别人不同的地方表现在哪方面？"><img src="images/help.gif" border="0" /></a>&nbsp;产品核心差异化表现:</td>
		<td>
		<select name="differentiated_performance" class="select_input">
		<option value="">--选择--</option>
		<option value="price" {if $product.differentiated_performance == 'price'} selected="selected"{/if}>价格</option>
		<option value="function" {if $product.differentiated_performance == 'function'} selected="selected"{/if}>功能</option>
		<option value="quality" {if $product.differentiated_performance == 'quality'} selected="selected"{/if}>质量</option>
		<option value="service" {if $product.differentiated_performance == 'service'} selected="selected"{/if}>服务</option>
		<option value="technology" {if $product.differentiated_performance == 'technology'} selected="selected"{/if}>技术</option>
		<option value="innovation" {if $product.differentiated_performance == 'innovation'} selected="selected"{/if}>创新</option>
		</select>
		</td>
		<td class="label"><a href="#" title="您的产品在哪个区域最有优势？在“其它”里可填入具体细分区域"><img src="images/help.gif" border="0" /></a>&nbsp;区域优势:</td>
		<td>
		<select name="regional_advantage" style="width:70px;" class="select_input">
		<option value="">--选择--</option>
		{foreach from=$country item=c_item}
		<option value="{$c_item.region_id}" {if $product.regional_advantage == $c_item.region_id} selected="selected"{/if}>{$c_item.region_name}</option>
		{/foreach}
		</select><span class="required">&nbsp;</span>
		其它:<input name="regional_advantage_other" type="text" value="{$product.regional_advantage_other|escape}"  class="FormSmall" style="width:100px;" />
		</td>		
		</tr>	

		
		<tr>
		<td class="label"><a href="#" title="在区域优势里的排名情况"><img src="images/help.gif" border="0" /></a>&nbsp;荣誉排名:</td>
		<td>
		<div style="float:left;">
		<select name="honor_rank"  class="select_input">
		<option value="">--选择--</option>
		<option value="first" {if $product.honor_rank == 'first'} selected="selected"{/if}>第一</option>
		<option value="three" {if $product.honor_rank == 'three'} selected="selected"{/if}>前三</option>
		<option value="five" {if $product.honor_rank == 'five'} selected="selected"{/if}>前五</option>
		<option value="ten" {if $product.honor_rank == 'ten'} selected="selected"{/if}>前十</option>
		<option value="lead" {if $product.honor_rank == 'lead'} selected="selected"{/if}>领先</option>
		</select><span class="required">&nbsp;</span>
		</div>
		<div style="float:left;">
		<input id="honor_rank_file_btn" name="honor_rank_file_btn" type="file" /> 
		</div>
		<div style="clear:both;"></div>
		<div id="honor_rank_file_box" align="center" width="100%">
		{if $form_act == 'update' && $product.honor_rank_file}
			<div class="gpic-box" id="honor_rank_file_box_1" style="float:left;margin-right:6px;">
				<input type="hidden" name="honor_rank_file" value="{$product.honor_rank_file}" />
				<div class="gpic" style="height:180px;">
					<img src="../{$product.honor_rank_file}" width="150" height="150" />
					<div>
						<a href="javascript:void(0);" onclick="drop_image('honor_rank_file_box_1');"  title="删除">删除</a>
					</div>
				</div>
			</div>
		 {/if}
	   </div> 
		</td>
		
		<td class="label"><a href="#" title="产品面市的时间"><img src="images/help.gif" border="0" /></a>&nbsp;上市日期:</td>
		<td colspan="3"><input name="listing_date" type="text" value="{$product.listing_date}" style="width:100px;" class="FormSmall" readonly="readonly" onFocus="{literal}WdatePicker({dateFmt:'yyyy-MM-dd'}){/literal}" /><span class="required">&nbsp;</span></td>		
		</tr>
		{/if}
		
		<tr>
		<td class="label"><a href="#" title="选择该产品属于哪个品牌"><img src="images/help.gif" border="0" /></a>&nbsp;品牌:</td>
		<td>
		<select name="brand_id_{$list.language_id}" class="select_input">
		<option value="0">--选择--</option>
		{foreach from=$brand item=b_item}
		{if $list.language_id == $b_item.language_id}
		<option value="{$b_item.brand_id}" {if $list.language_id == $b_item.language_id}selected{/if}>{$b_item.brand_name}</option>
		{/if}
		{/foreach}
		</select>
		</td>
		<td class="label"><a href="#" title="产品与众不同的优势，一句话总结出来"><img src="images/help.gif" border="0" /></a>&nbsp;产品独特优势，一句话总结:</td>
		<td>
		<input name="advantages_{$list.language_id}" type="text" value="{$list.advantages|escape}" class="FormSmall" style="width:200px;"  /><span class="required">&nbsp;</span>
		</td>		
		</tr>	
		
		<tr>
		<td class="label"><a href="#" title="产品主要针对的人群是谁？越具体越好"><img src="images/help.gif" border="0" /></a>&nbsp;产品主要的目标客户群体:</td>
		<td>
		<input name="customer_groups_{$list.language_id}" type="text" value="{$list.customer_groups|escape}" class="FormSmall" style="width:200px;"  /><span class="required">&nbsp;</span>
		</td>
		<td class="label"><a href="#" title="产品是否有专利？有的话填入专利号"><img src="images/help.gif" border="0" /></a>&nbsp;产品专利:</td>
		<td>
		<input name="product_patents_{$list.language_id}" type="text" value="{$list.product_patents|escape}" class="FormSmall" style="width:200px;"  /></td>		
		</tr>			
		
		{if $smarty.foreach.product.index == 0}
		
	

		<tr>
		<td class="label">产品图片:</td>
		<td colspan="3">
		<input class="upload_image_btn" id="upload_image" name="upload_image" type="file" multiple /><span class="required">&nbsp;</span> 按Shift同时上传多个图片
		<div id="product_image_box" align="center" width="100%">
		{if $form_act == 'update'}
			{foreach from=$product_image item=p_list name=foo}
			<div class="gpic-box" id="product_image_box_{$smarty.foreach.foo.index}" style="float:left;margin-right:6px;">
				<div class="gpic">
					<img src="../{$p_list.thumb}" width="150" height="150" />
					<div style="margin-top:3px;">
					<input type="hidden" name="product_image[]" value="{$p_list.image}" />
					描述:<input type="text" name="product_image_desc[]" value="{$p_list.name}" style="width:100px;" />
					</div>
					<div style="margin-top:3px;">
					排序:<input type="text" name="product_image_sort[]" value="{$p_list.sort_order}" style="width:20px;" />->数字小排在前
					</div>
					<div>
						<a href="javascript:void(0);" onclick="drop_image('product_image_box_{$smarty.foreach.foo.index}');"  title="删除">删除</a>
					</div>
				</div>
			</div>
			{/foreach}
		 {/if}
	   </div> 
		</td>
		</tr>
		{/if}
		
		<tr>
		<td class="label">文件上传:</td>
		<td colspan="3">
			<input type="file" class="upload_file_btn" id="file_{$list.language_id}" name="file_{$list.language_id}" ref="{$list.language_id}" />
			<div id="product_file_box_{$list.language_id}" align="center" width="100%">
			{foreach from=$list.product_file item=file name=foo}
			<div class="gpic-box" id="product_file_box_{$list.language_id}_{$smarty.foreach.foo.index}" style="float:left;margin-right:6px;">
				<div class="gpic" style="height:100px;">
					<a href="product.php?act=download&id={$file.product_file_id}"><strong>{$file.name}</strong></a>
					<div style="margin-top:3px;">
					<input type="hidden" name="product_file_{$list.language_id}[]" value="{$list.image}" />
					描述:<input type="text" name="product_file_desc_{$list.language_id}[]" value="{$list.name}" style="width:100px;" />
					</div>
					<div style="margin-top:3px;">
					排序:<input type="text" name="product_file_sort_{$list.language_id}[]" value="{$list.sort_order}" style="width:20px;" />->数字小排在前
					</div>
					<div>
						<a href="javascript:void(0);" onclick="drop_file('product_file_box_{$list.language_id}_{$smarty.foreach.foo.index}');"  title="删除">删除</a>
					</div>
				</div>
			</div>
			{/foreach}
			</div>
		</td>
		</tr>			
		
		{foreach from=$list.attribute item=attribute key=key name=foo}
		<tr>
		<td class="label">{$attribute.attr_name}:</td>
		<td colspan="3">
		{if $attribute.attr_input_type == 1}
		<input name="attribute_{$list.language_id}[{$attribute.attr_id}]" type="text" value="{$list.product_attr[$attribute.attr_id][0]}" class="FormSmall" style="width:150px;" />		
		{/if}
		
		{if $attribute.attr_input_type == 2}
		<select name="attribute_{$list.language_id}[{$attribute.attr_id}]" class="select_input">
		<option value="">请选择</option>
		{foreach from=$attribute.attr_values item=val}
		<option value="{$val}" {if $list.product_attr[$attribute.attr_id][0] == $val}selected{/if}>{$val}</option>
		{/foreach}
		</select>
		{/if}		
		
		{if $attribute.attr_input_type == 3}
		{foreach from=$attribute.attr_values item=val}
		<label><input type="checkbox" name="attribute_{$list.language_id}[{$attribute.attr_id}][]" class="FormSmall" value="{$val}"
		{foreach from = $list.product_attr[$attribute.attr_id] item=sub_val}
			 {if $sub_val == $val} checked="checked"{/if} 
		{/foreach}
		/> {$val}</label>&nbsp;&nbsp;
		{/foreach}		
		{/if}
		
		{if $attribute.attr_input_type == 4}
		<textarea name="attribute_{$list.language_id}[{$attribute.attr_id}]" rows="5" cols="80" class="FormSmall">{$list.product_attr[$attribute.attr_id][0]}</textarea>
		{/if}	
		</td>
		</tr>
		{/foreach}
			
		<tr>
		<td class="label">产品描述:</td>
		<td colspan="3">{$list.description}</td>
		</tr>	
		
		{if $smarty.foreach.product.index == 0} 
		<tr>
		<td class="label">选项:</td>
		<td>
		<input type="checkbox" name="is_featured" value="1" {if $product.is_featured}checked="checked"{/if} /> 推荐&nbsp;&nbsp;
		 <input type="checkbox" name="is_new" value="1" {if $product.is_new}checked="checked"{/if} /> 新品 &nbsp;&nbsp;
		 <input type="checkbox" name="status" value="1" {if $product.status} checked="checked" {/if}  /> 显示
		 
		 </td> 		
		<td class="label">排序:</td>
		<td><input name="sort_order" type="text" value="{$product.sort_order}" class="FormSmall" style="width:50px;" />（数字越小越排在前）</td>
		</tr>	
		{/if}		
			
		<tr>
		<td class="label">模版:</td>
		<td colspan="3">
		<select name="template_{$list.language_id}" class="select_input">
		<option value="">默认</option>
		{foreach from=$template item=t}
		<option value="{$t}" {if $list.template == $t}selected{/if}>{$t}</option>
		{/foreach}
		</select>
		</td>
		</tr>			

	</table>
	{/foreach}
	
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_form">
		<tr>
			<td style="border:none;" class="label">&nbsp;</td>
			<td style="border:none;">
				<input type="hidden" name="product_id" value="{$product.product_id}" />
				<input type="hidden" name="act" value="{$form_act}" />
				<input name="submit" type="submit" value=" 确定 " class="bginput" />
				<input name="reset" type="reset" value=" 重置 " class="bginput" />
			</td>
		</tr>
	</table>
	</form>
</div>
	
<script language="JavaScript">
var productId = '{$product.product_id}';
{literal}
$(document).ready(function(){
	$('.category_select').change(function(){
		var sel_id = $(this).val();
		$('.category_select').val(sel_id);
	})
}) 

function validate(){
	var validator = new Validator('theForm');
	validator.required('name_{/literal}{$language[0].language_id}{literal}', '产品名称不能为空.');
	if (document.forms['theForm'].elements['cat_id_{/literal}{$language[0].language_id}{literal}'].value == 0){
		validator.addErrorMsg('请选择产品分类.');
	}
	return validator.passed();
}

$('.upload_image_btn').uploadify({
	'formData'     : {
		'rand_str' 	: '{/literal}{$rand_str}{literal}',
		'hash'     	: '{/literal}{$hash}{literal}',
		'session_id' : '{/literal}{$session_id}{literal}',
		'thumb_width'  : '150',
		'thumb_height' : '150',
		'img_type'  : 'image'
	},	
	'multi':true,
	'width':'94',
	'height':'25',
	'buttonText':'',
	'buttonImage':'images/add_image_1.png',
	'swf':'images/uploadify.swf',
	'uploader' : 'uploadify.php',
	'fileTypeDesc' : 'Image Files',
	'fileSizeLimit' : '2048KB',
	'fileTypeExts' : '*.gif; *.jpg; *.png',
	'onUploadStart' : function(file) {
		//$("#loading").fadeIn("fast");
	},
	'onUploadSuccess' : function(file, data, response) {
		result = $.parseJSON(data);
		if(result.error == 1){
			alert(result.message);
		}else{
			html ='<div class="gpic-box" id="'+result.id+'" style="float:left;margin-right:6px;">';
			html =html+'	<div class="gpic">';
			html =html+'		<div><img src="../'+result.image+'" width="150" height="150" /></div>';
			html =html+'		<div style="margin-top:3px;">';
			html =html+'		<input type="hidden" name="product_image[]" value="'+result.image+'" />';
			html =html+'		描述:<input type="text" name="product_image_desc[]" value="'+result.name+'" style="width:70px;" /><br />';
			html =html+'		</div>';
			html =html+'		<div style="margin-top:3px;">';
			html =html+'		排序:<input type="text" name="product_image_sort[]" value="" style="width:70px;" />';
			html =html+'		</div>';
			html =html+'		<div>';
			html =html+'			<a href="javascript:void(0);" onclick="drop_image(\''+result.id+'\');"  title="删除">删除</a>';
			html =html+'		</div>';
			html =html+'	</div>';
			html =html+'</div>';
			$('#product_image_box').append(html);
		}
	 }
});

function drop_image(id){
	$('#'+id).remove();
}

$('#honor_rank_file_btn').uploadify({
	'formData'     : {
		'rand_str' 	: '{/literal}{$rand_str}{literal}',
		'hash'     	: '{/literal}{$hash}{literal}',
		'session_id' : '{/literal}{$session_id}{literal}',
		'thumb_width'  : '150',
		'thumb_height' : '150',
		'img_type'  : 'image'
	},	
	'multi':false,
	'width':'107',
	'height':'25',
	'buttonText':'上传荣誉证书',
	'itemTemplate' : '<div style="dispalay:none;"></div>',
	'swf':'images/uploadify.swf',
	'uploader' : 'uploadify.php',
	'fileTypeDesc' : 'Image Files',
	'fileSizeLimit' : '2048KB',
	'fileTypeExts' : '*.gif; *.jpg; *.png',
	'onUploadStart' : function(file) {
		//$("#loading").fadeIn("fast");
	},
	'onUploadSuccess' : function(file, data, response) {
		result = $.parseJSON(data);
		if(result.error == 1){
			alert(result.message);
		}else{
			html ='<div class="gpic-box" id="'+result.id+'" style="float:left;margin-right:6px;">';
			html =html+'	<div class="gpic"  style="height:180px;">';
			html =html+'		<div><img src="../'+result.image+'" width="150" height="150" /></div>';
			html =html+'		<div style="margin-top:3px;">';
			html =html+'		<input type="hidden" name="honor_rank_file" value="'+result.image+'" />';
			html =html+'		</div>';
			html =html+'		<div>';
			html =html+'			<a href="javascript:void(0);" onclick="drop_image(\''+result.id+'\');"  title="删除">删除</a>';
			html =html+'		</div>';
			html =html+'	</div>';
			html =html+'</div>';
			$('#honor_rank_file_box').html(html);
		}
	 }
});

$('.upload_file_btn').each(function(){
	var obj = this;
	$(this).uploadify({
		'formData': {
			'rand_str' 	: '{/literal}{$rand_str}{literal}',
			'hash'     	: '{/literal}{$hash}{literal}',
			'session_id' : '{/literal}{$session_id}{literal}',
			'img_type'  : 'file'
		},	
		'multi':true,
		'width':'94',
		'height':'25',
		'buttonText':'',
		'buttonImage':'images/add_file.png',
		'swf':'images/uploadify.swf',
		'uploader' : 'uploadify.php',
		'fileTypeDesc' : 'Upload Files',
		'fileSizeLimit' : '2048KB',
		'fileTypeExts' : '*.doc; *.xls; *.zip; *.rar; *.pdf; *.jpg; *.png',
		'onUploadStart' : function(file) {
			//$("#loading").fadeIn("fast");
		},
		'onUploadSuccess' : function(file, data, response) {
			result = $.parseJSON(data);
			if(result.error == 1){
				alert(result.message);
			}else{
				html ='<div class="gpic-box" id="product_file_box_'+$(obj).attr('ref')+'_'+result.id+'" style="float:left;margin-right:6px;">';
				html =html+'	<div class="gpic" style="height:100px;">';
				html =html+'		<strong><a href="../'+result.file+'" target="_blank">'+result.name+'</a></strong>';
				html =html+'		<div style="margin-top:3px;">';
				html =html+'		<input type="hidden" name="product_file_'+$(obj).attr('ref')+'[]" value="'+result.file+'" />';
				html =html+'		描述:<input type="text" name="product_file_desc_'+$(obj).attr('ref')+'[]" value="'+result.name+'" style="width:100px;" />';
				html =html+'		</div>';
				html =html+'		<div style="margin-top:3px;">';
				html =html+'		排序:<input type="text" name="product_file_sort_'+$(obj).attr('ref')+'[]" value="" style="width:100px;" />';
				html =html+'		</div>';
				html =html+'		<div>';
				html =html+'	<a href="javascript:void(0);" onclick="drop_file(\'product_file_box_'+$(obj).attr('ref')+'_'+result.id+'\');"  title="删除">删除</a>';
				html =html+'		</div>';
				html =html+'	</div>';
				html =html+'</div>';
				$('#product_file_box_'+$(obj).attr('ref')).append(html);
			}
		 }
	});
});

function drop_file(id){
	$('#'+id).remove();
}

{/literal}
</script>
{insert_scripts files="tab.js,validator.js"}
{include file="page_footer.htm"}