<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑页面</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{= d.id }}" />
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
				<div class="layui-form-item">
    				<label class="layui-form-label" title="请求路由">请求路由</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="rule" id="rule" placeholder="请输入请求路由" value="{{=d.rule.toString()}}" class="layui-input" lay-verify="">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="请求体">请求体</label>
    				<div class="layui-input-block">
            			<textarea name="request_body" id="request_body" placeholder="请输入请求体" class="layui-textarea" lay-verify="">{{=d.request_body}}</textarea>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="header参数">header参数</label>
    				<div class="layui-input-block">
            			<textarea name="request_header" id="request_header" placeholder="请输入header参数" class="layui-textarea" lay-verify="">{{=d.request_header}}</textarea>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="IP">IP</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="ip" id="ip" placeholder="请输入IP" value="{{=d.ip.toString()}}" class="layui-input" lay-verify="">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="返回状态码">返回状态码</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="status_code" id="status_code" placeholder="请输入返回状态码" value="{{=d.status_code.toString()}}" class="layui-input" lay-verify="">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="返回内容">返回内容</label>
    				<div class="layui-input-block">
            			<textarea name="response_body" id="response_body" placeholder="请输入返回内容" class="layui-textarea" lay-verify="">{{=d.response_body}}</textarea>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="创建时间">创建时间</label>
    				<div class="layui-input-block">
            			<input type="text" class="layui-input laydate"
            name="create_time" id="create_time" data-type="datetime"
            autocomplete="off" placeholder="请选择创建时间" value="{{=d.create_time}}" lay-verify="" />
    				</div>
				</div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        //获取参数ID
        var id = facade.getUrlParam('id');
        if(!id){
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.api.log/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function(res){
            if(res.code === 0){
                layui.laytpl($("#form").html()).render(res.data,function(string){
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                });
            }
        });

        form.on('submit(laytp-form)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            try{
                data = facade.setEditorField(data);
            }catch (e) {
                facade.error(e);
                return false;
            }
            facade.ajax({
                route:'/admin.api.log/edit',
                data:data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reloadData("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>