$(function(){
	var oTable=new TableInit();
	oTable.Init();
});


var TableInit=function(){
	var oTableInit=new Object();
	var url = ctxManager+"/kzfProduct/getPageProductTypeList";
	//初始化table
	oTableInit.Init=function(){
		$('#standardTable').bootstrapTable({
			url:url,
			method: 'post',  
			toolbar:'#toolbar',
			striped:true,//是否隔行变色
			cache:false,
			pagination:true,//是否分页
			minimumCountColumns: 2,
			queryParamsType : "",
			contentType: "application/x-www-form-urlencoded",
            showToggle:false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
			queryParams : function(params) {
			
			   return {
//				   	  mobileUser:$("#mobileUser").val(),
				   name:$("#name").val(),
				   	  pageSize: params.pageSize,
			          pageIndex: params.pageNumber,
			        };
			},
			responseHandler: function(res) {
				//console.log();
				if(res.rowCount==0){
					$("#standardTable tbody").hide();
				}else{
					$("#standardTable tbody").show();
				}
                return {
                    total: res.rowCount,//总条数
                    rows: res.records//数据
                 };
            },
			clickToSelect: true,
			sidePagination:'server',
			pageNumber:1,
			pageSize:10,
			pageList:[10,20,50,100],
			showColumns:true,
			uniqueId:"id",
			cardView:false,
			detailView:false,//是否显示父子表
			onPostBody:function(val){
				 $('.J_menuItem').each(function(i,v){
					// $v = $(v);
					 if(!v.hasAttribute("onclick")){
						 $(v).on('click', window.parent.Menu.menuOpenCloseBack);
					 }
				 });
			},
			columns:[
					/*{
					 	checkbox:false
					},*/
					{
						field:'id',
					 	title:'主键',
					 	visible:false,
					 	width:80
					},{
						field:'name',
					 	title:'分类名称',
					 	visible:true,
					 	width:80
					},{
						field:'level',
					 	title:'分类级别',
					 	visible:true,
					 	width:200,
					 	formatter:
					 		function(value, row, index){
					 		if (value == '0'){
					 			return '顶级分类';
					 		}else{
					 			return '二级分类';
					 		}
					 	}
					},
					{
						field:'parentName',
					 	title:'所属分类',
					 	width:80
					},
					{
						field:'sort',
					 	title:'排序',
					 	width:100
					},
					{
						field:'lagType',
						title:'语言类型',
						width:100,
						formatter:function(val,row,index){
							if(val == "01"){
								return "英文"
							}else{
								return "德文"
							}
						}
					},
					{
	                 	field: "ismade", 
	                 	title: "操作", 
	                 	align: "center",
	                 	width:150,
	                    formatter: 
		                    function (value, row, index){
	                    	var res;
			                     res =  [
			                       '<a class="J_menuItem" href="'+ctx+'/manager/kzfProduct/modKzfProductType?id='+row.id+'" title="商品类型修改">',
					               '<button id="btn_detail" type="button" class="btn btn-primary btn-sm">',
					               '<span class="fa fa-pencil" aria-hidden="true"></span>',
					               '</button>',	
					               '</a>&nbsp; &nbsp;',
//			                       '<a class="J_menuItem" href="'+ctx+'/manager/aba31/getDetail?id='+row.id+'">',
//					               '<button id="btn_detail" type="button" class="btn btn-primary btn-sm">',
//					               '<span class="fa fa-eye" aria-hidden="true"></span>',
//					               '</button>',	
//					               '</a>&nbsp; &nbsp;',
					               '<a class="J_menuItem" href="javascript:void(0)"  onclick="productTypeList.deleteProductType(\'' + row.id + '\')">',
					               '<button id="btn_detail" type="button" class="btn btn-danger btn-sm">',
					               '<span class="fa fa-minus" aria-hidden="true"></span>',
					               '</button>',	
					               '</a>'
			                    ].join('');
			                    
			                    return res;
		                	}
					}    
			]
		});
		
	};
	/*得到查询参数*/
	oTableInit.queryParams=function(params){
		var temp={
			limit:params.limit,//页面的大小
			offset:params.offset,//页码
		};
		return temp;
	};
	return oTableInit;
};

var productTypeList = {
	/*
	 * 查询
	 */
	chakan : function(){
			$('#standardTable').bootstrapTable('refresh');
			oTable.Init();
			/*$table.bootstrapTable('resetView');*/
	},
	deleteProductType: function(id){
		layer.alert('',{icon:2,title:'删除确认',content:'您确定要删除这条记录吗？',closeBtn:1},function(index){
			layer.close(index);
			$.ajax({
				url:ctxManager+"/kzfProduct/removeProductTypeById",
				type:'POST',
				data:{id:id},
				dataType:'json',
				sync:'false',
				success:function(res){
					//如果成功，返回
					if(res.result == "success"){
						layer.alert("删除成功",function(index){
							layer.close(index);
						});		
						productTypeList.chakan();
					}else{
						layer.alert(res.msg);	
					}
					
					
				},
			});
			
		})
	}
	
}
/**
 * 删除
 */
//function DeletebzptCms(id) {
//	layer.alert('',{icon:2,title:'删除确认',content:'您确定要删除这条记录吗？',closeBtn:1},function(index){
//		layer.close(index);
//		$.ajax({
//			url:ctxManager+"/bzptCms/delBzptCms",
//			type:'POST',
//			data:{id:id},
//			dataType:'json',
//			sync:'false',
//			success:function(res){
//				//如果成功，返回
//				if(res.flag){
//					layer.alert("删除成功",function(index){
//						layer.close(index);
//						//window.location.reload();
////						listbzptCms.chakan();
//					});		
//					$('#standardTable').bootstrapTable('refresh');
//				}else{
//					layer.alert(res.msg);	
//				}
//				
//				
//			},
//		});
//		
//	})
//}


