@page
@model Waste.Web.Entry.Pages.AppApi.IndexModel
@{
    ViewData["Title"] = "授权平台";
}
<div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select id="BusinessId" name="BusinessId">
                        <option value="">请选择商户</option>
                        @foreach (var item in Model.blist)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="btn btn-primary btn-lg  js-search" type="button">查询</button>
                <button class="btn btn-primary btn-lg  js-add" type="button">添加</button>
            </div>
        </div>
    </div>
    <div class="layui-card-body">
        <table class="layui-table" id="list" lay-filter="list">
        </table>
    </div>
</div>
<script type="text/html" id="optpl">
    <a href="#" class="js-edit" title="编辑" data-id="{{d.id}}">编辑</a>&nbsp;
    <a href="#" class="js-return" title="删除" data-id="{{d.id}}">删除</a>
</script>
@section Scripts
{
    <script type="text/javascript">
        layui.use(['common'], function () {
            var common = layui.common;
            common.initTable({
                url: '/api/business/getapilist'
                , method: 'post'
                , cols: [[
                    {
                        field: 'businessname', title: '商户'
                    },
                    {
                        field: 'appid', title: 'appid'
                    }
                    ,
                    {
                        field: 'appsecret', title: 'appsecret'
                    }
                    ,
                    {
                        field: 'pushurl', title: '推送地址'
                    }
                    ,
                    {
                        field: 'status', title: '状态', templet: function (d) {
                            return StatusType[d.status];
                        }
                    }
                    ,
                    {
                        field: 'createtime', title: '授权时间'
                    }
                    ,
                    {
                        title: '操作', templet: "#optpl"
                    }
                ]]
            });
            $(".js-search").on("click", function () {
                common.reloadtable("list", {
                    where: {
                        queryParam: [{
                            "Name": 'id',
                            "Type": QueryCond.Equal,
                            "Value": $("#BusinessId").val()
                        }]
                    }
                });
            });
            $(".js-add").on("click", function () {
                common.dialog({
                    title: '添加授权',
                    content: '/AppApi/Edit'
                });
            });
            $("body").on("click", ".js-edit", function () {
                var id = $(this).data('id');
                common.dialog({
                    title: '编辑授权',
                    content: '/AppApi/Edit?id=' + id
                });
            });
            $("body").on("click", ".js-return", function () {
                var id = $(this).data('id');
                common.confirm("确定删除?", function () {
                    common.uajax({
                        url: "/api/business/DeleteApiForm?keyvalue=" + id
                    });
                });
            });
        });
    </script>
}