
@{
    ViewData["Title"] = "Sku仓库";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

<div class="row">
    <div class="col-sm-12">
        <div id="leftcontain" style="position:relative;float:left;width:215px;margin-right:-220px;background-color:#fff;height:600px;border-top:solid 1px #E7EAEC;display:none;">
            <div id="ztree" class="ztree" style="margin:5px 10px;max-height: 600px;overflow: auto;">

            </div>
        </div>
        <div style="float:right;width:100%;">
            <div id="rightcontain">
                <div class="ibox-content m-b-sm border-bottom">
                    <form id="toolbar">
                        <input id="code" name="code" type="hidden" value="@ViewBag.warehousecode" />
                        <div class="form-inline" style="line-height:40px;">
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <button type="button" class="btn btn-success" onclick="showleft();">分类筛选</button>
                            </div>
                            <div class="form-group">
                                <label>产品库</label>
                                <select id="push_status" name="push_status" class="form-control">
                                    <option value="">是否已推送产品库</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>14日日均销量</label>
                                <input id="minordercount" name="minordercount" class="form-control" type="number" style="width:135px;" placeholder="14日均销量开始" />
                                <span>至</span>
                                <input id="maxordercount" name="maxordercount" class="form-control" type="number" style="width:135px;" placeholder="14日均销量结束" />
                            </div>
                            <div class="form-group">
                                <label>库存数量</label>
                                <input id="stockmin" name="stockmin" class="form-control" type="number" style="width:135px;" placeholder="库存数量开始" />
                                <span>至</span>
                                <input id="stockmax" name="stockmax" class="form-control" type="number" style="width:135px;" placeholder="库存数量结束" />
                            </div>
                            <div class="form-group">
                                <label>库存金额</label>
                                <input id="stockamountmin" name="stockamountmin" class="form-control" type="number" style="width:125px;" placeholder="库存金额开始" />
                                <span>至</span>
                                <input id="stockamountmax" name="stockamountmax" class="form-control" type="number" style="width:125px;" 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="ibox-content m-b-sm border-bottom">
                    <table id="roletable" style="table-layout:fixed;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
@section css{
    <link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/jquery.ztree.core.min.js"></script>
    <script src="~/js/jquery.ztree.excheck.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
    <script type="text/javascript">
        var tb;
        var zTreeObj;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));

            list();

            //listwarehouse();

            //listcategory();

            listcategory12();

        })

        function list() {
            var columns = [
                {
                    field: 'bailun_sku', title: 'sku编码', width: '160', sortable: true, formatter: function (idx, data) {
                        if (data.push_status == '是') {
                            return '<a href="http://pro.bailuntec.com/proMgr/productMgr?skuCode=' + data.bailun_sku + '" target="_blank" >' + data.bailun_sku + '</a>';
                        }
                        return data.bailun_sku;

                    }
                },
                { field: 'warehouse_name', title: '所在仓库', width: '110', sortable: true }, 
                {
                    field: 'push_status', title: '推送产品库', width: '120', sortable: true, formatter: function (idx, data) {
                        var s = '<span style="color:' + (data.push_status=='是'?"#01B468":"red") + ';">' + data.push_status + '</span>';
                        return s;
                    }
                }, 
                {
                    field: 'sku_image', title: '主图', width: '80', sortable: false, formatter: function (idx, data) {
                        var s = '<img src="' + data.sku_image + '" style="width:60px" />';
                        return s;
                    }
                },
                {
                    field: 'category_name', title: '分类名称', width: '160', sortable: false, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.category_name + '">' + data.category_name + '</div>';
                    }
                },
                {
                    field: 'sku_title_en', title: '英文标题', width: '160', sortable: false, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.sku_title_en + '">' + data.sku_title_en + '</div>';
                    }
                },
                {
                    field: 'sku_title_cn', title: '中文标题', width: '160', sortable: false, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.sku_title_cn + '">' + data.sku_title_cn + '</div>';
                    }
                },
                {
                    field: 'usable_stock', title: '库存数量', width: '110', sortable: true
                },
                {
                    field: 'amount_stock', title: '库存金额', width: '110', sortable: true
                },
                {
                    field: 'quantity_purchase', title: '采购在途数量', width: '130', sortable: true
                },
                { field: 'purchase_amount', title: '采购在途金额', width: '130', sortable: true },
                {
                    field: 'quantity_transfer', title: '调拨在途数量', width: '130', sortable: true
                },
                {
                    field: 'amount_transit', title: '调拨在途金额', width: '150', sortable: true
                },
                {
                    field: 'noshippingcount', title: '待发货数量', width: '130', sortable: true
                },
                {
                    field: 'nostockcount', title: '缺货数量', width: '130', sortable: true
                },
                { field: 'oneday_total_sales', title: '昨日总销量', width: '130', sortable: true },
                { field: 'amount_onedaysale', title: '昨日总销售额', width: '130', sortable: true },
                { field: 'sevenday_total_sales', title: '七天销量', width: '100', sortable: true },
                { field: 'fourteenday_total_sales', title: '十四天销量', width: '120', sortable: true },
                { field: 'thirtyday_total_sales', title: '三十天销量', width: '130', sortable: true }
            ];

            var s = '';

            try {
                s = getChkNode();
            } catch (e) {
                s = '';
            }

            var url = '@Url.Content("~/Reports/Warehouse/ListWareHouseSkuJson")' + '?' + $("#toolbar").serialize() + '&skucategoryids=' + s;

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "",);
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        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>');
                        }
                    }
                }
            })
        }

        function listcategory() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListSkuCategory")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#categoryid').html('<option value="">请选择sku分类</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#categoryid').append('<option value="' + result[i].c_ID + '">' + result[i].c_NAME + '</option>');
                        }
                    }
                }
            })
        }


        function listcategory12() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListSkuCategoryOneAndSecondLevel")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle:'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, eval('('+result+')'));
                }
            })
        }

        function getChkNode() {
            var s = '';
            var o = $.fn.zTree.getZTreeObj("ztree");
            var nodes = o.getCheckedNodes();
            for (var i in nodes) {
                if (nodes[i].children == null || nodes[i].children.length<=0)
                {
                    s += (nodes[i].id) + '|';
                }
            }

            return s;
        }

        function showleft() {
            var c = $('#leftcontain').css('display');
            if (c == 'none') {
                $('#leftcontain').css('display', 'inline');
                $("#rightcontain").animate({ marginLeft: "220px" });
            }
            else {
                $('#leftcontain').css('display', 'none');
                $("#rightcontain").animate({ marginLeft: "0px" });
            }
        }

    </script>

}

