
@{
    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">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>到货仓库：</label>
                        <select id="warehouse" name="warehouse" class="form-control">
                            <option value="">选择仓库</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>采购状态：</label>
                        <select id="status" name="status" class="form-control" style="width:160px;">
                            <option value="">请选择状态</option>
                            <option value="0">待确认</option>
                            <option value="1">已确认</option>
                            <option value="2">主管已审核</option>
                            <option value="3">发货入库中</option>
                            <option value="4">采购完成</option>
                            <option value="-2">拆分订单</option>
                            <option value="-1">作废</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="no" name="no" class="form-control" style="width:130px;" placeholder="采购单号" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input 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>
                    </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 () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();

            listwarehouse();
        })

        function list() {
            var columns = [
                { field: 'purchase_id', title: '采购单号',width:'130',sortable:true },
                { field: 'buy_status', title: '采购状态', width: '100', sortable: true },
                { 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;
                        //return '<div class="mules" title="' + data.sku_image + '">' + data.sku_image+'</div>';
                    }
                },
                {
                    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, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.sku_title_cn + '">' + data.sku_title_cn + '</div>';
                    }
                },
                { field: 'color', title: '颜色', width: '70', sortable: true },
                { field: 'character', title: '规格', width: '70', sortable: true },
                { field: 'price', title: '单价', width: '70', sortable: true },
                { field: 'count', title: '采购数量', width: '100', sortable: true },
                { field: 'amount', title: '合计金额', width: '100', sortable: true },
                { field: 'currency', title: '币种', width: '70', sortable: true },
                { field: 'has_transfer', title: '采购类型', width: '100', sortable: true },
                {
                    field: 'supplier_name', title: '供应商名称', width: '160', sortable: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.supplier_name + '">' + data.supplier_name + '</div>';
                    }
                },
                { field: 'buyer_name', title: '采购员名称', width: '110', sortable: true },
                { field: 'warehouse_name_from', title: '起始仓名称', width: '120', sortable: false },
                { field: 'warehouse_name_to', title: '目标仓名称', width: '120', sortable: false },
                { field: 'sendcount', title: '已发货数量', width: '110', sortable: true, iscount: true },
                { field: 'nosendcount', title: '未发货数量', width: '110', sortable: true, iscount: true },
                { field: 'arrivalcount', title: '已到货数量', width: '110', sortable: false, iscount: true },
                { field: 'noarrivalcount', title: '未到货数量', width: '110', sortable: true, iscount: true },
                //{ field: 'checkcount', title: '校验数量', width: '100', sortable: true, iscount: true },
                //{ field: 'check_success_count', title: '校验通过数量', width: '110', sortable: true, iscount: true },
                //{ field: 'check_fail_count', title: '校验不通过数量', width: '120', sortable: true, iscount: true },
                { field: 'qccount', title: '质检数量', width: '100', sortable: true, iscount: true },
                { field: 'qccount_success', title: '质检通过数量', width: '120', sortable: true, iscount: true },
                { field: 'qccount_fail', title: '质检不通过数量', width: '130', sortable: true, iscount: true },
                { field: 'losscount', title: '缺失数量', width: '100', sortable: true, iscount: true },
                { field: 'breakcount', title: '报损数量', width: '100', sortable: true, iscount: true },
                { field: 'returncount', title: '退货数量', width: '100', sortable: true, iscount: true },
                { field: 'exchangecount', title: '换货数量', width: '100', sortable: true, iscount: true },
                { field: 'putincount', title: '入库数量', width: '100', sortable: true, iscount: true },
                { field: 'waitallotcount', title: '待调拨数量', width: '110', sortable: true, iscount: true },
                { field: 'create_time', title: '创建时间', width: '140', sortable: true },
                { field: 'update_time', title: '更新时间', width: '140', sortable: true },
                { field: 'gmt_modified', title: '同步时间', width: '140', sortable: true }
            ];

            var url = '@Url.Content("~/Reports/Purchase/ListPurchaseJson")' + '?' + $("#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 listAccount() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListAccount")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#saleaccount').html('<option value="">选择帐号</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#saleaccount').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function listWebsite() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=FBA',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#website').html('<option value="">选择站点</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#website').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function listwarehouse() {
            $.submit({
                url: '@Url.Content("~/Home/ListWareHouse")',
                paramData: '',
                type:'POST',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#warehouse').html('<option value="">仓库不限</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#warehouse').append('<option value="' + result[i].warehouse_code + '">' + result[i].warehouse_name + '</option>');
                        }
                    }
                }
            })
        }

    </script>

}


