
@{
    ViewData["Title"] = "平台余额汇总";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>平台：</label>
                        <select id="platformcode" name="platformcode" class="form-control" style="width: 120px;">
                            <option value="">选择平台</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>日期：</label>
                        <input type="text" class="form-control layer-date" id="day" name="day" style="width:120px;" placeholder="开发开始时间" value="@DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")" />
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button id="btn_Upload" class="btn btn-success">导入</button>
                        <a id="btn_UpdateTemplate" class="btn btn-default" href="@Url.Content("~/templatefile/accountTemplate.xls")" target="_blank">下载导入模版</a>
                    </div>
                </div>
            </form>
        </div>

        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>

@section css{
    <link href="~/js/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
    <style>
        .webuploader-pick {
            position: relative;
            display: block;
            cursor: pointer;
            background: none;
            padding: 0px;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            overflow: hidden;
        }

        .webuploader-container {
            background-color: cornflowerblue !important;
        }
    </style>
}

@section scripts{
    <script src="~/js/webuploader-0.1.5/webuploader.min.js"></script>
    <script>
        var BASE_URL = '@(Url.Content("~/js/webuploader-0.1.5/"))';
        var tb;
        $(document).ready(function () {
            uploadfile('btn_Upload',
                '@Url.Content("~/Reports/Finance/UpdateBalanceCount")',
                function(result){
                    if(result.success)
                    {
                        alert('上传成功！');
                    }
                    else
                    {
                        alert(result.msg);
                    }
            });

            laydate.render({ elem: '#day' });
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 150));

            list();

            listplatform();
        })

        function list() {
            var columns = [
                { field: 'day', title: '统计日期', width: '120' },
                { field: 'platformname', title: '平台名称', width: '120', sortable: false, iscount: true  },
                { field: 'account', title: '帐号数', width: '100', sortable: true, iscount: true },
                { field: 'currency', title: '币种', width: '100', sortable: true},
                { field: 'amount', title: '总金额(原币)', width: '140', sortable: true, iscount: true },
                { field: 'userable_amount', title: '可用余额(原币)', width: '140', sortable: true, iscount: true },
                { field: 'freeze_amount', title: '冻结余额(原币)', width: '140', sortable: true, iscount: true },
                { field: 'puttime', title: '放款时间', width: '130' },
                { field: 'exchangerate', title: '汇率', width: '100'},
                { field: 'amount_rmb', title: '总余额(人民币)', width: '150', sortable: true, iscount: true },
                { field: 'userable_amount_rmb', title: '可用余额(人民币)', width: '140', sortable: true, iscount: true },
                { field: 'freeze_amount_rmb', title: '冻结余额(人民币)', width: '140', sortable: true, iscount: true },
                {
                    field: 'option', title: '操作',width:'120px', formatter: function (idx, data) {
                        var s = '<button class="btn btn-xs btn-primary" onclick="ShowDetail(\'' + data.platformcode + '\',\'' + data.platformname + '\',\'' + data.day + '\');">查看明细</button>';
                        return s;
                    }
                }
            ];

            var url = '@Url.Content("~/Reports/Finance/ListAccoutBalanceCountJson")' + '?' + $("#toolbar").serialize();

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, loadsuccess: function (d) {
                        //替换汇总行的相关列值
                        var tr = $('.fixed-table-footer').find('tr');
                        for (var c in columns) {
                            var key = columns[c].field;
                            if (columns[c].iscount) {
                                for (var v in d.count_row) {
                                    if (key == v) {
                                        tr.find('td').eq(c).children('div').first().html(d.count_row[v]);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }


        function uploadfile(id,url,callback)
        {
            var uploader = new WebUploader.Uploader({
                // swf文件路径
                swf: BASE_URL + 'Uploader.swf',
                // 文件接收服务端。
                server: url!=undefined?url:'@Url.Content("~/File/UploadFile")',
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#'+id,
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                resize: false,
                auto:true
            });

            uploader.on('uploadSuccess', function (file, response) {
                if(callback!=undefined)
                {
                    callback(response);
                }
            });

            uploader.on('uploadError', function (file) {
                layer.msg("上传出错");
            });
        }


        function ShowDetail(code, name, day) {
            showdetail(name + '的平台账号余额明细', '@Url.Content("~/Reports/Finance/ListAccountBalance?code=")' + code + '&day=' + day + '&n=' + name);
        }

        function listplatform() {
            $.ajax({
                url: '@Url.Content("~/Reports/Finance/ListPlatform")',
                type: "POST",
                data: '',
                success: function (result) {
                    if (result && result.length > 0) {
                        for (var i = 0; i < result.length; i++) {
                            $('#platformcode').append('<option value="' + result[i].code + '">' + result[i].code + '</option>');
                        }
                    }
                }
            })
        }

    </script>

}

