<!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="coupon-form">
                    <div class="select-list">
                        <ul>
                            <input type="hidden" name="couType" th:value="${couType}"/>
                            <li>
                                <input type="text" name="mobile" placeholder="请输入手机号码"/>
                            </li>
                            <li>
                                状态：
                                <select name="status" id="">
                                    <option value="0">全部</option>
                                    <option value="1">正常</option>
                                    <option value="2">冻结</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="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="exportSelected()" shiro:hasPermission="monitor:job: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 dicCouponBusiType = [[${@dict.getType('zhengzai_coupon_busi_type')}]];
        var dicCouponBindType = [[${@dict.getType('zhengzai_coupon_bind_type')}]];
        var prefix = ctx + "stone/logs";
        var prefix2 = ctx + "local";

        var viewMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:detail')}]];
        var cancelMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:cancel')}]];

        var couType = [[${couType}]];

        $(function () {
            var options = {
                url: prefix + "/list",
                detailUrl: prefix + "/integralStoreEdit?id={id}",
                removeUrl: prefix + "/cancel/{id}",
                // updateUrl: prefix + "/edit/{id}",
                // exportUrl: prefix + "/export",
                sortName: "createdAt",
                sortOrder: "desc",
                modalName: "积分",
                columns: [
                    {
                        checkbox: true
                    },
                    {
                        field: 'nickName',
                        title: '呢称'
                    },
                    {
                        field: 'mobile',
                        title: '手机号'
                    },
                    {
                        field: 'scoreAll',
                        title: '总积分'
                    },
                    {
                        field: 'scoreUse',
                        title: '已使用积分'
                    },
                    {
                        field: 'scoreRest',
                        title: '剩余积分'
                    },
                    {
                        field: 'status',
                        title: '积分状态',
                        formatter: function (value, row, index) {
                            if (value == 0) {
                                return "全部"
                            } else if (value == 1) {
                                return "正常"
                            } else {
                                return "冻结"
                            }
                        }
                    },
                    {
                        title: '操作',
                        // align: 'center',
                        formatter: function (value, row, index) {
                            let dataArr = [];
                            dataArr.push(`<span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.detailTab('${row.uid}')"><i class="fa fa-search"></i>查看</span>`)
                            if (row.status == 1) {
                                dataArr.push(`<span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openModal('${row.uid}', 2, '冻结后，用户将不可使用积分功能')">冻结</span>`)
                            } else if (row.status == 2) {
                                dataArr.push(`<span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openModal('${row.uid}', 1, '移除冻结后，用户积分账户立即恢复正常使用')">移除冻结</span>`)
                            }
                            return dataArr.join('  ')
                        }
                    }]
            };
            $.table.init(options);
        });

        function openModal(uid, status, title) {
            $.modal.confirm(title, function() {
                let data = {
                    status,
                    uid
                }
                $.ajax({
                    type: 'put',
                    url: prefix + '/change/status',
                    data,
                    success:function(e) {
                        console.log(e)
                    }
                })
            });
        }
        // 导出数据
        function exportSelected() {
        	var userIds = $.table.selectColumns("uid");
        	var dataParam = $("#export-form").serializeArray();
        	var tipMsg = "确定导出所有数据吗？";
        	if($.common.isNotEmpty(userIds)){
        		tipMsg = "确定导出勾选" + userIds.length + "条数据吗？";
        		dataParam.push({ "name": "uid", "value": userIds });
        	}
        	$.modal.confirm(tipMsg, function() {
    			$.post('demo/table/exportData', dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else {
                        $.modal.alertError(result.msg);
                    }
                });
        	});
        }
    </script>
</body>
</html>