
@{
    ViewData["Title"] = "数据仓Sku销售分销";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

<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;">
                    <input type="hidden" id="warehousecode" name="warehousecode" value="@ViewBag.warehousecode" />
                    <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="@ViewBag.devstart" placeholder="开发开始时间" />-
                        <input id="devend" name="devend" class="form-control" value="@ViewBag.devend" placeholder="开发结束时间" />
                    </div>
                    <div class="form-group">
                        <label>销量</label>
                        <input id="startcount" name="startcount" class="form-control" placeholder="sku销量开始" value="@ViewBag.startcount" />-
                        <input id="endcount" name="endcount" class="form-control" placeholder="sku销量结束" value="@ViewBag.endcount" />
                    </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();

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

        function list() {
            var columns = [
                {
                    field: 'bailun_sku', title: 'Sku', width: '110', sortable: false, iscount: false
                },
                {
                    field: 'bailun_sku_name', title: 'sku名称', width: '180', sortable: false, iscount: false, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.bailun_sku_name + '">' + data.bailun_sku_name + '</div>';
                    }
                },
                {
                    field: 'warehouse_name', title: '仓库名称', width: '190', sortable: false, iscount: true
                },
                { 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/SkuWarehouseSaleReportJson")' + '?' + $("#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 });
            }
        }
        
    </script>

}

