
@{
    ViewData["Title"] = "ListSkuDiffWeigh";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "Sku", "Sku发货重量差异" };
}

<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>发货时间</label>
                        <input id="shipstart" name="shipstart" type="text" class="form-control" style="width:130px;" placeholder="发货开始时间" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
                        <span>至</span>
                        <input id="shipend" name="shipend" type="text" class="form-control" style="width:130px;" placeholder="发货结束时间" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
                    </div>
                    <div class="form-group">
                        <label>差异范围</label>
                        <input id="min" name="min" type="number" class="form-control" style="width:140px" placeholder="差异范围开始值" />
                        <span>至</span>
                        <input id="max" name="max" type="number" class="form-control" style="width:140px" placeholder="差异范围结束值" />
                    </div>
                    <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>
                        </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>sku</label>
                        <input type="text" id="sku" name="sku" class="form-control" style="width:130px" placeholder="sku编码" />
                    </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>
                        <button id="btnexport" style="display:none;" type="button" class="btn btn-success" onclick="exportxls();">导出</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 scripts{
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            laydate.render({ elem: '#shipstart' });
            laydate.render({ elem: '#shipend' });
            list();

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

        function list() {
            var columns = [
                {
                    field: 'day', title: '日期', width: '160'
                },
                {
                    field: 'pick_order_id', title: '配货单号', width: '160'
                },
                {
                    field:'warehouse_name',title:'发货仓库',width:'130'
                },
                {
                    field: 'bailun_sku', title: 'sku编码', width: '160'
                },
                { field: 'weight', title: 'sku重量g', width: '130', sortable: true },
                { field: 'bailun_sku_outbound_weight', title: '发货重量g', width: '130', sortable: true, iscount: true },
                { field: 'diffweigh', title: '差异值g', width: '130', sortable: true }
            ];

            var url = '@Url.Content("~/Reports/Sku/ListSkuDiffWeighJson")' + '?' + $("#toolbar").serialize();

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    loadsuccess: function (d) {
                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }
                    }
                });
            }
            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 exportxls() {
            window.open("@Url.Content("~/Reports/Sku/ExportSkuDiffWeigh")" + '?' + $("#toolbar").serialize(), '_blank');
        }
        
    </script>

}

