<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('约球购票列表')"/>
</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" class="time-input" placeholder="请选择门票日期" name="ticketDate"
                                   th:value="${ticketDate}"/>
                        </li>
                        <li>
                            <label>场地名称：</label>
                            <input type="text" name="siteName" th:value="${siteName}" data-template="请输入场地名称"/>
                        </li>
                        <li>
                            <label>场地类型:</label>
                            <select name="siteType" th:with="type=${@dict.getType('site_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </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="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('admissionticket:AdmissionTicket:edit')}]];
    var removeFlag = [[${@permission.hasPermi('admissionticket:AdmissionTicket:remove')}]];
    var siteTypeDatas = [[${@dict.getType('site_type')}]];
    var prefix = ctx + "admissionticket";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "约球购票",
            columns: [{
                checkbox: true
            },
                {
                    field: 'venueName',
                    title: '场馆名称'
                },
                {
                    field: 'siteName',
                    title: '场地名称'
                },
                {
                    field: 'siteType',
                    title: '场地类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(siteTypeDatas, value);
                    }
                },
                {
                    field: 'session',
                    title: '场地时段'
                },
                {
                    field: 'price',
                    title: '时段价格'
                },
                {
                    field: 'ticketDate',
                    title: '门票日期'
                },
                {
                    field: 'admissionTicketStatus',
                    title: '预定状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                }, {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.admissionTicketStatus === "2") {
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirm(\'' + row.id + '\')"><i class="fa fa-edit"></i>核销</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    })
    ;

    function statusTools(row) {
        if (row.admissionTicketStatus === "0") {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        } else if (row.admissionTicketStatus === "1") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else if (row.admissionTicketStatus === "2") {
            return "已预定"
        } else if (row.admissionTicketStatus === "3") {
            return "已锁定"
        } else if (row.admissionTicketStatus === "4") {
            return "已核销"
        }
        /*else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }*/
    }

    function confirm(id) {
        $.operate.post(prefix + "/confirm", {"id": id, "admissionTicketStatus": "4"});
    }

    /* 用户管理-停用 */
    function disable(id) {
        $.operate.post(prefix + "/makeAnAppointment", {"id": id, "admissionTicketStatus": "1"});
    }

    /* 用户管理启用 */
    function enable(id) {
        $.operate.post(prefix + "/makeAnAppointment", {"id": id, "admissionTicketStatus": "0"});
    }
</script>
</body>
</html>
