<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XTSZ_WLSZ_LXSZ_T" html='<li class=""><a href="${ctx}/crmSupplyMaterialSetting/materialTypePage">物料类型设置</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_WLSZ_WLZSZ_T" html='<li class="layui-this"><a href="${ctx}/crmSupplyMaterialSetting/materialGroupPage">物料组设置</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_WLSZ_PPSZ_T" html='<li class=""><a href="${ctx}/crmSupplyMaterialSetting/materialUnitPage">物料单位设置</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 " id="searchBtn" data-type="reload">
                    <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-lg2 layui-col-sm3">
                        <label class="layui-form-label">物料组名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" class="layui-input" id="name" >
                        </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-xs3">
                                <input type="text" name="createTimeSta" class="layui-input" id="createTimeSta" placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs3">
                                <input type="text" name="createTimeEnd" class="layui-input" id="createTimeEnd" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="XTSZ_WLZSZ_XZ_T" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
    <sfTags:pagePermission authFlag="XTSZ_WLZSZ_SC_T" html='<button class="layui-btn layui-btn-sm" id="deleteBtn" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除 </button>'/>
</div>
</div>
<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="XTSZ_WLZSZ_BJ_T" html='<a class="layui-table-opt-link" lay-event="edit">编辑</a>'/>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        laydate = layui.laydate;
        table = layui.table;

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

        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/crmSupplyMaterialSetting/materialGroupList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', title: '序号', align: 'center', type: 'numbers',rowspan:'2'}
                ,{field : 'id', checkbox : true,align : 'center',rowspan:'2' }
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center'}
                , {field: 'name', title: '类型名称', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'create_time', minWidth: 200, title: '创建时间', align: 'center',exportable:true ,rowspan:'2'}
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '方案信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '方案信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'add') {
                layer.open({
                    type: 2,
                    title: '新增',
                    content: '${ctx}/crmSupplyMaterialSetting/addMaterialGroup',
                    area: ['22%','25%']
                });
            }  else if (obj.event === 'delete') {
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                var ids="";
                for(var i=0;i<data.length;i++){
                    ids+=data[i].id+",";
                }
                var indexla = layer.confirm('您确认删除该物料组吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/crmSupplyMaterialSetting/deleteMaterialGroup",
                        data: {
                            ids: ids
                        },
                        success: function (result) {
                            if(result.code=='200'){
                                layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                    reload();
                                });
                            }else {
                                layer.msg('删除失败!', {icon: 2});
                            }
                        },
                        error:{
                        }
                    })
                }, function () {
                    layer.close(indexla);
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'edit'){
                layer.open({
                    title:'编辑',
                    type: 2,
                    content: '${ctx}/crmSupplyMaterialSetting/addMaterialGroup?id='+id,
                    area:['22%','25%'],
                })
            }
        });

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            where: {
                name:$("#name").val().trim(),
                createTimeSta:$("#createTimeSta").val().trim(),
                createTimeEnd:$("#createTimeEnd").val().trim(),
            }
        });
    }

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

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




