
@{
    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/dailysale_template.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/UploadDailySales")',
                function(result){
                    if(result.result.success)
                    {
                        alert('上传成功！');
                    }
                    else
                    {
                        alert(result.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 },
                { field: 'account', title: '帐号数', width: '100', sortable: true},
                { field: 'currency', title: '币种', width: '100', sortable: true},
                { field: 'put_amount', title: '放款金额(原币)', width: '140', sortable: true},
                { field: 'put_amount_rmb', title: '放款金额(人民币)', width: '140', sortable: true},
                { field: 'freeze_amount', title: '冻结金额(原币)', width: '140', sortable: true},
                { field: 'freeze_amount_rmb', title: '冻结金额(人民币)', width: '140', sortable: true },
                { field: 'put_amount_time', title: '放款时间', width: '130'},
                {
                    field: 'option', title: '操作',width:'120px', formatter: function (idx, data) {
                        var s = '<button class="btn btn-primary" onclick="ShowDetail(\'' + data.platformcode + '\',\'' + data.platformname + '\',\'' + data.day + '\');">查看明细</button>';
                        return s;
                    }
                }
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "",);
            }
            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/DailySales?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>

}


