
@{
    ViewData["Title"] = "itemno的订单明细";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "API", "Item no 广告利润率", "订单明细" };
}

<div class="row">
    <div class="col-sm-12">
        <div style="float:right;width:100%;">
            <div id="rightcontain">
                <div class="ibox-content m-b-sm border-bottom">
                    <button type="button" class="btn btn-primary" onclick="exportxls();">导出订单明细</button>
                </div>

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

                <div class="ibox-content m-b-sm border-bottom">
                    说明：
                    @if (ViewBag.m != null)
                    {
                        <span>总销售GMV：@(ViewBag.m.amount_sales)</span><br />
                        <span>广告GMV：@(ViewBag.m.amount_sales_ad_gmv)</span><br/>
                        <span>广告费：@(ViewBag.m.cost_ad)</span><br/>
                        <span>销售成本（不含广告费）：@(ViewBag.m.cost_sales)</span><br/>
                    }

                    计算公式：
                    @ViewBag.tips  <br />
                    @ViewBag.values
                </div>
            </div>
        </div>
    </div>
</div>
@section css{
    <link href="~/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/bootstrap-table-fixed-columns.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {

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

            list();
        })

        function list() {
            var columns = [
                {
                    field: 'origin_order_id', title: '平台订单号', width: '200', formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.origin_order_id + '">' + data.origin_order_id + '</div>';
                    }
                },
                { field: 'shipping_status', title: '发货状态', width: '120', iscount: true },
                { field: 'amount_sales', title: '销售额', width: '110', iscount: true },
                { field: 'cost_product', title: '产品成本', width: '110', iscount: true },
                { field: 'cost_first', title: '头程费用', width: '110', iscount: true },
                {
                    field: 'cost_logistics', title: '尾程费用', width: '110', iscount: true, formatter: function (idx, data) {
                        return data.cost_logistics + (data.is_forecast==1?"[预估]":"");
                    }
                },
                { field: 'cost_platform_fee', title: '平台费用', width: '110', iscount: true },
                { field: 'cost_handle_platform', title: '操作费', width: '110', iscount: true },
                { field: 'cost_handle_bailun', title: '处理费', width: '110', iscount: true },
                { field: 'cost_paypal_fee', title: 'paypal费', width: '110', sortable: true },
                { field: 'cost_fba_fee', title: 'FBA费', width: '110', iscount: true },
                { field: 'losswithdraw', title: '提现损耗', width: '110', iscount: true }
            ];

            var url = '@Url.Content("~/Reports/Orders/ItemNoProfitOrderDetailJson")' + '?itemid=@(ViewBag.itemid)&day=@(ViewBag.day)';

            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;
                                    }
                                }
                            }
                        }
                    }
                }, {
                        fixedcol: true,
                        fixedcolnum:1
                    });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function exportxls() {
            window.open('@Url.Content("~/Reports/Orders/ExportItemNoProfitOrderDetail")'+'?itemid=@(ViewBag.itemid)&day=@(ViewBag.day)', '_blank');
        }



    </script>

}

