{include "header.inc.html"}
{$catLang = $lang.admin.category.form}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>{$lang.admin.category.name}</strong><br />
		<span class="english">{$lang.admin.category.name_en}</span> </span> </div>
	</div>
{if $smarty.get.act=="add" || $smarty.get.act=="edit"}
<div class="categoryForm">
<form class="form" action="" method="post">
<input type="hidden" name="act" value="{$smarty.get.act}" />
{if $smarty.get.act=="edit"}
<input type="hidden" name="id" value="{$smarty.get.id}" />
{/if}
<div class="form-line"><label class="label">{$catLang.name}：</label><div class="element">
{if $smarty.get.act=="add"}
<textarea class="text w300" name="name">{$catInfo.name}</textarea>
{else}
<input type="text" class="text w300" name="name" value="{$catInfo.name}">
{/if}
</div></div>
<div class="form-line"><label class="label">{$catLang.parent}：</label><div class="element"><select name="parentId"><option value="0">{$lang.form.topCat}</option>
{foreach from=$category item=item}
<option value="{$item.id}"{if $catInfo.parentId==$item.id} selected{/if}>{for $foo=1 to $item.grade*4}&nbsp;{/for}{$item.name}</option>
{/foreach}
</select>
</div></div>
<div class="form-line"><label class="label">商品类型：</label><div class="element"><select name="typeId">
{goodstype}
<option value="{$item.id}"{if $catInfo.typeId==$item.id} selected{/if}>{$item.name}</option>
{/goodstype}
</select>
</div></div>

<div class="form-line"><label class="label">{$lang.form.sort}：</label><div class="element"><input type="text" class="text w300" name="sortId" value="{$catInfo.sortId|default:50000}" /></div></div>
{*
{if $config.goods.brand}
<div class="form-line"><label class="label">关联品牌：</label><div class="element">
<div class="brandIds">
{brand limit="false"}
<input type="checkbox" name="brandId[]" id="brandId{$item.id}" value="{$item.id}" {if $smarty.get.act=="edit" && $catInfo.brandArr && $item.id|in_array:$catInfo.brandArr} checked{/if}><label for="brandId{$item.id}">{$item.name}&nbsp;&nbsp;</label>
{/brand}</div>
</div></div>
{/if}
*}
<div class="form-line"><label class="label">{$lang.form.logo}：</label><div class="element">
<input type="hidden" name="logoId" id="logoId" value="{$catInfo.logoId}" />
{if  $catInfo.logoId}
{attachment id=$catInfo.logoId limit=1}
<img id="img-thumb" src="{$item.url}" />
{/attachment}
{else}
<img id="img-thumb" src="/static/images/default.png" />
{/if} <span id="uploadBtnLogo"></span>
</div></div>
<div class="form-line"><label class="label">{$lang.form.banner}：</label><div class="element">
<input type="hidden" name="bannerId" id="bannerId" value="{$catInfo.bannerId}" />
{if  $catInfo.bannerId}
{attachment id=$catInfo.bannerId limit=1}
<img id="img-thumb-banner" src="{$item.url}" />
{/attachment}
{else}
<img id="img-thumb-banner" src="/static/images/default.png" />
{/if} <span id="uploadBtnBanner"></span>
</div></div>
{if $config.goods.searchKey}
<div class="form-line">
<label class="label">推荐搜索词：</label><div class="element"><textarea name="hotkey">{$catInfo.hotkey}</textarea></div>
</div>
{/if}
<div class="form-line"><label class="label">{$lang.seo.title}：</label><div class="element"><input type="text" class="text w300" name="title" value="{$catInfo.title}" /></div></div>
<div class="form-line"><label class="label">{$lang.seo.keywords}：</label><div class="element"><textarea name="keywords" style="width:550px;height:60px;">{$catInfo.keywords}</textarea></div></div>
<div class="form-line"><label class="label">{$lang.seo.description}：</label><div class="element"><textarea name="description" style="width:550px;height:60px;">{$catInfo.description}</textarea></div></div>

