
@{
    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="code" name="code" 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>
                    </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{
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script>
        var tb;
        $(document).ready(function (){
            var day = getUrlParam('day');
            if (day != '') {
                $('#day').val(day);
            }

            var code = getUrlParam('code');
            if (code != '') {
                $('#code').val(code);
                if ($('#code').val() == null) {
                    $('#code').append('<option value="' + code + '">' + code + '</option>');
                    $('#code').val(code);
                }
            }

            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: '140', sortable: true, formatter: function (idx, data) {
                        return '<p class="mules" title="' + data.account + '">' + data.account + '</p>';
                    }
                },
                { 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: '150', sortable: true },
                { field: 'put_amount_time', title: '放款时间', width: '130' },
                { field: 'putcount', title: '月放款次数', width: '130', sortable: true},
                {
                    field: 'option', title: '操作', width: '140px', formatter: function (idx, data) {
                        var s = '<button class="btn btn-danger btn-xs" onclick="DelDetail(\'' + rowObject.id + '\');">删除</button>';
                        return s;
                    }
                }
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "",);
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function DelDetail(id) {
            if (confirm('确定要删除该记录吗？')) {
                $.ajax({
                url: '@Url.Content("~/Reports/Finance/DelDailySales")',
                type: "POST",
                data: 'id='+id,
                success: function (result) {
                    if (result.success) {
                        alert("删除成功！");
                        list();
                    }
                    else {
                        alert(result.msg);
                    }
                }
            })
            }
        }
        
        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++) {
                            $('#code').append('<option value="' + result[i].code + '">' + result[i].code + '</option>')
                        }
                    }
                }
            })
        }

    </script>

}


