
@{
    ViewData["Title"] = "财务费用";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "统计", "亚马逊", "财务费用" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <input id="platform" name="platform" type="hidden" value="@ViewBag.platform" />
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>费用类型：</label>
                        <select id="feetype" name="feetype" class="form-control">
                            @*<option value="1">财务费用</option>*@
                            <option value="2">销售费用</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>费用性质：</label>
                        <select id="feecharacter" name="feecharacter" class="form-control">
                            <option value="">请选择费用性质</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>销售帐号：</label>
                        <select id="account" name="account" class="form-control" style="width:160px;">
                            <option value="">选择帐号</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>付款时间</label>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="orderno" name="orderno" class="form-control" style="width:160px;" placeholder="平台订单号" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <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 type="text/javascript">
        var tb;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();

            listAccount();
        })

        function list() {
            var columns = [
                { field: 'origin_order_id', title: '订单号',width:'190',sortable:true },
                { field: 'platform_type', title: '平台名称', width: '100', sortable: true },
                { field: 'website', title: '平台站点', width: '90', sortable: true, iscount: true },
                {
                    field: 'seller_account', title: '卖家帐号', width: '160', sortable: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.seller_account + '">' + data.seller_account+'</div>';
                    }
                },
                //{ field: 'bailun_sku', title: 'Sku', width: '100', iscount: true },
                { field: 'amount_sales', title: '销售额', width: '100', sortable: true, iscount: true },
                { field: 'cost_platform_fee', title: '平台费', width: '100', sortable: true, iscount: true },
                { field: 'platform_fee_rate', title: '佣金比例%', width: '90' },
                { field: 'amount_shipping', title: '运费收入', width: '90', sortable: true, iscount: true },
                { field: 'cost_promotion', title: '促销费', width: '90', sortable: true, iscount: true },
                { field: 'cost_first', title: '头程费', width: '110', sortable: true, iscount: true },
                { field: 'cost_logistics', title: '尾程费', width: '100', sortable: true, iscount: true },
                
                { field: 'cost_fba_fee', title: 'fba费用', width: '100', sortable: true, iscount: true },
                
                { field: 'losswithdrawal', title: '提现损耗', width: '100', sortable: true, iscount: true },
                //{ field: 'amount_total', title: '总收入', width: '90', sortable: true, iscount: true },
                //{ field: 'cost_total', title: '总支出', width: '90', sortable: true, iscount: true },
                { field: 'paid_time', title: '付款时间', width: '140', sortable: true }
            ];

            var url = '@Url.Content("~/Reports/Orders/FinanceFeeJson")' + '?' + $("#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 listAccount() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListAccount")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#account').html('<option value="">选择帐号</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#account').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function listWebsite() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#website').html('<option value="">选择站点</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#website').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

    </script>

}

