<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@include file="/views/common.jsp"%>
<style type="text/css">
/* 数据表格样式 */
.layui-table td, .layui-table th,.layui-table-header, .layui-table-page,.layui-table-tool, .layui-table-total, .layui-table-view{
	border-color:#6666;
	font-size:14px;
}
.layui-table-cell{
	height:30px;
	line-height:34px;
}
.layui-input-inline,.layui-form-label{
	margin-top:10px;
}
.layui-input{
 	width:100%;
}
.layui-form-select .layui-edge{
	right:0px;
}
.layui-form-select .layui-input {
	padding-right: 0px;
}
/* 数据渲染完的回调。
由于layui 设置了超出隐藏，所以这里改变下，以兼容操作按钮的下拉菜单 */
.laytable-cell-1-0-2,.layui-table-box,.layui-table-body{
	overflow: visible;
}
/* 数据表格中的下拉框和表格相同高度 */
td .layui-form-select {
	margin-top: -10px;
	margin-left: -15px;
	margin-right: -15px;
}
</style>
</head>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container demoTable">
    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle-fine" style="font-size:20px;font-weight:bold"></i>新增类型</button>
	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="refresh"><i class="layui-icon layui-icon-search" style="font-size:20px;font-weight:bold"></i>数据未显示？点我试试</button>
  </div>
</script>
<script type="text/html" id="barDemo">
  	<a class="layui-btn layui-btn-sm" lay-event="edit">	<i class="layui-icon layui-icon-edit"></i>编辑</a>
 	<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete" ></i>删除</a>
</script>
<body>
	<div class="layui-row">
		<form class="layui-form " action="">
			<input type="hidden" id="proType_kindLabel" name="proType" class="layui-input">
		</form>
		<table class="layui-hide" id="trainKindLabelTable" lay-filter="trainKindLabelTable"></table>
	</div>
<script>
	layui.use([ 'table', 'form','util','laydate'], function() {
		var $ = layui.jquery,
		table = layui.table,
		form = layui.form,
		util = layui.util,
		laydate = layui.laydate;
		
		// 生成表格
		table.render({
			elem : '#trainKindLabelTable',
			url : '${path}/getCustomerTrainKindLabelsByProType',
			toolbar : '#toolbarDemo',
			id : 'trainKindLabelAll',
			border : true,
			page : true,
			limits : [ 10, 30, 50, 80, 100, 999 ],
			where : {
				proType : $("#proType_kindLabel").val(),
				type	: '产品知识',
				needPage: "1"
			},
			cols : [ [ {
				type : 'numbers',
				width : 50,
				title : '序号',
				fixed : "left",
				totalRowText: '合计'
			},{
				field : 'kindLabel',
				width :  180,
				align : 'center',
				title : '产品类型'
			},{
				field : 'sort',
				title : '排序',
				width :  60,
				align : 'center',
			},{
  				field : 'remark',
  				title : '说明',
  				width :  300
  			},{
  				field : 'createBy',
  				title : '创建人',
  				align : 'center',
  				width :  120
  			},{
				field : 'createDate',
				width :  180,
				align : 'center',
				title : '添加时间',
  				templet:function(d){
  					return util.toDateString(d.createDate, "yyyy-MM-dd HH:mm:ss");
  				}
  			}, {
				fixed : 'right',
				title : '操作',
				align : "center",
				width :  180,
				toolbar : '#barDemo'
			}] ],
			parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
				return {
					"code" 	: 0, //解析接口状态
					"msg" 	: "", //解析提示文本
					"count"	: res.total,//解析数据长度
					"data" 	: res.list//解析数据列表
				};
			}
		});
		
		//监听头工具栏事件--新增文章按钮
		table.on('toolbar(trainKindLabelTable)', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id), 
			data = checkStatus.data; //获取选中的数据
			switch (obj.event) {
				case 'add':
				    layer.open({
						type: 2,
						title: "添加产品类型",
						area: ['50%','60%'],
						skin: "layui-layer-molv",
						content: './addCustomerKnowledgeKindLabel.jsp',
						success: function (layero, index) {
		                    //向layer页面传值，传值主要代码
		                    var body = layer.getChildFrame('body', index);
		                        
		                    // 页面传参
		                    body.find('#proTypeAdd_kindLabel').val($("#proType_kindLabel").val());
		               	}
					});
			    break;
				case 'refresh':
					table.reload('trainKindLabelAll', {
						method : 'post',
							where : {
								proType : $("#proType_kindLabel").val(),
								type	: '产品知识'
							},
							page : {
								curr : 1
							}
					});
				break;
			};
		});
		
		//监听表格操作按钮--文章编辑
		table.on('tool(trainKindLabelTable)',function(obj){
			if(obj.event === 'edit'){
				layer.open({
		    		type: 2,
		    		title: "修改",
		    		area: ['50%','60%'],
					skin: "layui-layer-molv",
		    		fix: false, //不固定
		    		//btn: ['取消'],//弹出层按钮
		    		maxmin: true,
		    		content: './updateCustomerKnowledgeKindLabel.jsp',
		    		success: function(layero, index){
		    			var body = layer.getChildFrame('body', index);
		    		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
		    		    body.find('#idUpdate_kindLabel').val(obj.data.id);
		    		    body.find('#kindLabelUpdate_kindLabel').val(obj.data.kindLabel);
		    		    body.find('#sortUpdate_kindLabel').val(obj.data.sort);
		    		    body.find('#remarkUpdate_kindLabel').val(obj.data.remark);
		    		}
		    	 }); 
			}else if(obj.event === 'del'){
				layer.confirm('确定要删除该数据么？',{icon:3,title:"提示"}, function(index){
					$.ajax({
		    			url:"${path}/deleteCustomerTrainKindLabel",
		    		  	data:{'id': obj.data.id},
		    			type:"post",
		    		  	success:function (data) {
		    			 	if (data.code == 200) {
		    			 		layer.msg('删除成功！',{icon:6,offset:"auto",time:1000});//提示框
						  	}else{
							    layer.msg('删除失败！',{icon:5,offset:"auto",time:1000});//提示框
						  	}
		    			 	setTimeout(function(){
		    			 		location.reload();//重新加载页面
							}, 1100);
		    		 	}  
		    	 	}); 
				});
			}
		});
	})
</script>
</body>
</html>