<%@ 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>
.layui-table-cell{
		height:32px;
		line-height:32px;
	}
	.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:17px;
	}
	.edge .layui-edge{
		right:30px;
	}
	.layui-input-inline,.layui-form-label{
		margin-top:10px;
	}
</style>
<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-danger" lay-event="batchdel" data-type="getCheckData"><i class="layui-icon layui-icon-delete" style="font-size:20px;"></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>
</head>
<body> 
	<div class="layui-row">
		<form class="layui-form">
			<input type="hidden" id="type" name="type" value="服务态度">
			<div class="layui-form-item">
				<label class="layui-form-label">品种：</label>
				<div class="layui-input-inline edge">
					<select id="proType_content" name="proType" lay-search lay-filter="proType" class="proType">
						<option></option>
					</select>
				</div>
				<label class="layui-form-label">种类：</label>
				<div class="layui-input-inline edge">
					<select id="kind_content" name="kind" lay-search lay-filter="kind" class="kind">
					</select>
				</div>
				<div class="layui-inline">
					<div class="layui-input-block" style="margin-top:10px;">
						<button type="button" class="layui-btn" id="searchBtn">查询</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</div>
		</form>
		<table class="layui-hide" id="trainContentTable" lay-filter="trainContentTable"></table>
	</div>
	<script src="${path}/js/getTrainData.js" charset="utf-8"></script>
	<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 : '#trainContentTable',
				url : '${path}/getCustomerTrainContents',
				toolbar : '#toolbarDemo',
				title : "更新日志",// 导出名
				id : 'trainContentAll',
				// skin : 'row',
				// size :'lg',
				border : true,
				page : true,
				limits : [ 10, 30, 50, 80, 100, 999 ],
				where : {
					proType  : '',
					kind	 : '',
					type	 : '服务态度'
				},
				cols : [ [
					/* { type: 'checkbox' }, */
					{
						type : 'numbers',
						title : '序号',
						width : '4%',
						unresize : true
					}, {
						field : 'proType',
						align : "center",
						width : '13%',
						title : '产品类型'
					}, {
						field : 'kind',
						align : "center",
						width : '15%',
						title : '产品种类'
					}, {
						field : 'sort',
						align : "center",
						width : '5%',
						edit  : 'text',
						title : '排序'
					}, {
						field : 'content',
						align : "center",
						width : '28%',
						title : '内容'
					}, {
						field : 'createDate',
						align : "center",
						width : '12%',
						title : '添加时间',
						templet : function(d) {
							return d.createDate != null ?layui.util.toDateString(d.createDate, "yyyy-MM-dd HH:mm:ss") : "";
						} 
					}, {
						field : 'createBy',
						align : "center",
						width : '10%',
						title : '添加人'
					}, {
						fixed : 'right',
						title : '操作',
						align : "center",
						width : '13%',
						toolbar : '#barDemo'
					} ] ],
				parseData : function(res) { // 将原始数据解析成 table 组件所规定的数据
					return {
						"code" : 0, // 解析接口状态
						"msg" : "", // 解析提示文本
						"count"	: res.total,//解析数据长度
						"data" 	: res.list//解析数据列表
					// 解析数据列表
					};
				}
			});
			
			//点击查询按钮，重载表格
			$('#searchBtn').on('click', function() {
				table.reload('trainContentAll', {
				method : 'post',
					where : {
						proType  : $("#proType_content").val(),
						kind	 : $("#kind_content").val(),
						type	 : $("#type").val()
					},
					page : {
						curr : 1
					}
				});
				return false;
			});
			
			//监听头工具栏事件--新增按钮
			table.on('toolbar(trainContentTable)', function (obj) {
				var checkStatus = table.checkStatus(obj.config.id), 
				data = checkStatus.data; //获取选中的数据
				switch (obj.event) {
					case 'add':
					    layer.open({
						type: 2,
						//btn: ['关闭'],//弹出层按钮
						title: "添加产品知识",
						area: ['90%','90%'],
						skin: "layui-layer-molv",
						content: './addCustomerAttitudeContent.jsp',
						});
				    break;
				};
			});
			
			//监听表格操作按钮--编辑/删除
			table.on('tool(trainContentTable)',function(obj){
				if(obj.event === 'edit'){
					layer.open({
			    		type: 2,
			    		title: "修改信息",
			    		area: ['90%','90%'],
			    		//btn: ['关闭'],//弹出层按钮
						skin: "layui-layer-molv",
			    		fix: false, //不固定
			    		//btn: ['取消'],//弹出层按钮
			    		maxmin: true,
			    		content: './updateCustomerAttitudeContent.jsp',
			    		success: function(layero, index){
			    			var body = layer.getChildFrame('body', index);
			    		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
			    		    body.find('#idUpdate_content').val(obj.data.id);
			    		    body.find('#proTypeUpdate_content').val(obj.data.proType);
			    		    body.find('#proTypeUpdateInput_content').val(obj.data.proType);
			    		    body.find('#kindUpdate_content').val(obj.data.kind);
			    		    body.find('#kindUpdateInput_content').val(obj.data.kind);
			    		    body.find('#contentUpdate_content').val(obj.data.content);
			    		    iframeWin.layui.form.render();
			    		}
			    	 }); 
				}else if(obj.event === 'del'){
					layer.confirm('确定要删除该数据么？',{icon:3,title:"提示"}, function(index){
						$.ajax({
			    			url:"${path}/deleteCustomerTrainContent",
			    		  	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);
			    		 	}  
			    	 	}); 
					});
				}
			});
			//监听单元格编辑--排序
			table.on('edit(trainContentTable)', function(obj){
				var value = obj.value, //得到修改后的值
			    data = obj.data; //得到所在行所有键值
			    $.ajax({
					url:"${path}/updateCustomerTrainContentSort",
				  	data:{
				  		id: data.id,
				  		value: value
				  	},
					type:"post",
				  	success:function (data) {
					 	if (data.code == 200) {
					 		layer.msg('修改成功！',{icon:6,offset:"auto",time:1000});//提示框
					 		setTimeout(function(){
								layui.table.reload('trainContentAll');//重新加载父页面表格
							}, 1100);
					  	}else{
						    layer.msg(data.msg,{icon:5,offset:"auto",time:1000});//提示框
					  	}
				 	}  
			 	}); 
			});
		})
	</script>
</body>
</html>