
@{
    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">
                <input id="isfba" name="isfba" type="hidden" value="0" />
                <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>&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 () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));

            list();

            listwarehouse();

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

        })

        function list() {
            var columns = [
                {
                    field: 'warehouse_name', title: '存储仓库', width: '190', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="SkuDetail(\'' + data.warehouse_code + '\')">' + data.warehouse_name + '</a>';
                    }
                },
                {
                    field: 'usable_stock', title: '库存数量', width: '110', sortable: true, iscount: true
                },
                {
                    field: 'amount_stock', title: '库存金额', width: '110', sortable: true, iscount: true
                },
                {
                    field: 'quantity_purchase', title: '采购在途数量', width: '130', sortable: true, iscount: true
                },
                { field: 'purchase_amount', title: '采购在途金额', width: '130', sortable: true, iscount: true },
                {
                    field: 'quantity_transfer', title: '调拨在途数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'amount_transit', title: '调拨在途金额', width: '150', sortable: true, iscount: true
                },
                {
                    field: 'noshippingcount', title: '待发货数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'nostockcount', title: '缺货数量', width: '130', sortable: true, iscount: true
                },
                { field: 'oneday_total_sales', title: '昨日总销量', width: '130', sortable: true, iscount: true },
                { field: 'amount_onedaysale', title: '昨日总销售额', width: '130', sortable: true, iscount: true },
                { field: 'sevenday_total_sales', title: '七天销量', width: '100', sortable: true, iscount: true },
                { field: 'fourteenday_total_sales', title: '十四天销量', width: '120', sortable: true, iscount: true },
                { field: 'thirtyday_total_sales', title: '三十天销量', width: '130', sortable: true, iscount: true }
            ];

            var url = '@Url.Content("~/Reports/Warehouse/LogicWarehouseJson")' + '?' + $("#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 SkuDetail(code) {
            layer_show('Sku仓库', '@Url.Content("~/Reports/Warehouse/ListWareHouseSku?code=")' + code,'90%','90%');
        }

    </script>

}


