<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><spring:message code="menu.consignor_info_set" /></title>
<script type="text/javascript" src="<%=basePath%>resource/easyui/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/validate/jquery.validate.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/validate/validate-extends.js"></script>
<!-- validate 验证中英文 -->
<script type="text/javascript"
	src="<%=basePath %>resource/validate/jquery.validate-${pageContext.response.locale}.js"></script>
<link rel="stylesheet" href="<%=basePath%>resource/layui/css/layui.css" media="all">
<script type="text/javascript" src="<%=basePath%>resource/layui/layui.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/js/tools.js"></script>
</head>
<body>
	<div class="layui-collapse">
		<div class="layui-colla-item">
			<h2 class="layui-colla-title">
				<spring:message code="consignor.list" />
			</h2>
			<div class="layui-colla-content layui-show">
				<div class="layui-row">
					<div class="layui-col-md12">
						<button class="layui-btn" onclick="edit()">新增</button>
						<button class="layui-btn layui-btn-danger" onclick="onDelete()">删除</button>
					</div>
				</div>
				<table id="consignor-table" class="layui-hide" lay-filter="consignor-table"></table>
			</div>
		</div>
	</div>

	<script type="text/html" id="opt-bar">
		<i class="layui-icon layui-icon-edit" style="font-size: 14px; color: #1E9FFF;" lay-event="edit">编辑</i> 
	</script>

	<script>
		var layer;
		layui.use('layer', function() {
			layer = layui.layer;
		});
	
		layui.use('element', function() {
			var element = layui.element;
		});

		$(window).load(function() {
			doSearch();
		});

		var table;
		function doSearch() {
			var api = "<%=basePath%>consignor/search";
			layui.use('table', function() {
				table = layui.table;
				table.on('checkbox(consignor-table)', function(obj) {
					/* console.log(JSON.stringify(obj)) */
				});

				table.render({
					elem : '#consignor-table',
					url : api,
					limit : 10,
					page : true,
					loading : true,
					limits : [ 10, 15, 20, 25, 30, 35, 40, 45, 50 ],
					text : '暂无数据',
					cols : [ [ //表头
					{
						type : 'checkbox',
						fixed : 'left',
						width : 60
					}, {
						field : '',
						title : '操作',
						toolbar : '#opt-bar',
						width : 80
					}, {
						field : 'co_company',
						title : '发货人公司',
					}, {
						field : 'co_city',
						title : '发货人城市',
						sort : true
					}, {
						field : 'co_country',
						title : '国家代码',
						sort : true,
						width : 100
					}, {
						field : 'co_telephone',
						title : '电话'
					} ] ]
				});
			});
		}
		
		function onDelete() {
			var checkStatus = table.checkStatus('consignor-table');
			var data = checkStatus.data;
			if(data&&data.length){
				var ids="";
				for (var i = 0; i < data.length; i++) {
					var item = data[i];
					var id = item.id;
					ids+=id;
					ids+=","
				}
				
				parent.layer.confirm('确定删除吗?', function(index) {
					layer.close(index);
					doDelete(ids);
				});
			}
		}
		
		function doDelete(ids) {
			var api = "<%=basePath%>consignor/delete";
			$.post(api, "ids="+ids, function(response, status) {
				if(response.status==200){
					layer.msg('删除成功'); 
					window.location.reload();
				}else{
					layer.msg("操作失败");
					console.log("response-->"+JSON.stringify(response));
				}
			});
		}
		
		layui.use('table', function() {
			var table = layui.table;
			table.on('tool(consignor-table)', function(obj) { //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值"
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
				var tr = obj.tr; //获得当前行 tr 的DOM对象

				if (layEvent === 'edit') { //编辑
					window.location.href = "<%=basePath%>/consignor/edit?id="+data.id;
				}
			});
		});
		
		function edit(){
			window.location.href = "<%=basePath%>/consignor/edit";
		}
		
	</script>
</body>
</html>