<!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('储值会员卡列表')"/>
</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="id"/>
                        </li>
                        <li>
                            <label>用户名：</label>
                            <input type="text" name="username"/>
                        </li>
                        <li>
                            <label>联系电话：</label>
                            <input type="text" name="mobile"/>
                        </li>
                        <!--<li>
                            <label>会员卡状态：</label>
                            <input type="text" name="cardState"/>
                        </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.add()" shiro:hasPermission="business:card:add">
                <i class="fa fa-plus"></i> 添加
            </a>-->
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="business:card:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="business:card:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:card:export">
                <i class="fa fa-download"></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('business:card:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:card:remove')}]];
    var cardStateDatas = [[${@dict.getType('vip_card_state')}]];
    var prefix = ctx + "vipCard";
    var vipLevelData = [[${@dict.getType('vip_level')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/refund",
            exportUrl: prefix + "/export",
            modalName: "储值会员卡",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '会员卡号',
                    // visible: true
                },
                {
                    field: 'username',
                    title: '用户名'
                },{
                    field: 'mobile',
                    title: '联系电话'
                },
                {
                    field: 'vipLevel',
                    title: '会员等级',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(vipLevelData, value);
                    }
                },
                {
                    field: 'balance',
                    title: '卡内余额'
                },{
                    field: 'score',
                    title: '当前积分'
                },
                {
                    field: 'createTime',
                    title: '开通时间'
                },
                {
                    field: 'refundTime',
                    title: '退卡时间'
                },
                {
                    field: 'cardState',
                    title: '会员卡状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(cardStateDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(row.cardState === "vip_card_state_open"){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="exchange(\'' + row.id + '\')"><i class="fa fa-random"></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 exchange(id){
        $.modal.open("兑换商品", prefix + "/exchange/"+id);
    }
</script>
</body>
</html>