
@{
    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>
                        </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>变化情况：</label>
                        <select id="type" name="type" class="form-control" style="width:160px;">
                            <option value="">请选择</option>
                            <option value="1">上升</option>
                            <option value="2">下降</option>
                            <option value="0">不变</option>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="transfer_order_id" name="transfer_order_id" class="form-control" style="width:130px" placeholder="调拨单号" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="bailun_sku" name="bailun_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 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: 'channel_order_id', title: '物流单号', width: '180' },
                { field: 'transfer_order_id', title: '调拨单号', width: '150'},
                { field: 'box_id', title: '箱号', width: '80'},
                { field: 'cost_first', title: '箱子总头程费', width: '130' },
                { field: 'warehouse_name', title: '仓库', width: '180'},
                { field: 'bailun_sku', title: 'SKU', width: '130' },
                { field: 'quantity', title: 'SKU数量', width: '100' },
                { field: 'sku_weight', title: '单个SKU重量', width: '130' },
                { field: 'sku_weight_ratio', title: 'SKU重量占比%', width: '130' },
                { field: 'sku_stock_quantity', title: 'SKU当时库存', width: '130' },
                { field: 'pre_avl_sku_cost_first', title: '原头程费', width: '100', sortable: true },
                { field: 'after_avl_sku_cost_first', title: '新头程费', width: '100', sortable: true },
                {
                    field: 'change_rate', title: '变化%', width: '130', sortable: true, formatter: function (idx, data) {
                        return data.change_rate + " <span style=\"color:" + (data.exception_type == 1 ? "red" : (data.exception_type == 2 ? "green" : "#333333"))+"\">" + (data.exception_type == 1 ? "上升" : (data.exception_type==2?"下降":"不变"))+"</span>"
                    }
                },
                { field: 'operation_time', title: '调拨单完成时间', width: '150', sortable: true },
                { field: 'bj_create_time', title: '创建时间', width: '150', sortable: true },
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: false, 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/Warehouse/ExportLogicWarehouse?")' + $("#toolbar").serialize(), '_blank');
        }

        function SkuDetail(code) {
            layer_show('Sku仓库', '@Url.Content("~/Reports/Warehouse/ListWareHouseSku?code=")' + code,'90%','90%');
        }

    </script>

}