<%@ 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="BJGL_BJSQ_DCK_T" html='<a href="${ctx}/platform/fitting/toPendingReviewPage"><li>待审核</li></a>'/>
                <sfTags:pagePermission authFlag="BJGL_BJSQ_BJZT_T" html='<a href="${ctx}/platform/fitting/fittingOnTheWay"><li class="layui-this">待出库</li></a>'/>
                <sfTags:pagePermission authFlag="BJGL_BJSQ_YWC_T" html='<a href="${ctx}/platform/fitting/finishedFitApplyPage"><li>全部申请</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" >
                      <select name="siteId">
                          <option value="">请选择</option>
                          <c:forEach var="site" items="${siteList}">
                              <option value="${site.columns.id}">${site.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">
                      <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="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="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="applyMarks" 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="factoryMarks" class="layui-input" >
                  </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="applyTimeSta" class="layui-input" id="startTime" placeholder="开始日期">
                      </div>
                      <div class="layui-col-xs2 text-c lh-30">
                          —
                      </div>
                      <div class="layui-col-xs5">
                          <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-xs5">
                          <input type="text" name="staconfirmTime" class="layui-input" id="shipStart" placeholder="开始日期">
                      </div>
                      <div class="layui-col-xs2 text-c lh-30">
                          —
                      </div>
                      <div class="layui-col-xs5">
                          <input type="text" name="endconfirmTime" class="layui-input" id="shipEnd" 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="BJGL_BJSQ_ZTBJ_DC_T" html='<button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出
                </button>'/>
                </div>
            </script>
        </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(['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 CKTag = '${fns:checkPagePermission(request, "BJGL_BJSQ_BJZT_CK_B")}';
        var BHTag = '${fns:checkPagePermission(request, "BJGL_BJSQ_BJZT_BH_B")}';
        tableExt.render({
            elem: '#test'
            , height: 'full-240'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/platform/fitting/getAllOnTheWayFitData'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field: 'id', title: '操作', fixed:'left', minWidth:'150', sort: false, align: 'center'  ,templet:function(d){
                    var html="";
                    if(CKTag=='0'){
                        html= html+ '<a class="layui-table-opt-link" href="javascript:ConfirmOutApply(\'' + d.id + '\');"> 出库</a>';
                    }
                   if(BHTag=='0'){
                       html = html +'<a class="layui-table-opt-link" href="javascript:RejectFitting(\'' + d.id + '\',\''+d.fitting_name+'\');"> 驳回</a>';
                   }
                   if(isBlank(html)){
                      html="--";
                   }

                    return html;
                }}
                , {field: 'site_name', title: '服务商名称', minWidth:'150',sort: false, align: 'center', exportable:true}
                , {field: 'fitting_name', title: '备件名称',minWidth:'100', sort: false, align: 'center', exportable:true
          /*          ,templet:function(d){
                        if(fitTag=='0'){return '<a style="color:#D9B589" href="javascript:fittingDetail(\''+d.id+'\');">'+d.fitting_name+'</a>'}else{return d.fitting_name;}
                    }*/
                }
                , {field: 'fitting_code', title: '物料号', minWidth:'150',sort: false, align: 'center', exportable:true}
                , {field: 'fitting_version', title: '备件型号',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'apply_num', title: '申请数量',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'applicant_name', title: '申请人',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'apply_marks', title: '申请备注',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'createTime', title: '申请时间',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'fitting_audit_num', title: '审核数量',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'factory_marks', title: '审核备注',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'confirm_time', title: '审核时间',minWidth:'200', 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
                }
            });
        });

        //申请开始日期
        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 insShipS = laydate.render({
            elem: '#shipStart'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insShipE.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

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

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

    });


    /**
     * 出库
    */
    function ConfirmOutApply(id){
        layer.open({
            type: 2
            , title: '备件出库'
            , content: '${ctx}/platform/fitting/outStockFittingApply?applyId=' + id
            , area: ['1000px', '430px']
            , yes: function(index, layero){

            }
        });
    }


    /*驳回*/
    function RejectFitting(id,name) {
        var indexla = layer.confirm('确认将待出库的'+name+' 驳回？', {
            icon:3,
            btn: ['确定','取消'] //按钮
        }, function(){

            $.ajax({
                type:"POST",
                url:"${ctx}/platform/fitting/RejectFitting",
                data:{
                    id:id
                },
                success:function(result){
                    if(result.code == "200"){
                        layer.msg('操作成功！', {icon:1,time:1000},function(){
                            layer.close(indexla);
                            window.location.reload();
                        });
                    }else if(result.code =="401"){
                        layer.msg('该备件申请已出库不可操作驳回！', {icon:2});
                        window.location.reload();
                    }else{
                        layer.msg('操作失败！', {icon:2});
                        window.location.reload();
                    }
                }
            });


        }, function(){
            layer.close(indexla)
        });
    }



    function fittingDetail(id){
        layer.open({
            type: 2
            , title: '备件信息'
            , content: '${ctx}/platform/fitting/toFittingDetailNo?id=' + id
            , area: ['1000px', '430px']
            , yes: function(index, layero){

            }
        });
    }

    function refundOld(d){
        if(d.old_fitting_flag=='0'){return "否"}else if(d.old_fitting_flag=='1'){return "是"}
    }

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

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

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

