<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('球场管理列表')" />
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/js/bootstrap-switch.min.js"></script>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addToSet()" shiro:hasPermission="system:site:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:site:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:site:remove')}]];
        var siteTypeDatas = [[${@dict.getType('site_type')}]];
        var prefix = ctx + "system/site";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "球场管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'siteType',
                    title: '分类',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(siteTypeDatas, value);
                    }
                },
                {
                    field: 'cover',
                    title: '封面',
                    visible: false
                },
                {
                    field: 'intro',
                    title: '简介',
                    visible: false
                },
                {
                    field: 'price',
                    title: '价格'
                },
                {
                    field: 'warmReminder',
                    title: '温馨提示'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    field: 'siteStatus',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'venueName',
                    title: '场馆名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        /* 球场状态显示 */
        function statusTools(row) {
            if (row.siteStatus == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 球场状态-停用 */
        function disable(id) {
            $.modal.confirm("确认要停用该球场吗？", function() {
                $.operate.post(prefix + "/siteStatus", { "id": id, "siteStatus": 1 });
            })
        }

        /* 球场状态-启用 */
        function enable(id) {
            $.modal.confirm("确认要启用该球场吗？", function() {
                $.operate.post(prefix + "/siteStatus", { "id": id, "siteStatus": 0 });
            })
        }
    </script>
</body>
</html>