<div class="form-line"><label class="label">{$lang.form.seoUrl}：</label><div class="element"><input type="text" class="text w300" name="seoUrl" value="{$catInfo.seoUrl}" /> 以/开头并且符合URL规则</div></div>
<div class="form-line"><label class="label">显示模板：</label><div class="element"><input type="text" class="text w300" name="template" value="{$catInfo.template}" /></div></div>

<div class="form-line"><label class="label"></label><div class="element"><input type="submit" class="btn_sub" value="{$lang.form.submit}" /></div></div>
</form>
</div>
{else}
{*
<div class="tool">
<form action="{$adminUrl}category" method="get" class="form">
<input type="text" name="key" value="{$smarty.get.key}" /><input type="submit" class="btn_sub" value="{$lang.form.search}" />
</form>
<div class="clr"></div>
</div><!--.tool-->
*}
<style type="text/css">
.table-ca{ width:auto;}
.datagrid-cell-id{ width:50px; }
.datagrid-cell-name{ width:250px; }
.datagrid-cell-parent{ width:150px; }
.datagrid-cell-seourl{ width:150px; }
.datagrid-cell-template{ width:150px; }
.datagrid-cell-sortid{ width:70px; }
.datagrid-cell-datetime{ width:90px; }
.datagrid-cell-tool{ width:80px; }
.datagrid-cell-mainnav{ width:80px; }
</style>
 <table class="table-ca" style="margin:0px auto 0px 10px;; ">
<thead>
 <tr>
<th>{$lang.form.id}</th><th>{$lang.form.catName}</th><th>父类</th><th>自定义URL</th><th>显示模板</th><th>主导航中显示</th><th>{$lang.form.sort}</th><th>{$lang.form.posttime}</th><th>{$lang.form.operate}</th>
 </tr>
</thead>
<div class="datagrid">
{category limit='false' pager='true' orderBy="sortId asc,id asc" parentId='0' filelds="subNum"}
<tr sid="{$item.id}">
<td><div class="datagrid-cell-id">{$item.id}</div></td><td style="text-align:left;"><div class="datagrid-cell-name">{for $foo=1 to $item.grade*4}&nbsp;{/for}{if $item.subNum>0}<i class="arrow"></i>{/if}{$item.name}</div></td><td><div class="datagrid-cell-parent">{$item.parentInfo.name}</div></td><td><div class="datagrid-cell-seourl">{$item.seoUrl}</div></td><td><div class="datagrid-cell-template">{$item.template}</div></td><td><div class="datagrid-cell-mainnav"><img class="smodtoggle" name="mainNav" src="{$baseUrl}static/images/{if $item.mainNav==1}yes{else}no{/if}.gif" sid="{$item.id}"></div></td><td><div class="datagrid-cell-sortid"><span class="smodedit" width="50" name="sortId" sid="{$item.id}">{$item.sortId}</span></div></td><td><div class="datagrid-cell-datetime">{$item.posttime|date_format:"%Y-%m-%d"}</div></td><td><div class="datagrid-cell-tool"><a href="/qkadmin/category/act/edit/id/{$item.id}" class="modBtn" title="{$lang.edit}">{$lang.edit}</a> <a href="/qkadmin/category/act/del/id/{$item.id}" class="delBtn" title="{$lang.del}">{$lang.del}</a></div></td>
</tr>
{/category}
</div>
</tbody>
</table>
<div class="page">
	<div class="pagin fr">{pager allCount=$allCount url='/qkadmin/category/page/' number="false"}</div>
