<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
	<meta http-equiv="pragma" content="no-cache"/> 
	<meta http-equiv="cache-control" content="no-cache,must-revalidate"/>
	<meta http-equiv="expires" content="0"/>
    <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, maximum-scale=1">
	{% include '/common/layui_css.html' %}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">平台</label>
							<div class="layui-input-inline">
								<select name="type">
                                    <option value=""></option>
									<option value="ztn-data">省大数据平台</option>
								</select>
							</div>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">指标名称</label>
							<div class="layui-input-inline">
								<input type="text" name="name" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-inline">
							<button type="button" class="layui-btn layui-btn-primary" data-type="reload" lay-submit
								lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="btn_add">新增</button>
				<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="btn_delete">删除</button>
			</div>
		</script>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>
		</script>
    </div>
</div>
{% include '/common/layui_js.html' %}
<script>
    layui.use(['layer', 'miniTab','table','form'], function () {
        var $ = layui.$,
			form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            table = layui.table;
		var loadingIndex;
		var param = {};
        miniTab.listen();

		table.render({
			elem: '#test'
			,url:'index.json'
			,toolbar: '#toolbarDemo'
			,defaultToolbar: []
			,cols: [[
				{type:'checkbox'}
				,{type:'numbers'}
				,{field:'name', title:'接口名称', minWidth: 380}
				,{field:'type', title:'平台', width:130}
				,{field:'state', title:'状态', width:120}
				,{field:'rank', title:'排序', width:80}
				,{field:'log_time', title:'最近运行时间', width:180}
				,{field:'log_status', title:'日志状态', width:110}
				,{field:'row_count', title:'记录数', width:80}
				,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:120}
			]]
			,page: true
			,limit: 40
			,where: {
				time:new Date()
			}
		});

		form.on('submit(data-search-btn)', function (data) {
			console.log(data.field);
			param = data.field;
			table.reload('test', {
				page: { curr: 1 }
				, where: data.field
			}, 'data');
			return false;
		});

		table.on('toolbar(test)', function(obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			if(obj.event == 'btn_add') {
				layer.open({
                        type: 2,
                        title: '新增',
                        area: ['700px', '550px'],
                        fixed: true,
                        maxmin: false,
                        content: 'add.html',
                        end:function(){
                            location.reload();
                        }
                });
			}
			if(obj.event == 'btn_delete') {
				var data = checkStatus.data;
				if(data.length == 0) {
					var index = layer.alert('请勾选接口', {
						icon: 2,
					}, function () {
						layer.close(index);
					});	
					return false;
				}
				else {
					var id_list = [];
					data.forEach(function (item) {
						id_list.push(item.id);
					});
					layer.confirm('确认删除接口?', function (index) {
						$.post("delete.html", JSON.stringify({ ids: id_list}), function(r) {
							if(r.ret == 0) {
								layer.close(index);
								location.reload();
							}
							else {
								layer.alert(r.msg, { icon: 2 });
							}
						});
					});
					return false;
				}
			}
		});

		table.on('tool(test)', function (obj) {
            var data = obj.data;
			if (obj.event === 'edit') {
				miniTab.openNewTabByIframe({
					href: "ywtg/jkjc/zcqk/jkzc/edit.html?id="+data.id,
					title: '接口详情',
				});
            }
        });
    });
</script>
</body>
</html>
