
@{
    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">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>平台类型：</label>
                        <select id="platform" name="platform" class="form-control">
                            <option value="">选择平台</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>站点：</label>
                        <select id="website" name="website" class="form-control">
                            <option value="">选择站点</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>销售帐号：</label>
                        <select id="account" name="account" class="form-control">
                            <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="@(ViewBag.start)" placeholder="付款开始时间" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(ViewBag.end)" placeholder="付款结束时间" />
                    </div>
                    <div class="form-group">
                        <label>发货时间</label>
                        <input id="shipstart" name="shipstart" type="text" class="form-control" style="width:130px;" value="@(ViewBag.shipstart)" placeholder="发货开始时间" />
                        <span>至</span>
                        <input id="shipend" name="shipend" type="text" class="form-control" style="width:130px;" value="@(ViewBag.shipend)" placeholder="发货结束时间" />
                    </div>
                    <div class="form-group">
                        <label>利润率</label>
                        <input id="rate_start" name="rate_start" type="number" class="form-control" style="width:110px" placeholder="利润率开始" />%
                        <span>至</span>
                        <input id="rate_end" name="rate_end" type="number" class="form-control" style="width:110px;" placeholder="利润率结束" />%
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="orderno" name="orderno" class="form-control" type="text" style="width:180px" value="@(ViewBag.orderno)" 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>
                        <button id="btnexport" style="display:none;" type="button" class="btn btn-success" onclick="exportxls();">导出</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{
    <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;
        var isdoneplatform = false, isdoneaccount = false, isdonewebsite = false;
        var objTime;
        var companyid = 0;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            laydate.render({ elem: '#shipstart' });
            laydate.render({ elem: '#shipend' });

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

            objTime = setInterval(function () {
                if (isdoneaccount && isdoneplatform && isdonewebsite) {
                    list();
                    clearInterval(objTime);
                }
            }, 1000);
            
        })

        function list() {
            var columns = [
                {
                    field: 'origin_order_id', title: '平台单号', width: '160', formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.origin_order_id + '"><a target="_blank" href="http://oms.bailuntec.com/#/bailun-order/all-orders?id=' + data.bailun_order_id+'">' + data.origin_order_id + '</a></div>';
                    }
                },
                {
                    field: 'bailun_order_id', title: '订单号', width: '210', iscount: true, formatter: function (idx,data) {
                        return '<div class="mules" title="' + data.bailun_order_id + '"><a target="_blank" href="http://oms.bailuntec.com/#/bailun-order/all-orders?id=' + data.bailun_order_id + '">' + data.bailun_order_id + '</a></div>';
                    }
                },
                { field: 'platform_type', title: '平台', width: '100' },
                { field: 'website', title: '站点', width: '90' },
                { field: 'seller_account', title: '销售帐号', width: '110', sortable: false },
                {
                    field: 'amount_sales', title: '销售额', width: '90', sortable: true, iscount: true
                },
                { field: 'amount_product', title: '产品收入', width: '110', sortable: true, iscount: true },
                {
                    field: 'amount_shipping', title: '运费收入', width: '110', sortable: true, iscount: true
                },
                { field: 'amount_tax', title: '税费收入', width: '110', sortable: true, iscount: true },
                { field: 'amount_adjustment', title: '调整金额', width: '120', sortable: true, iscount: true },
                { field: 'amount_gift_wrap', title: '礼品包装金额', width: '150', sortable: true, iscount: true },
                //{ field: 'amount_refund', title: '退款金额', width: '90', sortable: true, iscount: true },
                { field: 'cost_total', title: '总支出', width: '110', sortable: true, iscount: true },
                { field: 'cost_promotion', title: '促销费用', width: '110', sortable: true, iscount: true },
                { field: 'cost_platform_fee', title: '平台费用', width: '100', sortable: true, iscount: true },
                { field: 'cost_product', title: '产品成本', width: '100', sortable: true, iscount: true },
                { field: 'cost_package', title: '包装费用', width: '100', sortable: true, iscount: true },
                { field: 'cost_fba_fee', title: 'FBA费用', width: '100', sortable: true, iscount: true },
                { field: 'cost_paypal_fee', title: 'Paypal费用', width: '120', sortable: true, iscount: true },
                { field: 'cost_refund_commisson', title: '退款佣金费用', width: '130', sortable: true, iscount: true },
                { field: 'cost_handle_bailun', title: '处理费(百伦)', width: '130', sortable: true, iscount: true },
                { field: 'cost_handle_platform', title: '第三方仓处理费', width: '130', sortable: true, iscount: true },
                { field: 'cost_first', title: '头程费', width: '100', sortable: true, iscount: true },
                { field: 'cost_logistics', title: '尾程费', width: '120', sortable: true, iscount: true },
                { field: 'profit_total', title: '利润', width: '100', sortable: true, iscount: true },
                { field: 'profit_rate', title: '利润率', width: '100', sortable: true, iscount: true },
                { field: 'amount_prepaid', title: '预收款', width: '100', sortable: true,iscount: true },
                { field: 'create_time', title: '下单时间', width: '150', sortable: true },
                { field: 'paid_time', title: '付款时间', width: '150', sortable: true }
            ];

            var columns_single = [
                {
                    field: 'origin_order_id', title: '平台单号', width: '160', formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.origin_order_id + '">' + data.origin_order_id + '</div>';
                    }
                },
                {
                    field: 'bailun_order_id', title: '订单号', width: '210', iscount: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.bailun_order_id + '">' + data.bailun_order_id + '</div>';
                    }
                },
                { field: 'platform_type', title: '平台', width: '100' },
                { field: 'website', title: '站点', width: '90' },
                { field: 'seller_account', title: '销售帐号', width: '110', sortable: false },
                {
                    field: '@(ViewBag.col)', title: '@(ViewBag.coltitle)', width: '150', sortable: true, iscount: true
                }
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", (@ViewBag.showsingle== 1 ? columns_single : columns), url, "", {
                    showfooter: true, showCount: true, loadsuccess: function (d) {
                        companyid = d.companyid;

                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }

                    }
                }, {
                        fixedcol: true,
                        fixedcolnum: 2
                    });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function listPlatform() {
            var lindex = layer.load();
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListPlatform")',
                type:'POST',
                paramData: '',
                func: function (result) {
                    layer.close(lindex);
                    if (result != null && result != undefined) {
                        $('#platform').html('<option value="">选择平台</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#platform').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }

                        $('#platform').val('@ViewBag.platform');
                        listWebsite();
                        listAccount();
                        isdoneplatform = true;
                    }
                }
            })
        }

        function listWebsite() {
            var lindex = layer.load();
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=' + $('#platform').val(),
                func: function (result) {
                    layer.close(lindex);
                    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>');
                        }

                        $('#website').val('@ViewBag.website');
                        isdonewebsite = true;
                    }
                }
            })
        }

        function listAccount() {
            $.submit({
                type: 'POST',
                url: '@Url.Content("~/Reports/Orders/ListAccount")',
                paramData: 'platform=@(ViewBag.platform)',
                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>');
                        }

                        $('#account').val('@ViewBag.account');
                        isdoneaccount = true;
                    }
                }
            })
        }

        function exportxls() {
            window.open('@Url.Content("~/Reports/Orders/ExportListOrderDetail?")' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
        }


    </script>

}

