<%@ page contentType="text/html;charset=UTF-8" %>
<script>
	    var $materialTypeTreeTable=null;  
		$(document).ready(function() {
			$materialTypeTreeTable=$('#materialTypeTreeTable').treeTable({  
		    	   theme:'vsStyle',	           
					expandLevel : 2,
					column:0,
					checkbox: false,
		            url:'${ctx}/warehouse/materialtype/materialType/getChildren?parentId=',
		            callback:function(item) { 
		            	 var treeTableTpl= $("#materialTypeTreeTableTpl").html();
		            	 item.dict = {};
	           	  var result = laytpl(treeTableTpl).render({
								  row: item
							});
		                return result;                   
		            },  
		            beforeClick: function($materialTypeTreeTable, id) { 
		                //异步获取数据 这里模拟替换处理
		                $materialTypeTreeTable.refreshPoint(id);  
		            },  
		            beforeExpand : function($materialTypeTreeTable, id) {   
		            },  
		            afterExpand : function($materialTypeTreeTable, id) {  
		            },  
		            beforeClose : function($materialTypeTreeTable, id) {    
		            	
		            }  
			});
		        $materialTypeTreeTable.initParents('${parentIds}', "0");//在保存编辑时定位展开当前节点
		       
		});
		
		function del(con,id){  
			jp.confirm('确认要删除物资品名代码吗？', function(){
				jp.loading();
	       	  	$.get("${ctx}/warehouse/materialtype/materialType/delete?id="+id, function(data){
	       	  		if(data.success){
	       	  			$materialTypeTreeTable.del(id);
	       	  			jp.success(data.msg);
	       	  		}else{
	       	  			jp.error(data.msg);
	       	  		}
	       	  	})
	       	   
       		});
	
		} 
		
		function add(){//新增
			jp.openSaveDialog("新增物资品名代码",'${ctx}/warehouse/materialtype/materialType/form/add', '800','600');
		}
		function edit(id){//编辑
			jp.openSaveDialog("编辑物资品名代码",'${ctx}/warehouse/materialtype/materialType/form/edit?id='+id, '800','600');
		}
		function view(id){//查看
			jp.openViewDialog("查看物资品名代码",'${ctx}/warehouse/materialtype/materialType/form/view?id='+id, '800','600');
		}
		function addChild(id){//添加下级机构
			jp.openSaveDialog("添加下级物资品名代码",'${ctx}/warehouse/materialtype/materialType/form/add?parent.id='+id, '800','600');
		}
		function refresh(){//刷新
			var index = jp.loading("正在加载，请稍等...");
			$materialTypeTreeTable.refresh();
			jp.close(index);
		}
</script>
<script type="text/html" id="materialTypeTreeTableTpl">
			<td>
			<c:choose>
			      <c:when test="${fns:hasPermission('warehouse:materialtype:materialType:edit')}">
				    <a onclick="edit('{{d.row.id}}')">

						{{d.row.name === undefined ? "": d.row.name}}
					</a>	
			      </c:when>
			      <c:when test="${fns:hasPermission('warehouse:materialtype:materialType:view')}">
				    <a  onclick="view('{{d.row.id}}')">

						{{d.row.name === undefined ? "": d.row.name}}
					</a>	
			      </c:when>
			      <c:otherwise>

					  {{d.row.name === undefined ? "": d.row.name}}
			      </c:otherwise>
			</c:choose>
			</td>
			<td>
				{{d.row.code === undefined ? "": d.row.code}}
			</td>
			<td>
				{{d.row.amount === undefined ? "": d.row.amount}}
			</td>
			<td>
				{{d.row.unit === undefined ? "": d.row.unit}}
			</td>
			<td>
				{{d.row.remarks === undefined ? "": d.row.remarks}}
			</td>
			<td>
				<div class="btn-group">
			 		<button type="button" class="btn  btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
						<i class="fa fa-cog"></i>
						<span class="fa fa-chevron-down"></span>
					</button>
				  <ul class="dropdown-menu" role="menu">
					<shiro:hasPermission name="warehouse:materialtype:materialType:view">
						<li><a onclick="view('{{d.row.id}}')"><i class="fa fa-search-plus"></i> 查看</a></li>
					</shiro:hasPermission>
					<shiro:hasPermission name="warehouse:materialtype:materialType:edit">
		   				<li><a onclick="edit('{{d.row.id}}')"><i class="fa fa-edit"></i> 修改</a></li>
		   			</shiro:hasPermission>
		   			<shiro:hasPermission name="warehouse:materialtype:materialType:del">
		   				<li><a  onclick="return del(this, '{{d.row.id}}')"><i class="fa fa-trash"></i> 删除</a></li>
					</shiro:hasPermission>
		   			<shiro:hasPermission name="warehouse:materialtype:materialType:add">
						<li><a onclick="addChild('{{d.row.id}}')"><i class="fa fa-plus"></i> 添加下级物资品名代码</a></li>
					</shiro:hasPermission>
				  </ul>
				</div>
			</td>
	</script>