</div>
{/if}
<script type="text/javascript">
$(function(){
function bindArrow(){
	$("i.arrow").unbind().click(function(){
		var obj=$(this),tr=obj.parent("div").parent('td').parent('tr'),sid=tr.attr('sid');
		if(!obj.hasClass('arrow-expand')){
			var tbody=tr.next(".child");
			if(tbody.length!=0){
				tbody.show();
				obj.addClass('arrow-expand');
			}else{
				$.ajax({ type:'POST',url:'{$baseUrl}category/data',data:'inajax=1&act=getChild&id='+sid,dataType:'json',success:function(json){
						var colspan=9;
						var html="<tr class=\"child\"><td colspan=\""+colspan+"\" class=\"child\"><table class=\"table-ca\">";
						//html+='<colgroup><col class="w50"><col class=""><col class="w100"><col class="w100"><col class="w100"><col class="w100"><col class="w120"><col class="w100"></colgroup>';
						$.each(json.data,function(idx,item){
							var childBtn='';
							if(item.subNum && item.subNum>0){ childBtn='<i class="arrow"></i>'; }
							html+="<tr sid=\""+item.id+"\"><td><div class=\"datagrid-cell-id\">"+item.id+"</div></td><td style=\"text-align: left;\"><div class=\"datagrid-cell-name\">"+item.nbsp+childBtn+item.name+"</div></td><td><div class=\"datagrid-cell-parent\">"+item.parentInfo.name+"</div></td><td><div class=\"datagrid-cell-seourl\">"+item.seoUrl+"</div></td><td><div class=\"datagrid-cell-template\">"+item.template+"</div></td>"+"<td><div class=\"datagrid-cell-mainnav\"><img class=\"smodtoggle\" name=\"mainNav\" src=\"{$baseUrl}static/images/"+((item.mainNav=='1')?'yes':'no')+".gif\" sid=\""+item.id+"\"></div></td>"+"<td><div class=\"datagrid-cell-sortid\"><span class=\"smodedit\" width=\"50\" name=\"sortId\" sid=\""+item.id+"\">"+item.sortId+"</span></div></td><td><div class=\"datagrid-cell-datetime\">"+item.datetime+"</div></td><td><div class=\"datagrid-cell-tool\"><a href=\"/qkadmin/category/act/edit/id/"+item.id+"\" class=\"modBtn\">修改</a> <a href=\"javascript:void(0)\" class=\"delBtn\">删除</a></div></td></tr>";
						});
						html+="</table></td></tr>";
						tr.after(html);
						window.smod&&window.smod.bind();
						bindArrow();
						bindDel();
						obj.addClass('arrow-expand');
					},error:function(){  }});
			}
		}else{
			var tbody=tr.next(".child");if(tbody.length!=0){ tbody.hide(); }
			obj.removeClass('arrow-expand')
		}
	});
}
bindArrow();

function bindDel(){
	$(".delBtn").unbind().click(function(){
		if(!confirm(lang[4])){ return false; }
			var tr = $(this).parent("div").parent("td").parent("tr");
			var id = tr.attr('sid');
			if(parseInt(id,10)){
				var sdata = "inajax=1&act=del&id="+id;
				$.ajax({
					type:"POST",
					url:"{$adminUrl}category",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							alert(data.message);
						}
					}
				});
			}
		return false;
	});
}
bindDel();
})
</script>
{if $smarty.get.act=="edit" or $smarty.get.act=="add"}

<script type="text/javascript" src="/plugins/swfupload/swfupload.js"></script>
<script type="text/javascript">
$(function(){
	swfu_settings.button_placeholder_id = "uploadBtnLogo";
	swfu = new SWFUpload(swfu_settings);
	swfu.uploadSuccess = function(obj,data,resp){
			var data = eval('('+data+')');
			if(data.success){
				var url = decodeURIComponent(data.url);
				swfu.setButtonText("<span class='redText'>{$lang.admin.success}</span>");
				swfu.setButtonDisabled(false);
				$("#img-thumb").attr("src","/"+url);
				$("#logoId").val(data.id);
			}
	};

	swfuBanner = new SWFUpload(swfu_settings_banner);
	swfuBanner.uploadSuccess = function(obj,data,resp){
			var data = eval('('+data+')');
			if(data.success){
				var url = decodeURIComponent(data.url);
				swfuBanner.setButtonText("<span class='redText'>{$lang.admin.success}</span>");
				swfuBanner.setButtonDisabled(false);
				$("#img-thumb-banner").attr("src","/"+url);
				$("#bannerId").val(data.id);
			}
	};
});
</script>
{/if}
</div><!--.content_box-->

{include "footer.inc.html"}