<!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 :: bootstrap-editable-css" />
</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>用户ID：</label>
<!--                                <input type="text" name="userId"/>-->
                                <select name="userId" th:with="users=${@user.getUserList()}">
                                    <option value="">所有</option>
                                    <option th:each="user : ${users}" th:text="${user.userName}" th:value="${user.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>结余周期：</label>
<!--                                <input type="text" name="duration"/>-->
                                <select name="duration" th:with="commons=${@common.getDurationList()}">
                                    <option value="">所有</option>
                                    <option th:each="common : ${commons}" th:text="${common}" th:value="${common}"></option>
                                </select>
                            </li>
<!--                            <li>-->
<!--                                <label>期初数：</label>-->
<!--                                <input type="text" name="openingBalance"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>收入：</label>-->
<!--                                <input type="text" name="income"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>支出：</label>-->
<!--                                <input type="text" name="payment"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>期末数：</label>-->
<!--                                <input type="text" name="closingBalance"/>-->
<!--                            </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:balance:add">-->
<!--                    <i class="fa fa-plus"></i> 添加-->
<!--                </a>-->
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:balance:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:balance:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:balance: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" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:balance:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:balance:remove')}]];
        var prefix = ctx + "business/balance";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "用户结余",
                onEditableSave: onEditableSave,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'balanceId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '用户ID',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '用户名称'
                },
                {
                    field: 'duration',
                    title: '结余周期'
                },
                {
                    field: 'openingBalance',
                    title: '期初数',
                    editable : {
                        type : 'text',
                        title : '期初数',
                        emptytext : "0",
                        validate : function(value) {
                            if (value.length == 0) {
                                return '期初数不能为空';
                            }
                            if (!$.common.isCurrency(value)) {
                                return '期初数应为正的金额';
                            }
                        }
                    }
                },
                {
                    field: 'income',
                    title: '收入'
                },
                {
                    field: 'payment',
                    title: '支出'
                },
                {
                    field: 'closingBalance',
                    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="adjustOpening(\'' + row.balanceId + '\',' + row.openingBalance + ')"><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.balanceId + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
                ]
            };
            $.table.init(options);
        });

        function onEditableSave (field, row, rowIndex, oldValue, $el) {
            $.operate.post(prefix + "/adjustOpening", {"balanceId": row.balanceId, "openingBalance": row.openingBalance}, refreshTable);
        }

        function refreshTable() {
            $.table.refresh();
        }
    </script>
</body>
</html>