
@{
    ViewData["Title"] = "SkuRedundancy";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "库存", "库存分析报表", ViewBag.warehousename + " 库存冗余分析" };
}

<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>&nbsp;</label>
                        <input id="day" name="day" class="form-control" value="@(ViewBag.day)" 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>
                    </div>
                </div>
            </form>
        </div>*@

        <div class="tabs-container">
            <ul class="nav nav-tabs">
                <li class="active" onclick="list2(0)">
                    <a data-toggle="tab" href="#tab-1" aria-expanded="true"> 前100冗余金额sku分析</a>
                </li>
                <li class="" onclick="list2(1)">
                    <a data-toggle="tab" href="#tab-2" aria-expanded="false">前100冗余个数sku分析</a>
                </li>
                <li class="" onclick="list2(2)">
                    <a data-toggle="tab" href="#tab-3" aria-expanded="false">前100个数动销最快sku分析</a>
                </li>
                <li class="" onclick="list2(3)">
                    <a data-toggle="tab" href="#tab-4" aria-expanded="false">前100金额动销最快sku分析</a>
                </li>
            </ul>
            <div class="tab-content">
                <div id="tab-1" class="tab-pane active">
                    <div class="panel-body">
                        <div style="margin-bottom:5px;">
                            <a class="btn btn-success" onclick="exportxls(0);">导出</a>
                        </div>
                        <table id="t1" class="table table-hover table-bordered table-condensed table-striped" style="table-layout:fixed;">
                            <thead>
                                <tr>
                                    <th>sku</th>
                                    <th>产品编码</th>
                                    <th>sku标题</th>
                                    <th>sku库存</th>
                                    <th>在途数</th>
                                    <th>库存总金额</th>
                                    <th>日销产品个数</th>
                                    <th>动销产品比例</th>
                                    <th>日销金额</th>
                                    <th>动销金额比例</th>
                                    <th>冗余产品个数</th>
                                    <th>冗余个数比例</th>
                                    <th>冗余金额</th>
                                    <th>冗余金额比例</th>
                                    <th>监控状态</th>
                                    <th>是否侵权</th>
                                </tr>
                            </thead>
                            <tbody id="tb1"></tbody>
                        </table>
                    </div>
                </div>
                <div id="tab-2" class="tab-pane">
                    <div class="panel-body">
                        <div style="margin-bottom:5px;">
                            <a class="btn btn-success" onclick="exportxls(1);">导出</a>
                        </div>
                        <table id="t2" class="table table-hover table-bordered table-condensed table-striped" style="table-layout:fixed;">
                            <thead>
                                <tr>
                                    <th>sku</th>
                                    <th>产品编码</th>
                                    <th>sku标题</th>
                                    <th>sku库存</th>
                                    <th>在途数</th>
                                    <th>库存总金额</th>
                                    <th>日销产品个数</th>
                                    <th>动销产品比例</th>
                                    <th>日销金额</th>
                                    <th>动销金额比例</th>
                                    <th>冗余产品个数</th>
                                    <th>冗余个数比例</th>
                                    <th>冗余金额</th>
                                    <th>冗余金额比例</th>
                                    <th>监控状态</th>
                                    <th>是否侵权</th>
                                </tr>
                            </thead>
                            <tbody id="tb2"></tbody>
                        </table>
                    </div>
                </div>
                <div id="tab-3" class="tab-pane">
                    <div class="panel-body">
                        <div style="margin-bottom:5px;">
                            <a class="btn btn-success" onclick="exportxls(2);">导出</a>
                        </div>
                        <table id="t3" class="table table-hover table-bordered table-condensed table-striped" style="table-layout:fixed;">
                            <thead>
                                <tr>
                                    <th>sku</th>
                                    <th>产品编码</th>
                                    <th>sku标题</th>
                                    <th>sku库存</th>
                                    <th>在途数</th>
                                    <th>库存总金额</th>
                                    <th>昨日销量</th>
                                    <th>昨日销售金额</th>
                                    <th>过去3天日均</th>
                                    <th>过去7天日均</th>
                                    <th>过去14天日均</th>
                                    <th>过去30天日均</th>
                                    <th>日周转率</th>
                                    <th>周周转率</th>
                                    <th>月周转率</th>
                                    <th>缺货数</th>
                                    <th>监控状态</th>
                                    <th>是否侵权</th>
                                </tr>
                            </thead>
                            <tbody id="tb3"></tbody>
                        </table>
                    </div>
                </div>
                <div id="tab-4" class="tab-pane">
                    <div class="panel-body">
                        <div style="margin-bottom:5px;">
                            <a class="btn btn-success" onclick="exportxls(3);">导出</a>
                        </div>
                        <table id="t4" class="table table-hover table-bordered table-condensed table-striped" style="table-layout:fixed;">
                            <thead>
                                <tr>
                                    <th>sku</th>
                                    <th>产品编码</th>
                                    <th>sku标题</th>
                                    <th>sku库存</th>
                                    <th>在途数</th>
                                    <th>库存总金额</th>
                                    <th>昨日销量</th>
                                    <th>昨日销售金额</th>
                                    <th>过去3天日均</th>
                                    <th>过去7天日均</th>
                                    <th>过去14天日均</th>
                                    <th>过去30天日均</th>
                                    <th>日周转率</th>
                                    <th>周周转率</th>
                                    <th>月周转率</th>
                                    <th>缺货数</th>
                                    <th>监控状态</th>
                                    <th>是否侵权</th>
                                </tr>
                            </thead>
                            <tbody id="tb4"></tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section css{
    <style>
        .tablesorter-headerDesc {
            background-position: right;
            background-repeat: no-repeat;
            padding-right: 30px;
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII=' );
        }

        .tablesorter-headerAsc {
            background-position: right;
            background-repeat: no-repeat;
            padding-right: 30px;
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg==');
        }
    </style>
}

