<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
    <div class="admin-content">
        <div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
            <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">系统管理</strong> /
                <small>后端资源管理</small>
            </div>
        </div>
        <div class="am-g">
            <div class="am-u-sm-12">
                <form class="am-form" id="listForm" action="${base}/permission/list" method="POST">
                    <input type="hidden" id="keywords" name="keywords" value='${keywords!""}'/>
                    <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
                        <tbody>
                        <tr>
                            <th class="am-text-middle">主键ID</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <input type="text" id="pmsID" class="am-form-field am-input-sm" value="${pmsID!}"
                                           maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'') "
                                           onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
                                </div>
                            </td>
                            <th class="am-text-middle">资源名称</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <input type="text" id="pmsName" class="am-form-field am-input-sm"
                                           value="${pmsName!}"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="am-text-middle">URL</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <input type="text" id="pmsUrl" class="am-form-field am-input-sm"
                                           value="${pmsUrl!}"/>
                                </div>
                            </td>
                            <th class="am-text-middle">父ID</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <input type="text" id="pmsParentID" class="am-form-field am-input-sm"
                                           value="${pmsParentID!}" maxlength="11"
                                           onkeyup="value=value.replace(/[^\d]/g,'') "
                                           onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="am-text-middle">LEVEL</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <select data-am-selected id="pmsLevel" name="pmsLevel">
                                        <option value="0" <#if pmsLevel == "0" > selected </#if>>全部</option>
                                        <option value="1" <#if pmsLevel == "1" > selected </#if> >1</option>
                                        <option value="2" <#if pmsLevel == "2" > selected </#if> >2</option>
                                        <option value="3" <#if pmsLevel == "3" > selected </#if> >3</option>
                                        <option value="4" <#if pmsLevel == "4" > selected </#if> >4</option>
                                        <option value="5" <#if pmsLevel == "5" > selected </#if> >5</option>
                                    </select>
                                </div>
                            </td>
                            <th class="am-text-middle">节点类型</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <select data-am-selected id="pmsType" name="pmsType">
                                        <option value="0" <#if pmsType == "0" > selected </#if>>全部</option>
                                        <option value="1" <#if pmsType == "1" > selected </#if> >非叶子节点</option>
                                        <option value="2" <#if pmsType == "2" > selected </#if> >叶子节点</option>
                                    </select>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="am-text-middle">是否有效</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <select data-am-selected id="pmsDeleted" name="pmsDeleted">
                                        <option value="-1" <#if pmsDeleted == "-1" > selected </#if>>全部</option>
                                        <option value="0" <#if pmsDeleted == "0" > selected </#if> >有效</option>
                                        <option value="1" <#if pmsDeleted == "1" > selected </#if> >无效</option>
                                    </select>
                                </div>
                            </td>
                            <th class="am-text-middle">资源编码</th>
                            <td>
                                <div class="am-u-sm-10">
                                    <input type="text" id="pmsCode" class="am-form-field am-input-sm"
                                           value="${pmsCode!}"/>
                                </div>
                            </td>
                        </tr>
                        <tr>


                            <td colspan="4">
                                <div align='right'>
                                    <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary"
                                            id="submit-btn">搜索
                                    </button>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
            <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
                <div class="am-btn-toolbar" style="padding-left:.5rem;">
                    <div class="am-btn-group am-btn-group-xs">
                        <@shiro.hasPermission name="PERMISSION_ADD">
                            <button type="button" class="am-btn am-btn-default"
                                    onclick="location.href='${base}/permission/add'">
                                <span class="am-icon-plus"></span> 新增
                            </button>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name="PERMISSION_DELETE">
                            <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"
                                    onclick="deleteAll('${base}/permission/delete')"><span
                                        class="am-icon-trash-o"></span> 删除
                            </button>
                        </@shiro.hasPermission>
                    </div>
                </div>
            </div>
        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <div class="am-scrollable-horizontal">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                        <tr class="am-text-nowrap">
                            <th class="table-check"><input type="checkbox" id="allCheck"></th>
                            <th class="table-id">主键ID</th>
                            <th class="table-title">资源名称</th>
                            <th class="table-title">是否有效</th>
                            <th class="table-title">URL</th>
                            <th class="table-title">CODE</th>
                            <th class="table-title">父ID</th>
                            <th class="table-title">LEVEL</th>
                            <th class="table-title">节点类型</th>
                            <th class="table-title">排序</th>
                            <th class="table-title">创建人</th>
                            <th class="table-date">创建时间</th>
                            <th class="table-title">最近更新人</th>
                            <th class="table-date">最近更新时间</th>
                            <th class="table-title">备注</th>
                            <th class="table-set">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#if (pager.list)?exists>
                            <#list    pager.list as list>
                                <tr>
                                    <td><input type="checkbox" name="ids" value="${list.id}"/></td>
                                    <td>${list.id!}</td>
                                    <td>${list.name!}</td>
                                    <td> <#if (list.isDeleted ==0) >
                                            有效
                                        <#else>
                                            无效
                                        </#if>
                                    </td>
                                    <td>${list.url!}</td>
                                    <td>${list.permission!}</td>
                                    <td>${list.parentId!}</td>
                                    <td>${list.level!}</td>
                                    <td>
                                        <#if (list.type ==1) >
                                            非叶子节点
                                        <#else>
                                            叶子节点
                                        </#if>
                                    </td>
                                    <td>${list.sort!}</td>
                                    <td>${list.creator!}</td>
                                    <td><#if list.createdTime??>${list.createdTime?datetime}</#if></td>
                                    <td>${list.updator!}</td>
                                    <td><#if list.lastUpdatedTime??>${list.lastUpdatedTime?datetime}</#if></td>
                                    <td>${list.remark!}</td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <@shiro.hasPermission name="PERMISSION_EDIT">
                                                    <button type="button"
                                                            class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                            onclick="location.href='${base}/permission/edit?id=${list.id?c}'"><span
                                                                class="am-icon-pencil-square-o"></span>编辑
                                                    </button>
                                                </@shiro.hasPermission>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        </tbody>
                    </table>
                </div>
                <div class="am-cf">
                    <!-- 分页 -->
                    <#if (pager.list)?exists && (pager.list?size>0) >
                        <div class="am-fr">
                            <#include "../common/common_pager.ftl">
                        </div>
                    <#else>
                        <div class="am-kai" align="center">
                            <h3>没有找到任何记录!</h3>
                        </div>
                    </#if>
                </div>

            </div>
        </div>

    </div>
