<?php
  require __DIR__.'/head.html';
  require __DIR__.'/header.html';
  $File_Ming = 'apiinfo';
  require __DIR__.'/nav.html';
  ?>
<style>
    #admin-apiinfo .close {
        background-color: transparent;
        border: 0;
        -webkit-appearance: none;
    }
</style>
<!-- 主体 -->
<main class="app-content">
    <div class="app-title">
        <ul class="app-breadcrumb breadcrumb">
            <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
            <li class="breadcrumb-item">参数设置</li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <form id="admin-apiinfo">
                <div class="tile">
                    <div class="bs-component">
                        <div class="alert alert-dismissible alert-success">
                            <input class="close" type="button" value="x" data-dismiss="alert">
                            以下任意参数仅供用户参考,无其他效果，具体接口参数请自行设置;<br />
                        </div>
                    </div>
                    <div class="apihttp">
                        <div class="row">
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <label for="name0">参数名1</label>
                                    <input class="form-control" id="name0" type="text" aria-describedby="name0"
                                        name="data[0][name]" value="" placeholder="url">
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <label for="crux0">必填</label>
                                    <input class="form-control" id="crux0" type="text" aria-describedby="crux0"
                                        name="data[0][crux]" value="" placeholder="是">
                                </div>
                            </div>
                            <div class="col-lg-3">

                                <div class="form-group">
                                    <label for="type0">参数类型</label>
                                    <input class="form-control" id="type0" type="text" aria-describedby="type0"
                                        name="data[0][type]" value="" placeholder="string">
                                </div>
                            </div>
                            <div class="col-lg-5">
                                <div class="form-group">
                                    <label for="desc0">参数说明</label>
                                    <input class="form-control" id="desc0" type="text" aria-describedby="desc0"
                                        name="data[0][desc]" value="" placeholder="需要进行操作网址">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row" style="text-align: center;width: 100%;display: inline-block;">
                        <a href="javascript:" id="addapihttp">添加新参数</a> </div>
                    <div class="form-group">
                        <label for="optApi">选择绑定接口</label>
                        <select class="form-control" name="optApi" id="optApi">
                            <?php if(!empty($data)):
                            foreach ($data as $k => $v) : ?>
                            <option value="<?php echo $v['l_id']; ?>"><?php echo $v['l_title']; ?></option>
                            <?php endforeach;
                            endif;?>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="optType">选择参数类型</label>
                        <select class="form-control" name="optType" id="optType">
                            <option value="0">请求参数</option>
                            <option value="1">返回参数</option>
                            <option value="2">错误码</option>
                        </select>
                    </div>

                    <div class="tile-footer">
                        <input value="apiinfo" name="target" style="display: none">
                        <button type="button" class="btn btn-primary">添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <?php  require __DIR__.'/fooer.html'; ?>
    <script>
        /*阻止表单提交数据*/
        $("form").click(function (event) {
            event.preventDefault();
        });

        /*提交按下*/
        $('#admin-apiinfo button').click(function () {

            //判断是否存在接口
            if ($('#optApi').val() == null) {
                layer.msg("请选择绑定接口");
                return;
            }
            /*实例化表单数据*/
            var fd = new FormData(document.getElementById('admin-apiinfo'));
            $.ajax({
                url: '/admin/apiinfo',
                type: "POST",
                timeout: "5000",
                dataType: "json",
                contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                data: fd,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.code == "200") {
                        layer.msg(data.msg, { time: 1000 }, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function (XMLResponse) {
                    layer.msg(XMLResponse.error);
                }
            });
        });

        var add_id = 0; //保存ID计数
        $("#addapihttp").click(function () {
            add_id++;
            $(".apihttp").append(
                '<div class="row"> <div class="col-lg-2"> <div class="form-group"> <label for="name' + add_id +
                '">参数名' + ((add_id - 0) + 1) + '</label> <input class="form-control" id="name' + add_id +
                '" type="text" aria-describedby="name' + add_id + '" name="data[' + add_id +
                '][name]" value="" placeholder="url"> </div> </div> <div class="col-lg-2"> <div class="form-group"> <label for="crux' +
                add_id + '">必填</label> <input class="form-control" id="crux' + add_id +
                '" type="text" aria-describedby="crux' + add_id + '" name="data[' + add_id +
                '][crux]" value="" placeholder="是"> </div> </div> <div class="col-lg-3"> <div class="form-group"> <label for="type' +
                add_id + '">参数类型</label> <input class="form-control" id="data' + add_id +
                '" type="text" aria-describedby="type' + add_id + '" name="data[' + add_id +
                '][type]" value="" placeholder="string"> </div> </div> <div class="col-lg-5"> <div class="form-group"> <label for="desc' +
                add_id + '">参数说明</label> <input class="form-control" id="desc' + add_id +
                '" type="text" aria-describedby="desc' + add_id + '" name="data[' + add_id +
                '][desc]" value="" placeholder="需要进行操作网址"> </div> </div> </div>');
        });
    </script>
    </body>

    </html>