<%@ 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" />
    <style>
        xm-select {
            min-height: 30px;
            line-height: 36px;
        }
        .sele dl{
            max-width: 100px;
        }
        .mr-2{margin-right: 2px}

    </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">
                <sfTags:pagePermission authFlag="CKGL_CRKJL_CRKJL_T" html='<a href="${ctx}/materialKeep/fittingInventoryStatistics"><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" >
            <form class="layui-form layui-card" action="" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label"><i class="red mr-2">*</i>统计时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="startCreateTime"  class="layui-input" id="startCreateTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="endCreateTime"  class="layui-input" id="endCreateTime" placeholder="结束日期">
                        </div>
                    </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="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">
                        <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="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">
                        <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">
                        <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>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm4">
                    <label class="layui-form-label">物料归属：</label>
                    <div class="layui-input-block">
                        <%--  <div id="belong"></div>--%>
                        <div id="demo1" class="xm-select-demo"></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 demo1;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){

        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        layer.msg("点击查询获取统计数据",{time:2500});


        //开始日期
        var endStartTime = laydate.render({
            elem: '#startCreateTime'
            ,value:'${startTime}'
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#endCreateTime'
            ,value: new Date()
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新开始日期的最大日期
                endEndTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });


        $.ajax({
            url:'${ctx}/materialKeep/findMaterialOwnership',
            method:'post',
            dataType:'JSON',
            success:function(result){
                demo1 = xmSelect.render({
                    el: '#demo1',
                    name: 'belong',
                    autoRow: true,
                    size: 'mini',
                    filterable: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: [ -3 ],
                    },
                    toolbar: {
                        show: true,
                        list: ['ALL', 'REVERSE', 'CLEAR']
                    },
                    model: {
                        label: {
                            type: 'block',
                            block: {
                                //最大显示数量, 0:不限制
                                showCount: 4,
                                //是否显示删除图标
                                showIcon: true,
                            }
                        }
                    },
                    filterable: true,
                    height: 'auto',
                    data: result
                })
            },
            error:function (data) {
            }
        }) ;


        tableExt.render({
            elem: '#test'
            , title:'进销存统计'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/materialKeep/fittingInventoryStatisticsData'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field: 'ascription_name', title: '仓库归属',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'warehouse_name', title: '仓库名称',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'material_name', title: '物料名称',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'material_specs', title: '物料规格',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'material_brand', title: '物料品牌',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'material_unit', title: '库存单位',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'material_code', title: '物料代码',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'qcJcAmount', title: '期初结存库存<br/>(入库-出库)',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'bqInAmount', title: '本期入库总数量',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'bqOutAmount', title: '本期出库总数量',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'qmJcAmount', title: '期末结存数量',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'material_remarks', title: '物料描述',minWidth:'130', sort: false, align: 'center',exportable:true}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '进销存统计',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 6000,                    //当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 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("");
         demo1.reset();
    }
</script>
</body>
</html>


