
@{
    ViewData["Title"] = "Sku";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "库存", "库存周转报表", "Sku" };
}

<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">
                        <input id="sku" name="sku" class="form-control" style="width:150px" placeholder="Sku编码" />
                        <input id="skuname" name="skuname" class="form-control" style="width:150px" placeholder="Sku中文标题" />
                    </div>
                    <div class="form-group">
                        <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();
        })

        function list() {
            var columns = [
                { field: 'bailun_sku', title: 'sku编码', width: '90', sortable: true },
                {
                    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, iscount: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.sku_title_cn + '">' + data.sku_title_cn + '</div>';
                    }
                },
                {
                    field: 'count_stock', title: '库存数量', width: '110', sortable: true, iscount: true
                },
                {
                    field: 'amount_stock', title: '库存金额', width: '110', sortable: true, iscount: true
                },
                {
                    field: 'count_onway_purchase', title: '采购在途数量', width: '130', sortable: true, iscount: true
                },
                { field: 'amount_onway_purchase', title: '采购在途金额', width: '130', sortable: true, iscount: true },
                {
                    field: 'count_onway_allot', title: '调拨在途数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'amount_onway_allot', title: '调拨在途金额', width: '150', sortable: true, iscount: true
                },
                {
                    field: 'count_unshipping', title: '待发货数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'count_outstock', title: '缺货数量', width: '130', sortable: true, iscount: true
                },
                { field: 'one_day_sale_count', title: '昨日总销量', width: '130', sortable: true, iscount: true },
                { field: 'one_day_sale_amount', title: '昨日总销售额', width: '130', sortable: true, iscount: true },
                { field: 'seven_day_sale_count', title: '七天销量', width: '100', sortable: true, iscount: true },
                { field: 'fourteen_day_sale_count', title: '十四天销量', width: '120', sortable: true, iscount: true },
                { field: 'thirty_day_sale_count', title: '三十天销量', width: '130', sortable: true, iscount: true }
            ];

            var url = '@Url.Content("~/Reports/Sku/ListSkuJson")' + '?' + $("#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() {
            $.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>

}

