<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>备件申请-待出库</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="SIT_BJGL_XCJSQ_DSH_T" html='<a href="${ctx}/site/apply/toNoauditPage"><li>待审核</li></a>'/>
                <sfTags:pagePermission authFlag="SIT_BJGL_XCJSQ_DSJ_T" html='<a href="${ctx}/site/apply/toWaitReceive"><li>待收件</li></a>'/>
                <sfTags:pagePermission authFlag="SIT_BJGL_XCJSQ_QBSQ_T" html='<a href="${ctx}/site/apply/allApplyPage"><li class="layui-this">全部申请</li></a>'/>
                <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" id="searchBtn" lay-submit lay-filter="LAY-user-back-search">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" 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="fittingCode" 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="fittingName" 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="fittingVersion" 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="suitPrinter" 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="status" id="status" class="layui-bg-gray" lay-filter="status" >
                            <option value="">请选择</option>
                            <option value="1">待审核</option>
                            <option value="2">待出库</option>
                            <option value="3">待收件</option>
                            <option value="4">已完成</option>
                            <option value="5">申请已取消</option>
                            <option value="7">审核未通过</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-xs4">
                            <input type="text" name="applyTimeSta" class="layui-input" id="startTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs1 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs4">
                            <input type="text" name="applyTimeEnd" class="layui-input" id="endTime" 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-xs4">
                            <input type="text" name="confirmTimeMin" class="layui-input" id="confirmTimeMin" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs1 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs4">
                            <input type="text" name="confirmTimeMax" class="layui-input" id="confirmTimeMax" 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-xs4">
                            <input type="text" name="outTimeMin" class="layui-input" id="outTimeMin" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs1 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs4">
                            <input type="text" name="outTimeMax" class="layui-input" id="outTimeMax" 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-xs4">
                            <input type="text" name="sendTimeMin" class="layui-input" id="sendTimeMin" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs1 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs4">
                            <input type="text" name="sendTimeMax" class="layui-input" id="sendTimeMax" 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" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <sfTags:pagePermission authFlag="SIT_BJGL_GCSSQ_QBSQ_DC" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出
                </button>'/>
                </div>
            </script>
        </div>
    </div>
</div>

<div class="layui-form  layui-card hide" id="local">
    <div class="layui-card-body" >
        <div class="layui-col-xs12 mt-20" style="margin-left: -30px" >
            <label class="layui-form-label"><i class="mark">*</i>库位：</label>
            <div class="layui-input-block">
                <input type="text" name="location" id="location" class="layui-input">
            </div>
        </div>
    </div>
</div>

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

        //开始日期
        var insStart = laydate.render({
            elem: '#startTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

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

        //开始日期
        var confirmTimeMin = laydate.render({
            elem: '#confirmTimeMin'
            ,done: function(value, date){
                //更新结束日期的最小日期
                confirmTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                confirmTimeMax.config.elem[0].focus();
            }
        });

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

        //开始日期
        var outTimeMin = laydate.render({
            elem: '#outTimeMin'
            ,done: function(value, date){
                //更新结束日期的最小日期
                outTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                outTimeMax.config.elem[0].focus();
            }
        });

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

        //开始日期
        var sendTimeMin = laydate.render({
            elem: '#sendTimeMin'
            ,done: function(value, date){
                //更新结束日期的最小日期
                sendTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                sendTimeMax.config.elem[0].focus();
            }
        });

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

        tableExt.render({
            elem: '#test'
            , height: 'full-200'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/site/apply/allApplyList'
            , cols: [[
                {title: '序号',type: 'numbers',fixed:'left'}
                , {field: 'id', title: '操作',width:'100', sort: false, fixed:'left',align: 'center'  ,templet:function(d){
                        if (d.status == "1") {
                            return '<a class="layui-table-opt-link" href="javascript:ToExamine(\'' + d.id + '\');"> 查看</a>';
                        } else if (d.status == "3") {
                            return '<a class="layui-table-opt-link" href="javascript:inStock(\'' + d.id + '\');"> 确认入库</a>';
                        } else {
                            return '---';
                        }
                    }}
                , {field: 'status', title: '申请状态',width:'150', sort: false, align: 'center', exportable:true,templet:function(d){
                        if (d.status == "1") {
                            return "待审核";
                        } else if (d.status == "2") {
                            return "待出库";
                        } else if (d.status == "3") {
                            return "待收件";
                        } else if (d.status == "4") {
                            return "已完成";
                        } else if (d.status == "5") {
                            return "申请已取消";
                        } else  {
                            return "审核未通过";
                        }},
                        expFormat:function(d) {
                            if (d.status == "1") {
                                return "待审核";
                            } else if (d.status == "2") {
                                return "待出库";
                            } else if (d.status == "3") {
                                return "待收件";
                            } else if (d.status == "4") {
                                return "已完成";
                            } else if (d.status == "5") {
                                return "申请已取消";
                            } else  {
                                return "审核未通过";
                            }
                        }
                }
                , {field: 'fitting_code', title: '物料号',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'fitting_name', title: '备件名称',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'fitting_version', title: '备件型号',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'suit_printer', title: '适用机型',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'site_price', title: '服务商价格(元)',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'send_time', title: '入库时间',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'out_fitting_marks', title: '出库备注',width:'250', sort: false, align: 'center', exportable:true}
                , {field: 'out_fitting_time', title: '出库时间',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'fitting_audit_num', title: '审核数量',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'confirm_time', title: '审核时间',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'refuse_reason', title: '拒绝理由',width:'200', sort: false, align: 'center', exportable:true}
                , {field: 'apply_marks', title: '申请备注',width:'250', sort: false, align: 'center', exportable:true}
                , {field: 'apply_num', title: '申请数量',width:'150', sort: false, align: 'center', exportable:true}
                , {field: 'applicant_name', title: '申请人',width:'200', sort: false, align: 'center', exportable:true},
                , {field: 'create_time', title: '申请时间',width:'170', sort: false, align: 'center', exportable:true}
            ]],exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '向厂家申请-全部申请',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '向厂家申请-全部申请',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

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

    });

    /*审核*/
    function inStock(id) {
        layer.open({
            type: 1,
            content: $("#local")  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            ,title: "备件详情"
            ,area:["300px","200px"]
            ,btn:['确定', '取消']
            , yes: function(index, layero){
                var location = $("#location").val();
                if(isBlank(location)){
                    layer.msg("请输入库位",{icon :2})
                    return
                }
                $.ajax({
                    url: '${ctx}/site/apply/fittingInStock',
                    type: 'post',
                    data: {
                        id: id,
                        location:location
                    },
                    success: function(data) {
                        if(data.code=="200"){
                            layer.msg("保存成功！",{time:1000},function(){
                                var index = layer.open();
                                layer.close(index)//先得到当前iframe层的索引
                                window.location.reload();
                            });
                        }else{
                            layer.msg("入库失败！");
                        }
                    },
                    complete:function(){
                        noRepeatSub = false;
                    }
                });
            }
        });
    }

    /*查看*/
    function ToExamine(id) {
        layer.open({
            type: 2,
            content: "${ctx}/site/apply/ToExamineForm?applyId="+id  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            ,title: "备件详情"
            ,area:["600px","350px"]
            , yes: function(index, layero){

            }
        });
    }


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

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function layerIFrameReload(layerIndex) {
        window['layui-layer-iframe' + layerIndex].location.reload();
    }
</script>
</body>
</html>

