<!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('会员卡列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var editOnsaleFlag = [[${@permission.hasPermi('adam:member:edit:onsale')}]] == 'hidden';
    var editFlag = [[${@permission.hasPermi('adam:member:view:edit')}]];
    var viewMemberCodeMgtFlag = [[${@permission.hasPermi('adam:member:code:mgt:list')}]];
    var prefix = ctx + "adam/member";

    $(function() {
        var options = {
            url: prefix + "/list",
            updateUrl: prefix + "/info/{id}",
            sortName: "memberId",
            sortOrder: "asc",
            modalName: "会员设置",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'memberId',
                    title: '会员卡ID'
                },
                {
                    field: 'icon',
                    title: 'ICON',
                    formatter: function (value, row, index) {
                        // var actions = [];
                        // actions.push($.common.sprintf("<img class='img-circle img-xs' src='%s' />", value));
                        // return actions;
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'title',
                    title: '会员卡标题',
                    align: 'center',
                },
                {
                    field: 'subTitle',
                    title: '会员卡说明',
                },
                {
                    field: 'onsale',
                    title: '开售状态',
                    align: 'center',
                    // formatter: function(value, row, index) {
                    //     var actions = [];
                    //     var listClass = "badge badge-" + (value === 1 ? 'primary' : 'danger');
                    //     actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, value === 1 ? '开售' : '停售'));
                    //     return actions;
                    // }
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="onsaleDisable(\'' + row.memberId + '\')"></i> ';
                        } else {
                            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="onsaleEnable(\'' + row.memberId + '\')"></i> ';
                        }
                    }
                },
                {
                    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.editTab(\'' + row.memberId + '\'); setVipTabs()"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + viewMemberCodeMgtFlag + '" href="javascript:void(0)" onclick="memberCodeMgt(\'' + row.memberId + '\')"><i class="fa fa-barcode"></i>会员码管理</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 会员码管理 */
    function memberCodeMgt(memberId) {
        $.modal.openTab("会员码管理", 'adam/mcode/mgt?memberId=' + memberId);
    }

    /* 会员停售 */
    function onsaleDisable(memberId) {
        if (!editOnsaleFlag) {
            $.modal.confirm("确认要停售VIP吗？", function() {
                $.operate.post(prefix + "/edit_onsale", { "memberId": memberId, "onsale": 2 });
            });
        }
    }

    /* 会员开售 */
    function onsaleEnable(memberId) {
        if (!editOnsaleFlag) {
            $.modal.confirm("确认要开售VIP吗？", function() {
                $.operate.post(prefix + "/edit_onsale", { "memberId": memberId, "onsale": 1 });
            });
        }
    }

    function setVipTabs () {
        window.localStorage.setItem('tabActive', 0);
    }
</script>
</body>
</html>