<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>能辉</title>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this sf-tab"><a href="${ctx}/purchaseManage/jzyPurchasePage">报检管理</a></li>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " lay-submit lay-filter="LAY-user-back-search" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">订单编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="number"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">SAP采购号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="spaNumber"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">订单备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="remark"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">检验备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="examineRemark"  autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">入库仓库：</label>
                    <div class="layui-input-block">
                        <select name="warehouseId"  lay-search>
                            <option value="">请选择</option>
                            <c:forEach var="warehouse" items="${warehouse}">
                                <option value="${warehouse.columns.id}">${warehouse.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">检验状态：</label>
                    <div class="layui-input-block">
                        <select name="status"  >
                            <option value="">请选择</option>
                            <option value="1">待检验</option>
                            <option value="2">已检验</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">开始报检时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeSta" id="createTimeSta" class="layui-input"  placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeEnd" id="createTimeEnd" class="layui-input"  placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">本次报检时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="confirmTimeSta" id="confirmTimeSta" class="layui-input"  placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="confirmTimeEnd" id="confirmTimeEnd" class="layui-input"  placeholder="结束日期">
                        </div>
                    </div>
                </div>

                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">检验完成时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="finishTimeSta" id="finishTimeSta" class="layui-input"  placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="finishTimeEnd" id="finishTimeEnd" class="layui-input"  placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="table-toolbar"></table>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/html" id="table-toolbar">
        {{# if(d.status == '1'){ }}
        <a class="layui-table-opt-link" lay-event="examine">检验</a>
        {{# }else{ }}
        --
        {{# } }}
</script>

<script type="text/javascript">
    var table;
    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laydate','form'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
        $ = layui.jquery;
        var laydate = layui.laydate;
        var  form = layui.form;

        table = tableExt.getLayTable();

        //下单时间
        var insStart = laydate.render({
            elem: '#createTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });

        var insEnd = laydate.render({
            elem: '#createTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        //确认时间
        var confirmStart = laydate.render({
            elem: '#confirmTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                confirmEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                confirmEnd.config.elem[0].focus();
            }
        });

        var confirmEnd = laydate.render({
            elem: '#confirmTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                confirmStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        //开始检验时间
        var examineStart = laydate.render({
            elem: '#examineTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                examineEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                examineEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var examineEnd = laydate.render({
            elem: '#examineTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                examineStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //完成时间
        var finishStart = laydate.render({
            elem: '#finishTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                finishEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                finishEnd.config.elem[0].focus();
            }
        });

        var finishEnd = laydate.render({
            elem: '#finishTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                finishStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        tableExt.render({
            elem: '#test-table-reload'
            , height: 'full-180'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/purchaseManage/inspectionPurchaseOrderList'
            ,cols: [[
                {type: 'numbers', title: '序号' ,fixed: 'left'}
                ,{field : 'id', checkbox : true,fixed: 'left' }
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center',minWidth: 90,fixed: 'left' }
                ,{field:'number', title: '订单编号',align: 'center',width: 180,fixed: 'left'
                    ,templet:function(d){
                        return '<a href="#" class="layui-table-link" onclick="orderDetail(\''+d.purchase_id+'\',\''+d.id+'\')">'+d.number+'</a>'
                    }
                }
                ,{field:'supplier_name', title: '供应商',align: 'center',width: 180}
                ,{field:'spa_number', title: 'SAP采购订单号',align: 'center',width: 180}
                ,{field:'status', title: '检验状态',align: 'center' ,width: 90
                    ,templet:function(d){
                        if(d.status=='1'){
                            return "待检验";
                        }else if(d.status=='2'){
                            return "已检验";
                        }else{
                            return "";
                        }
                    }
                }

                ,{field:'id', title: '物料清单',align: 'center',minWidth: 90
                    ,templet:function(d){
                        return '<a href="#" class="layui-table-link" onclick="materialDetail(\''+d.purchase_id+'\',\''+d.id+'\')">查看</a>';
                    }
                }
                ,{field:'orderRemark', title: '订单备注',align: 'center',width: 110}
                ,{field:'warehouse_name', title: '入库仓库',align: 'center',width:110}
                ,{field:'remark', title: '检验备注',align: 'center',width:110}
                ,{field:'inspection_time', title: '开始报检时间',align: 'center',width: 180}
                ,{field:'create_time', title: '本次报检时间',align: 'center',width: 180 }
                ,{field:'finish_time', title: '检验完成时间',align: 'center',width: 180}
            ]]
            ,done: function(res, curr, count){

            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '员工列表',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '员工导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //监听行工具事件
        table.on('tool(table-toolbar)', function(obj){
            var data = obj.data;
            var id = data.id;
            var supplierId=data.supplier_id;
            console.log(data)
           if(obj.event === 'examine'){
                layer.open({
                    type: 2,
                    title: '检验',
                    content: '${ctx}/purchaseManage/examinePurchaseOrderPage?supplierId='+supplierId+'&id=' + id,
                    area: ['80%','80%']
                });
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test-table-reload', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

    });

    window.importMaterial = function (materials) {
        childWin.importMaterial(materials);
    };

    function orderDetail(purchase_id,id){
        layer.open({
            type: 2,
            title: '详情',
            content: '${ctx}/purchaseManage/orderDetail?id=' + purchase_id +'&inspectionId='+id,
            area: ['80%','80%']
        });
    }

    function materialDetail(orderId,id){
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/purchaseManage/orderMaterialList?id=' + orderId+'&inspectionId='+id,
            area: ['80%','80%']
        });
    }

    function reload(){
        table.reload('test-table-reload', {
            page:{
                curr:1
            }
        });
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

</script>
</body>
</html>

