<%@ 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="CKGL_CRKJL_CRKJL_T" html='<a href="${ctx}/materialKeep/inOrOutRecord"><li class="layui-this">入库记录</li></a>'/>
                <sfTags:pagePermission authFlag="CKGL_CRKJL_CKJL_T" html='<a href="${ctx}/materialKeep/outWarehouseRecord"><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" >
            <form class="layui-form layui-card" action="" id="searchForm">
               <div class="layui-form-item">
                <c:if test="${userType eq '1'}">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">物料归属：</label>
                    <div class="layui-input-block">
                        <div id="belong"></div>
                    </div>
                </div>
                </c:if>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">物料代码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="code" 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="materialType" >
                            <option value="">请选择</option>
                            <c:forEach items="${types}" var="type">
                                <option value="${type.columns.name}" >${type.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="materialRemarks" 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="source" >
                            <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="6" >调拨出库</option>--%>
                            <option value="7" >盘点</option>
                          <%--  <option value="8" >出库单</option>
                            <option value="9" >退货出库</option>--%>
                            <option value="a" >退货入库</option>
                            <option value="b" >企企入库</option>
                            <option value="c" >库存初始化</option>
                        </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="creator" 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 items="${wares}" var="ware">
                                <option value="${ware.columns.id}" >${ware.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="sourceCode" 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="deliveryMethod" >
                            <option value="">请选择</option>
                            <c:forEach items="${deliveryMethods}" var="deliveryMethod">
                                <option value="${deliveryMethod.columns.name}" >${deliveryMethod.columns.name}</option>
                            </c:forEach>
                        </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" class="layui-input" id="endStartTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeEnd" class="layui-input" id="endEndTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
            </form>
        </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">
                    <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>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script>
    var belongSelect;
    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;
        table = tableExt.getLayTable();

        //开始日期
        var endStartTime = laydate.render({
            elem: '#endStartTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#endEndTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新开始日期的最大日期
                endStartTime.config.max = lay.extend({}, date, {
                    day: date.day - 1
                });
            }
        });
        <c:if test="${userType eq '1'}">
        belongSelect = xmSelect.render({
            el: '#belong',
            name: 'belong',
            size: 'mini',
            filterable: true,
            model: {
                label: {
                    type: 'block',
                    block: {
                        //最大显示数量, 0:不限制
                        showCount: 1,
                        //是否显示删除图标
                        showIcon: true,
                    }
                }
            },
            toolbar: {
                show: true
            },
            height: '300px',
            data: [
                {name:'供应链', value:'a' },
                <c:forEach items="${traderList}" var="trader">
                {name:'${trader.columns.name}', value:'${trader.columns.id}' },
                </c:forEach>
                <c:forEach items="${supplyList}" var="supply">
                {name:'${supply.columns.name}', value:'${supply.columns.id}' },
                </c:forEach>
            ]
        });
        belongSelect.setValue('${map.belong}'.split(","));
        </c:if>
        tableExt.render({
            elem: '#test'
            , title:'出入库记录'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/materialKeep/materialKeepList?type=1'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}

                , {field: 'material_code', title: '物料代码',minWidth:'160', sort: false, align: 'center',exportable:true}
                , {field: 'material_name', title: '物料名称',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'material_type', title: '物料类型',minWidth:'120', sort: false, align: 'center', exportable:true}
                , {field: 'material_specs', title: '物料规格',minWidth:'150', sort: false, align: 'center', exportable:true
                    ,templet:function(d){
                        if (d.material_type == '组件') {
                            return d.material_specs+"Wp";
                        } else {
                            return d.material_specs;
                        }
                    },expFormat:function(d){
                        if (d.material_type == '组件') {
                            return d.material_specs+"Wp";
                        } else {
                            return d.material_specs;
                        }
                    }
                }
                , {field: 'material_brand', title: '供应商名称',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'batch_code', title: '入库批次',minWidth:'170', sort: false, align: 'center',exportable:true}
                , {field: 'amount', title: '入库数量',minWidth:'100', sort: false, align: 'center', exportable:true
                    /*,templet:function(d){
                        if(d.type == '1'){
                            return "+ "+d.amount;
                        }else if(d.type=='2'){
                            return "- "+d.amount;
                        } else {
                            return d.amount;
                        }
                    }
                    ,expFormat:function(d){
                        if(d.type == '1'){
                            return "+ "+d.amount;
                        }else if(d.type=='2'){
                            return "- "+d.amount;
                        } else {
                            return d.amount;
                        }
                    }*/
                }
                <c:if test="${userType eq '1' }">
                // , {field: 'cost_price', title: '采购单价',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'bd_sale_price', title: '零售单价',minWidth:'100', sort: false, align: 'center',exportable:true}
                </c:if>
                , {field: 'material_unit', title: '库存单位',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'source', title: '入库类型',minWidth:'150', sort: false, align: 'center', exportable:true
                    ,templet:function(d){
                        if(d.source=='1'){
                            return "采购入库";
                        }else if(d.source=='2'){
                            return "订单入库";
                        }else if(d.source=='3'){
                            return "调拨入库";
                        }else if(d.source=='4'){
                            return "发货出库";
                        }else if(d.source=='5'){
                            return "使用出库";
                        }else if(d.source=='6'){
                            return "调拨出库";
                        }else if(d.source=='7'){
                            return "盘点";
                        }else if(d.source=='8'){
                            return "入库单";
                        }else if(d.source=='9'){
                            return "退货出库";
                        }else if(d.source=='a'){
                            return "退货入库";
                        }else if(d.source=='b'){
                            return "企企入库";
                        }else if(d.source=='c'){
                            return "库存初始化";
                        }
                    }
                    ,expFormat:function(d){
                        if(d.source=='1'){
                            return "采购入库";
                        }else if(d.source=='2'){
                            return "订单入库";
                        }else if(d.source=='3'){
                            return "调拨入库";
                        }else if(d.source=='4'){
                            return "发货出库";
                        }else if(d.source=='5'){
                            return "使用出库";
                        }else if(d.source=='6'){
                            return "调拨出库";
                        }else if(d.source=='7'){
                            return "盘点";
                        }else if(d.source=='8'){
                            return "入库单";
                        }else if(d.source=='9'){
                            return "退货出库";
                        }else if(d.source=='a'){
                            return "退货入库";
                        }else if(d.source=='b'){
                            return "企企入库";
                        }else if(d.source=='c'){
                            return "库存初始化";
                        }
                    }
                }
                , {field: 'warehouse_name', title: '仓库名称',minWidth:'240', sort: false, align: 'center',exportable:true}
                , {field: 'ascription_name', title: '仓库归属',minWidth:'180', sort: false, align: 'center',exportable:true}
                , {field: 'delivery_method', title: '发货方式',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'source_code', title: '关联单号',minWidth:'160', sort: false, align: 'center',exportable:true}
                , {field: 'creator', title: '操作人',minWidth:'150', sort: false, align: 'center',exportable:true}
               /* , {field: 'material_remarks', title: '物料描述',minWidth:'130', sort: false, align: 'center',exportable:true}*/
             /*   , {field: 'material_brand', title: '物料品牌',minWidth:'150', sort: false, align: 'center', exportable:true}*/
                , {field: 'create_time', title: '入库时间',minWidth:'180', sort: false, align: 'center',exportable:true}

            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '入库记录',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当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
                }
            });
        });

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })


    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }
    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("");
        <c:if test="${userType eq '1'}">
        belongSelect.reset();
        </c:if>
    }
</script>
</body>
</html>


