<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta name="decorator" content="base" />
<meta charset="utf-8">
<title>layuiAdmin 网站用户</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
<title>资料设置</title>
<style>
.menuItem:hover {
	background-color: #f0f0f0;
}

.ul-li {
	float: left;
}

.layui-table-cell {
	height: inherit;
}


#categoryList.layui-tab-title .layui-this{height: calc(100% - 3px);
    margin-bottom: 3px;
    border-bottom: 3px solid #144856;
}

#categoryList{
    white-space: normal;
    overflow: visible;
    background:#e6e6e6;
    height: auto;}
    #categoryList>li{
    border:1px solid #e6e6e6;
    border-bottom:3px solid #e6e6e6;
    }
</style>

</head>
<body>
	<div class="layui-fluid">
		<div class="layui-form layui-card" style="margin-top: -10px">
			<div class="layui-tab layui-tab-brief">
				<ul class="layui-tab-title">
					<sfTags:pagePermission authFlag="FACTORY_SETTLEMENT_SET_T" html='<li class="layui-this">
						<a href="${ctx}/yangguang/customerSettlementSet/customerSettlementSetList">结算方案设置</a>
					</li>'/>
					<sfTags:pagePermission authFlag="FACTORY_MELEAGE_SET_T" html='<li >
						<a href="${ctx}/yangguang/orderMileageSet/orderFactoryMileageSetPage">里程费用设置</a>
					</li>'/>
					<button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 layui-hide" id="searchBtn" lay-submit lay-filter="formDemo">
						<i class="layui-icon fs-12">&#xe615;</i>
						查询
					</button> 
				</ul>
			</div>
			<div class="layui-card-body">
				<div class="">
					<ul class="layui-tab-title" id="categoryList">
								<li class="layui-this " title="维修">维修</li>
					</ul>

				</div>
				<table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
				<script type="text/html" id="imgTpl"> 
        		</script>
				<script type="text/html" id="table-useradmin-webuser">
        		</script>
			</div>
		</div>
	</div>

	<!--自定义toolbar-->
	<div id="toolbarDemo" class="layui-form-item layui-hide">
		<sfTags:pagePermission authFlag="FACTORY_SETTLEMENT_SET_ADD_B" html='<button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin " lay-event="add" data-type="add">
			<i class="layui-icon layui-icon-add-1"></i>
			新增
		</button>'/>
		<sfTags:pagePermission authFlag="FACTORY_SETTLEMENT_SET_EDIT_B" html='<button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin " lay-event="edit"  data-type="batchdel">
			<i class="layui-icon layui-icon-edit"></i>
			编辑
		</button>'/>
		<sfTags:pagePermission authFlag="FACTORY_SETTLEMENT_SET_DEL_B" html='<button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin " lay-event="del"  data-type="batchdel">
			<i class="layui-icon layui-icon-delete"></i>
			删除
		</button>'/>
	</div>

	<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
	<script type="text/javascript">
		var saveMark = false;
		layui.use([ 'table', 'laypage', 'layer', 'form', 'element' ], function() {
			$ = layui.$, form = layui.form, table = layui.table;
			var table = layui.table;
			function isBlank(val){
				if(val==null || $.trim(val)=='' || val==undefined){
					return true;
				}
				return false;
			}

			/*条件查询*/
			layui.form.on('submit(formDemo)', function(data) {//formDemo为lay-filter="formDemo"
				var params = data.field; //获取提交的字段
				table.reload('LAY-user-manage', {
					where : params,
					page : {
						curr : 1
					}
				}); //数据刷新
			});

			//初始化table表格，事件处理在初始化之后
			table.render({
				elem : '#LAY-user-manage',
				height : 'full-320',
				url : '${ctx}/yangguang/customerSettlementSet/loadSettlementSetList?defaultCategory='+'${defaultCategory}', //数据接口
				layout : [ 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip' ],
				page : true, //开启分页
				toolbar : "#toolbarDemo",
				defaultToolbar : [],
				limits : [ 20, 50, 100 ],
				limit : 20,
				cols : [ [ //表头
                    {type: 'numbers',title:'序号',},
						{
							field : 'id',
							width : '5%',
							checkbox : true,
							align : 'center'
						},
						{
							field : 'warranty_type',
							width : '20%',
							title : '保修类型',
							align : 'center',
							templet : function(d) {
								var warrantyType = d.warranty_type;
								if (warrantyType == '1') {
									return "<span >保内</span>";
								} else if (warrantyType == '2') {
									return "<span >保外</span>";
								} else {
									return "<span >--</span>";
								}
							}
						},
						{
							field : 'service_step',
							title : '服务措施',
							width : '20%',
							align : 'center'
						},
						{
							field : 'charge_amount',
							title : '结算金额',
							width : '20%',
							align : 'center'

						},	{
                        field : 'service_content',
                        title : '服务项目',
                        width : '20%',
                        align : 'center'
                    } ] ],
				jump : function(obj) {

				},
				done : function(res) {//表格数据加载完成后可查看表格数据

				}
			});
			
			//监听行工具事件
		    table.on('toolbar(LAY-user-manage)', function(obj) {
			    var d = obj.data;
			    if(obj.event === 'add') {
			    	layer.open({
						type : 2,
						title : '新增结算方案',
						content : '${ctx}/yangguang/customerSettlementSet/addCustomerSettlementSetPage',
						maxmin : true,
						area : [ '50%', '40%' ],
						btn : [ '确定', '取消' ],
						yes : function(index, layero) {
							var iframeWindow = window['layui-layer-iframe' + index], submitID = 'LAY-user-front-submit_add', submit = layero.find('iframe').contents().find(
									'#' + submitID);
							//监听提交
							iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
								var field = data.field; //获取提交的字段
								if (saveMark) {
									return;
								}
								$.ajax({
									type : 'post',
									data : field,
									url : "${ctx}/yangguang/customerSettlementSet/addSaveCustomerSettlementSet",
									success : function(data) {
										if (data.code == '200') {
											layer.msg("添加成功！", {
												icon : 1
											});
                                            table.reload('LAY-user-manage'); //数据刷新
                                            layer.close(index); //关闭弹层
										}else {
											layer.msg(data.errMsg, {
												icon : 2
											});
										}
										saveMark = false;
										return;
									},
									error : function(e) {
										layer.msg("保存失败！", {
											icon : 2
										});
										saveMark = false;
										return;
									}
								}) 
							});
							submit.trigger('click');
						},
						success : function(layero) {
							layero.find('.layui-layer-btn').css('text-align', 'center');
							layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
						}
					});
			    }else if(obj.event==='edit'){
			    	var data = table.checkStatus("LAY-user-manage");
					if (data.data.length < 1) {
						layer.msg("请先选择数据！", {
							icon : 2
						});
						return;
					}
					if(data.data.length > 1){
						layer.msg("暂不支持批量编辑！", {
							icon : 2
						});
						return;
					}
					var id = data.data[0].id;

			    	layer.open({
						type : 2,
						title : '编辑结算方案',
						content : '${ctx}/yangguang/customerSettlementSet/editCustomerSettlementSetPage?id='+id,
						maxmin : true,
						area : [ '50%', '40%' ],
						btn : [ '确定', '取消' ],
						yes : function(index, layero) {
							var iframeWindow = window['layui-layer-iframe' + index], submitID = 'LAY-user-front-submit_edit', submit = layero.find('iframe').contents().find(
									'#' + submitID);
							//监听提交
							iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
								var field = data.field; //获取提交的字段
								if (saveMark) {
									return;
								}
								$.ajax({
									type : 'post',
									data : field,
									url : "${ctx}/yangguang/customerSettlementSet/editSaveCustomerSettlementSet",
									success : function(data) {
										if (data.code == '200') {
                                            layer.msg("编辑成功！", {
                                                icon : 1
                                            });
                                            table.reload('LAY-user-manage'); //数据刷新
                                            layer.close(index); //关闭弹层

										}else {
											layer.msg(data.errMsg, {
												icon : 2
											});
										}
										saveMark = false;
										return;
									},
									error : function(e) {
										layer.msg("保存失败！", {
											icon : 2
										});
										saveMark = false;
										return;
									}
								}) 
							});
							submit.trigger('click');
						},
						success : function(layero) {
							layero.find('.layui-layer-btn').css('text-align', 'center');
							layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
						}
					});
			    }else if(obj.event==='del'){
			    	var data = table.checkStatus("LAY-user-manage");
					if (data.data.length < 1) {
						layer.msg("请先选择数据！", {
							icon : 2
						});
						return;
					}
					var ids ="";
					var number = "";
					var category = "";
					for(var i=0;i<data.data.length;i++){
						var val = data.data[i].id;
						category = data.data[i].category;

					//	number = isBlank(number) ? val : (number+","+val);
						ids = isBlank(ids) ? val : (ids+","+val);
					}
					layer.confirm("确定要删除这"+data.data.length+"条结算方案吗？", {
						icon : 3,
						title : "删除提示",
					}, function(index) {
						$.ajax({
							type : "post",
							url : "${ctx}/yangguang/customerSettlementSet/saveDelCustomerSettlementSet",
							data : {
								ids : ids
							},
							success : function(data) {
								if (data.code == '200') {

                                    $.ajax({
                                        type : 'post',
                                         data : {
                                             ids : ids
                                    			},
                                        url : "${ctx}/yangguang/customerSettlementSet/savetemplateLowest",
                                        success : function(data) {
                                            layer.msg("删除成功！", {
                                                icon : 1
                                            });
                                            table.reload('LAY-user-manage'); //数据刷新
                                        }
                                    })


								} else {
									layer.msg(data.errMsg, {
										icon : 2
									});
								}
							},
							error : function(e) {
								layer.msg("保存失败！", {
									icon : 2
								});
							}
						});

					});
			    }else if(obj.event==='edit'){
			    	
			    }
		    });
		});
		
		function reset() {
			$("#serviceMeasures").val("");
		}
		
				
	</script>
</body>
</html>