
@{
    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" style="width:160px;">
                            <option value="">选择帐号</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>仓库：</label>
                        <select id="warehousecode" name="warehousecode" 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(-1).ToString("yyyy-MM-dd"))" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="sku" name="sku" class="form-control" style="width:130px;" placeholder="sku编码" />
                    </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();

            listWebsite();

            listwarehouse();

            listPlatform();
        })

        function list() {
            var columns = [
                { field: 'platform_type', title: '平台名称', width: '100', sortable: false },
                {
                    field: 'bailun_sku', title: 'sku', width: '160', sortable: false, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.bailun_sku + '">' + data.bailun_sku+'</div>';
                    }
                },
                { field: 'warehouse_name', title: '仓库名称', width: '110', sortable: false, iscount: true},
                { field: 'ordercount', title: '订单数', width: '100', sortable: true, iscount: true },
                { field: 'count', title: '下单总数量', width: '130', sortable: true, iscount: true },
                { field: 'shippingcount', title: '总发货数量', width: '130', sortable: true, iscount: true }
            ];

            var url = '@Url.Content("~/Reports/Orders/OrderSaleCountJson")' + '?' + $("#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: '',
                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: '',
                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>');
                        }
                    }
                }
            })
        }

        function listPlatform() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListPlatform")',
                type:'POST',
                paramData: '',
                func: function (result) {
                    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>');
                        }
                    }
                }
            })
        }

        function listwarehouse() {
            $.submit({
                url: '@Url.Content("~/Home/ListWareHouse")',
                paramData: '',
                type:'POST',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#warehousecode').html('<option value="">仓库不限</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#warehousecode').append('<option value="' + result[i].warehouse_code + '">' + result[i].warehouse_name + '</option>');
                        }
                    }
                }
            })
        }

    </script>

}