</@defaultLayout.layout>

<script type="text/javascript">

    $(function () {
        $("body").on('click', '.list-item', function () {
            $(".list-item").removeClass("tr-selected");
            $(this).addClass('tr-selected');
        });
        $("#allCheck").click(function () {
            $('input[name="ids"]').prop("checked", this.checked);
            $("#deleteButton").prop("disabled", $("input[name='ids']:checked").length == 0 ? true : false);
        });
        var $citySubBox = $("input[name='ids']");
        $citySubBox.click(function () {
            $("#allCheckCity").prop("checked", $citySubBox.length == $("input[name='ids']:checked").length ? true : false);
            $("#deleteButton").prop("disabled", $("input[name='ids']:checked").length == 0 ? true : false);
        });


        var keywordsObj = {};
        $("#submit-btn").on("click", function () {
            $("#pageNumber").val(1);
            if ($("#pmsName").val())
                keywordsObj.pmsName = $("#pmsName").val();
            if ($("#pmsID").val())
                keywordsObj.pmsID = $("#pmsID").val();
            if ($("#pmsUrl").val())
                keywordsObj.pmsUrl = $("#pmsUrl").val();
            if ($("#pmsParentID").val())
                keywordsObj.pmsParentID = $("#pmsParentID").val();
            if ($("#pmsLevel").val())
                keywordsObj.pmsLevel = $("#pmsLevel").val();
            if ($("#pmsType").val())
                keywordsObj.pmsType = $("#pmsType").val();
            if ($("#pmsDeleted").val()) {
                keywordsObj.pmsDeleted = $("#pmsDeleted").val();
            }
            if ($("#pmsCode").val()) {
                keywordsObj.pmsCode = $("#pmsCode").val();
            }


            var keywords = "";
            if (!$.isEmptyObject(keywordsObj)) {
                keywords = JSON.stringify(keywordsObj);
            }
            console.log("keywords = " + keywords);

            $("#keywords").val(keywords);
            $("#listForm").submit();
        });


    });

    // 删除
    var deleteAll = function (url) {
        var $deleteButton = $("#deleteButton");// 删除按钮
        var ids = "";
        $("input[name='ids']:checked").each(function () {
            ids += $(this).val() + "#%#";
        });
        var params = {ids: ids};
        if (window.confirm('确定要删除吗？')) {
            $.ajax({
                url: url,
                data: params,
                dataType: "json",
                async: false,
                beforeSend: function (data) {
                    $deleteButton.prop("disabled", true)
                },
                success: function (data) {
                    $deleteButton.prop("disabled", false)
                    if (data.status == 0) {
                        layer.alert("删除成功");
                        window.location.href = window.location.href;
                    } else if (data.status == 1) {
                        layer.alert("删除失败");
                    }
                }
            });
        }
    }


</script>
















