
@{
    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="warehousetype" name="warehousetype" class="form-control">
                            <option value="">选择仓库类型</option>
                            <option value="国内仓">国内仓</option>
                            <option value="海外仓">海外仓</option>
                            <option value="FBA仓">FBA仓</option>
                            <option value="第三方仓库">第三方仓库</option>
                            <option value="半成品仓">半成品仓</option>
                            <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" class="form-control" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" placeholder="请选择统计开始日期" />-
                        <input id="end" name="end" class="form-control" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" placeholder="请选择统计结束日期" />
                    </div>
                    <div class="form-group">
                        <label>开发时间</label>
                        <input id="devstart" name="devstart" class="form-control" value="" placeholder="开发开始时间" />-
                        <input id="devend" name="devend" class="form-control" value="" placeholder="开发结束时间" />
                    </div>
                    <div class="form-group">
                        <label>销量</label>
                        <input id="startcount" name="startcount" class="form-control" placeholder="sku销量开始" />-
                        <input id="endcount" name="endcount" class="form-control" 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>
                        <button type="button" class="btn btn-warning" 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{
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));

            list();

            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });
            laydate.render({ elem: '#devstart' });
            laydate.render({ elem: '#devend' });
            
            listwarehouse();

            $('#warehousetype').change(function () {
                listwarehouse();
            })

        })

        function list() {
            var columns = [
                {
                    field: 'warehouse_name', title: '仓库名称', width: '190', sortable: false, iscount: true, formatter: function (idx, data) {
                        return '<div style="color:#7CABD9;cursor:pointer;" onclick="ShowSku(\'' + data.warehouse_code + '\',\'' + data.warehouse_name + '\')">' + data.warehouse_name + '</div>';
                    }
                },
                { field: 'stock_count', title: '库存数量', width: '110', sortable: true, iscount: true },
                { field: 'stock_amount', title: '库存金额', width: '120', sortable: true, iscount: true },
                { field: 'aliexpress_salecount', title: '速卖通销量', width: '130', sortable: true, iscount: true },
                { field: 'aliexpress_saleamount', title: '速卖通销售额', width: '130', sortable: true, iscount: true },
                { field: 'amazon_salecount', title: '亚马逊销量', width: '120', sortable: true, iscount: true },
                { field: 'amazon_saleamount', title: '亚马逊销售额', width: '120', sortable: true, iscount: true },
                { field: 'fba_salecount', title: 'FBA销量', width: '120', sortable: true, iscount: true },
                { field: 'fba_saleamount', title: 'FBA销售额', width: '120', sortable: true, iscount: true },
                { field: 'ebay_salecount', title: 'Ebay销量', width: '120', sortable: true, iscount: true },
                { field: 'ebay_saleamount', title: 'Ebay销售额', width: '120', sortable: true, iscount: true },
                { field: 'wish_salecount', title: 'Wish销量', width: '120', sortable: true, iscount: true },
                { field: 'wish_saleamount', title: 'Wish销售额', width: '120', sortable: true, iscount: true },
                { field: 'amazon2B_salecount', title: '亚马逊2B销量', width: '130', sortable: true, iscount: true },
                { field: 'amazon2B_saleamount', title: '亚马逊2B销售额', width: '150', sortable: true, iscount: true },
                { field: 'jollychic_salecount', title: 'jollychic销量', width: '120', sortable: true, iscount: true },
                { field: 'jollychic_saleamount', title: 'jollychic销售额', width: '140', sortable: true, iscount: true },
                { field: 'joom_salecount', title: 'Joom销量', width: '120', sortable: true, iscount: true },
                { field: 'joom_saleamount', title: 'Joom销售额', width: '130', sortable: true, iscount: true },
                { field: 'marketing_salecount', title: 'Marketing销量', width: '140', sortable: true, iscount: true },
                { field: 'marketing_saleamount', title: 'Marketing销售额', width: '160', sortable: true, iscount: true },
                { field: 'mymall_salecount', title: 'mymall销量', width: '120', sortable: true, iscount: true },
                { field: 'mymall_saleamount', title: 'mymall销售额', width: '130', sortable: true, iscount: true },
                { field: 'opensky_salecount', title: 'opensky销量', width: '120', sortable: true, iscount: true },
                { field: 'opensky_saleamount', title: 'opensky销售额', width: '140', sortable: true, iscount: true },
                { field: 'priceminister_salecount', title: 'priceminister销量', width: '150', sortable: true, iscount: true },
                { field: 'priceminister_saleamount', title: 'priceminister销售额', width: '160', sortable: true, iscount: true },
                { field: 'qoo10_salecount', title: 'qoo10销量', width: '120', sortable: true, iscount: true },
                { field: 'qoo10_saleamount', title: 'qoo10销售额', width: '140', sortable: true, iscount: true },
                { field: 'shopee_salecount', title: 'shopee销量', width: '120', sortable: true, iscount: true },
                { field: 'shopee_saleamount', title: 'shopee销售额', width: '140', sortable: true, iscount: true },
                { field: 'shopify_salecount', title: 'shopify销量', width: '120', sortable: true, iscount: true },

                { field: 'shopify_saleamount', title: 'shopify销售额', width: '130', sortable: true, iscount: true },
                { field: 'walmart_salecount', title: 'walmart销量', width: '120', sortable: true, iscount: true },
                { field: 'walmart_saleamount', title: 'walmart销售额', width: '130', sortable: true, iscount: true },
                { field: 'salecount', title: '总销量', width: '120', sortable: true, iscount: true },
            ];

            var url = '@Url.Content("~/Reports/Inventory/WarehouseSaleReportJson")' + '?' + $("#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 listwarehouse() {
            var type = $('#warehousetype').val();

            $.submit({
                url: '@Url.Content("~/Home/ListWarehouseFromStockAndSales")',
                paramData: 'warehousetype=' + type,
                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>');
                        }
                    }
                }
            })
        }

        function ShowSku(warehousecode, title) {
            var start = $('#start').val();
            var end = $('#start').val();
            var devstart = $('#devstart').val();
            var devend = $('#devend').val();
            var startcount = $('#startcount').val();
            var endcount = $('#endcount').val();
            layer_show(title + ' 数据仓sku销量明细', '@Url.Content("~/Reports/Inventory/SkuWarehouseSaleReport?warehousecode=")' + warehousecode + '&startcount=' + startcount + '&endcount=' + endcount + '&devstart=' + devstart + '&devend=' + devend + '&start=' + start+'&end='+end, '95%', '95%');
        }

        function ShowHistoryData(warehousecode, col, coltitle,warehousename) {
            var day = $('#day').val();

            layer_show(day + ' ' + warehousename + ' 前两个月的库存分析', '@Url.Content("~/Reports/Warehouse/WHRedundancyChart?warehousecode=")' + warehousecode + '&day=' + day + '&warehousename=' + warehousename + '&col=' + col + '&colname=' + coltitle, '95%', '95%');
        }

        function exportxls() {
            if (confirm("确定要导出明细吗？")) {
                window.open('@Url.Content("~/Reports/Inventory/ExportSkuWarehouseSale?")' + $("#toolbar").serialize(),'_blank')
            }
        }

    </script>

}



