
@{
    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>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(ViewBag.start)" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(ViewBag.end)" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-success" onclick="list();">搜索</button>
                        <button type="button" class="btn btn-primary" onclick="exportFile();">导出</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();
        })

        function list() {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '') {
                alert('请选择开始日期');
                return false;
            }

            if (end == '') {
                alert('请选择结束日期');
                return false;
            }

            var columns = [
                { field: 'origin_order_id', title: '平台单号', width: '160' },
                { field: 'pick_order_id', title: '配货单号', width: '130' },
                { field: 'tracking_order_id', title: '物流跟踪号', width: '130' },
                { field: 'bailun_sku', title: 'Sku', width: '100', iscount: true },
                { field: 'quantity_shipped', title: '发货数量', width: '100' },
                { field: 'bailun_sku_unit_price', title: '采购价', width: '100' },
                { field: 'amount_sale_count', title: '发货成本', width: '130', iscount: true },
                { field: 'shipping_time', title: '发货时间', width: '130' },
            ];

            var url = '@Url.Content("~/Reports/Finance/ListFirstSupplierSaleJson")' + '?start=' + start + '&end=' + end;

            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 exportFile() {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '') {
                alert('请选择开始日期');
                return false;
            }

            if (end == '') {
                alert('请选择结束日期');
                return false;
            }

            window.open('@Url.Content("~/Reports/Finance/ExportFirstSupplierSale?start=")' + start + '&end=' + end, '_blank');
        }



    </script>
}

