
@{
    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="platformname" name="platformname" class="form-control" style="width: 120px;">
                            <option value="">选择平台</option>
                            @foreach (var item in ViewBag.listplatform)
                            {
                                <option value="@item">@item</option>
                            }
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <select id="currency" name="currency" 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 platformname = unescape(getUrlParam('n'));
            if (platformname != '') {
                $('#platformname').val(platformname);
                if ($('#platformname').val() == null) {
                    $('#platformname').append('<option value="' + platformname + '">' + platformname + '</option>');
                    $('#platformname').val(platformname);
                }
            }

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

            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: 'amount', title: '总金额(原币)', width: '140', sortable: true},
                { field: 'userable_amount', title: '可用余额(原币)', width: '140', sortable: true},
                { field: 'freeze_amount', title: '冻结余额(原币)', width: '140', sortable: true},
                //{ field: 'puttime', title: '放款时间', width: '130', sortable: true },
                { field: 'exchangerate', title: '汇率', width: '100'},
                { field: 'amount_rmb', title: '总余额(人民币)', width: '150', sortable: true},
                { field: 'userable_amount_rmb', title: '可用余额(人民币)', width: '140', sortable: true},
                { field: 'freeze_amount_rmb', title: '冻结余额(人民币)', width: '140', sortable: true },
                {
                    field: 'notes', title: '备注', width: '140', sortable: false, formatter: function (idx, data) {
                        return '<p class="mules" title="' + data.notes + '">' + data.notes + '</p>';
                    }
                },
                //{ field: 'before_balance', title: '上一期期末', width: '140', sortable: true },
                //{ field: 'amount_sales', title: '平台每日销售额', width: '140', sortable: true },
                //{
                //    field: 'withdraw_amount', title: '平台每日到账额', width: '160', sortable: true, formatter: function (idx, data) {
                //        if (data.fromsource == "oms") {
                //            return '<input id="withdraw_amount_' + data.id + '" type="number" style="width:100px;" value="' + data.withdraw_amount + '" />';
                //        }
                //        else {
                //            return (data.withdraw_amount);
                //        }
                //    }
                //},
                //{ field: 'saleday', title: '初始额统计日期', width: '140', sortable: true },
                //{
                //    field: 'option', title: '操作', width: '140px', formatter: function (idx, data) {
                //        var s = '';
                //        if (data.fromsource == 'oms') {
                //            s += '<button class="btn btn-success btn-xs" onclick="SaveDetail(\'' + data.id + '\');">保存</button>';
                //        }

                //        s+='<button class="btn btn-danger btn-xs" onclick="DelDetail(\'' + data.id + '\');">删除</button>';
                //        return s;
                //    }
                //}
            ];

            var url = '@Url.Content("~/Reports/Finance/ListAccountBalanceJson")' + '?' + $("#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/DelAccountBalance")',
                type: "POST",
                data: 'id='+id,
                success: function (result) {
                    if (result.success) {
                        alert("删除成功！");
                        list();
                    }
                    else {
                        alert(result.msg);
                    }
                }
            })
            }
        }

        function SaveDetail(id) {
            var val = $('#withdraw_amount_' + id).val();
            if (val == '') {
                alert('请输入提现金额');
                return false;
            }

            if (confirm('确定要操作保存吗？')) {
                $.ajax({
                url: '@Url.Content("~/Reports/Finance/SavePlatformBalance")',
                type: "POST",
                data: 'id='+id+'&balance='+val,
                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>

}