@section scripts{
    <script src="~/js/jquery.tablesorter.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            laydate.render({ elem: '#day' });

            //list();
            list2(0);
        })

        var indexload;
        function list() {
            indexload = layer.load();
            var day = $('#day').val();

            if (day == '') {
                layer.msg('请选择日期');
                return false;
            }

            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Warehouse/SkuRedundancyJson")',
                paramData: 'warehousecode=@(ViewBag.warehousecode)' + '&day=@(ViewBag.day)',
                func: function (result) {
                    layer.close(indexload);
                    if (result != undefined && result != null && result.length == 4) {
                        for (var i in result) {
                            var obj = result[i];
                            
                            var s = '';
                            if (i < 2) {   //前100冗余金额sku分析，前100冗余个数sku分析模版
                                var shtml = '';
                                for (var o in obj) {
                                    shtml += '<tr><td><a href="http://pro.bailuntec.com/proMgr/productMgr?skuCode=' + obj[o].bailun_sku + '" target="_blank" >' + obj[o].bailun_sku + '</a></td>';
                                    shtml += '<td>' + obj[o].sku_product_code + '</td>';
                                    shtml += '<td>' + obj[o].bailun_sku_name + '</td>';
                                    shtml += '<td>' + obj[o].productcount + '</td>';
                                    shtml += '<td>' + obj[o].onway_count + '</td>';
                                    shtml += '<td>' + obj[o].amount_total + '</td>';
                                    shtml += '<td>' + obj[o].daily_productsale_count + '</td>';
                                    shtml += '<td>' + obj[o].productsale_rate + '</td>';
                                    shtml += '<td>' + obj[o].dailysale_amount + '</td>';
                                    shtml += '<td>' + obj[o].saleamount_rate + '</td>';
                                    shtml += '<td>' + obj[o].redundancy_product_count + '</td>';
                                    shtml += '<td>' + obj[o].redundancy_product_rate + '</td>';
                                    shtml += '<td>' + obj[o].redundancy_amount + '</td>';
                                    shtml += '<td>' + obj[o].redundancy_amount_rate + '</td>';
                                    shtml += '</tr>';
                                }

                                $('#tb' + (parseInt(i) + 1)).append(shtml);
                                $('#t' + (parseInt(i) + 1)).trigger("destroy");
                                $('#t' + (parseInt(i) + 1)).tablesorter();
                            }
                            else if(i>1 && i<4){   //前100个数动销最快sku分析，前100金额动销最快sku分析
                                var shtml = '';
                                for (var o in obj) {
                                    shtml += '<tr><td><a href="http://pro.bailuntec.com/proMgr/productMgr?skuCode=' + obj[o].bailun_sku + '" target="_blank" >' + obj[o].bailun_sku + '</a></td>';
                                    shtml += '<td>' + obj[o].sku_product_code + '</td>';
                                    shtml += '<td>' + obj[o].bailun_sku_name + '</td>';
                                    shtml += '<td>' + obj[o].productcount + '</td>';
                                    shtml += '<td>' + obj[o].onway_count + '</td>';
                                    shtml += '<td>' + obj[o].amount_total + '</td>';
                                    shtml += '<td>' + obj[o].yesterdaysale_count + '</td>';
                                    shtml += '<td>' + obj[o].yesterdaysale_amount + '</td>';
                                    shtml += '<td>' + obj[o].sale_3d_avg + '</td>';
                                    shtml += '<td>' + obj[o].sale_7d_avg + '</td>';
                                    shtml += '<td>' + obj[o].sale_14d_avg + '</td>';
                                    shtml += '<td>' + obj[o].sale_30d_avg + '</td>';
                                    shtml += '<td>' + obj[o].day_turnover_rate + '</td>';
                                    shtml += '<td>' + obj[o].week_turnover_rate + '</td>';
                                    shtml += '<td>' + obj[o].month_turnover_rate + '</td>';
                                    shtml += '<td>' + obj[o].stockout + '</td>';
                                    shtml += '</tr>';
                                }

                                $('#tb' + (parseInt(i) + 1)).append(shtml);
                                $('#t' + (parseInt(i) + 1)).trigger("destroy");
                                $('#t' + (parseInt(i) + 1)).tablesorter();
                            }
                        }
                    }
                }
            })
        }

        function list2(i) {

            if ($('#tb' + (parseInt(i) + 1)).html().length > 1) {
                return false;
            }

            indexload = layer.load();
            var day = $('#day').val();

            if (day == '') {
                layer.msg('请选择日期');
                return false;
            }

            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Warehouse/SkuRedundancyJson")',
                paramData: 'warehousecode=@(ViewBag.warehousecode)' + '&day=@(ViewBag.day)'+'&t='+i,
                func: function (result) {
                    layer.close(indexload);
                    if (result != undefined && result != null) {
                        var obj = result;
                        var s = '';
                        if (i < 2) {   //前100冗余金额sku分析，前100冗余个数sku分析模版
                            var shtml = '';
                            for (var o in obj) {
                                shtml += '<tr><td><a href="http://pro.bailuntec.com/proMgr/productMgr?skuCode=' + obj[o].bailun_sku + '" target="_blank" >' + obj[o].bailun_sku + '</a></td>';
                                shtml += '<td>' + obj[o].sku_product_code + '</td>';
                                shtml += '<td>' + obj[o].bailun_sku_name + '</td>';
                                shtml += '<td>' + obj[o].productcount + '</td>';
                                shtml += '<td>' + obj[o].onway_count + '</td>';
                                shtml += '<td>' + obj[o].amount_total + '</td>';
                                shtml += '<td>' + obj[o].daily_productsale_count + '</td>';
                                shtml += '<td>' + obj[o].productsale_rate + '</td>';
                                shtml += '<td>' + obj[o].dailysale_amount + '</td>';
                                shtml += '<td>' + obj[o].saleamount_rate + '</td>';
                                shtml += '<td>' + obj[o].redundancy_product_count + '</td>';
                                shtml += '<td>' + obj[o].redundancy_product_rate + '</td>';
                                shtml += '<td>' + obj[o].redundancy_amount + '</td>';
                                shtml += '<td>' + obj[o].redundancy_amount_rate + '</td>';
                                shtml += '<td>' + (obj[o].monitorstatus==0?"正在监控":"停止监控") + '</td>';
                                shtml += '<td>' + (obj[o].tortstatus==1?"已侵权":"未侵权") + '</td>';
                                shtml += '</tr>';
                            }

                            $('#tb' + (parseInt(i) + 1)).append(shtml);
                            $('#t' + (parseInt(i) + 1)).trigger("destroy");
                            $('#t' + (parseInt(i) + 1)).tablesorter();
                        }
                        else if (i > 1 && i < 4) {   //前100个数动销最快sku分析，前100金额动销最快sku分析
                            var shtml = '';
                            for (var o in obj) {
                                shtml += '<tr><td><a href="http://pro.bailuntec.com/proMgr/productMgr?skuCode=' + obj[o].bailun_sku + '" target="_blank" >' + obj[o].bailun_sku + '</a></td>';
                                shtml += '<td>' + obj[o].sku_product_code + '</td>';
                                shtml += '<td>' + obj[o].bailun_sku_name + '</td>';
                                shtml += '<td>' + obj[o].productcount + '</td>';
                                shtml += '<td>' + obj[o].onway_count + '</td>';
                                shtml += '<td>' + obj[o].amount_total + '</td>';
                                shtml += '<td>' + obj[o].yesterdaysale_count + '</td>';
                                shtml += '<td>' + obj[o].yesterdaysale_amount + '</td>';
                                shtml += '<td>' + obj[o].sale_3d_avg + '</td>';
                                shtml += '<td>' + obj[o].sale_7d_avg + '</td>';
                                shtml += '<td>' + obj[o].sale_14d_avg + '</td>';
                                shtml += '<td>' + obj[o].sale_30d_avg + '</td>';
                                shtml += '<td>' + obj[o].day_turnover_rate + '</td>';
                                shtml += '<td>' + obj[o].week_turnover_rate + '</td>';
                                shtml += '<td>' + obj[o].month_turnover_rate + '</td>';
                                shtml += '<td>' + obj[o].stockout + '</td>';
                                shtml += '<td>' + (obj[o].monitorstatus == 0 ? "正在监控" : "停止监控") + '</td>';
                                shtml += '<td>' + (obj[o].tortstatus == 1 ? "已侵权" : "未侵权") + '</td>';
                                shtml += '</tr>';
                            }

                            $('#tb' + (parseInt(i) + 1)).append(shtml);
                            $('#t' + (parseInt(i) + 1)).trigger("destroy");
                            $('#t' + (parseInt(i) + 1)).tablesorter();
                        }
                    }
                }
            })
        }

        function exportxls(t) {
            window.open('@Url.Content("~/Reports/Warehouse/ExportSkuRedundancy?")'+'warehousecode=@(ViewBag.warehousecode)' + '&day=@(ViewBag.day)'+'&t='+t, '_blank');
        }

    </script>
}

