<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>产品线设置</title>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
    </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="XTSZ_CPXSZ_CPXSZ_T" html='<a href="${ctx}/productLine/set/index"><li class="layui-this">产品线设置</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset" id="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" 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" id="form-name" autocomplete="off" 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-xs3">
                            <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-xs3">
                            <input type="text" name="applyTimeEnd" class="layui-input" id="endTime" 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-table-reload" lay-filter="table-toolbar"></table>
            <script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag="CPXSZ_XZ_B" html='<button class="layui-btn layui-btn-sm" lay-event="addBtn"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
            </script>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="CPXSZ_BJ_B" html='<a href="#" class="layui-table-link" lay-event="edit" >编辑</a>'/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <sfTags:pagePermission authFlag="CPXSZ_SC_B" html='<a href="#" class="layui-table-link" lay-event="del">删除</a>'/>
</script>

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

        tableExt.render({
            elem: '#test-table-reload'
            ,toolbar : '#toolbarDemo'
            ,defaultToolbar : false
            ,url: '${ctx}/productLine/set/getList'
            ,cols: [[
                {type: 'numbers',title:'序号'}
                ,{field:'name', title: '产品线名称',align: 'center'}
                ,{field:'attribute', title: '业务属性',align: 'center', templet: function(d){
                    if (d.attribute == '1') {
                        return '纯租25年业务';
                    } else if (d.attribute == '2') {
                        return '经营性租赁';
                    } else if (d.attribute == '3') {
                        return '融资租赁';
                    } else if (d.attribute == '4') {
                        return '光伏贷';
                    } else if (d.attribute == '5') {
                        return '全款';
                    } else if (d.attribute == '6') {
                        return '其他';
                    }}
                }
                ,{field:'create_time', title: '创建时间',align: 'center'}
                ,{field:'id', title: '操作',align: 'center',toolbar: '#table-toolbar'}
            ]]
            ,done: function(res, curr, count){
                //   console.log("customer done", res);
            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '员工列表',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '员工导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    var ret = {};
                    ret.name= $("#form-name").val();
                    return ret;
                }
            }
        });

        var table = tableExt.getLayTable();

        //监听行工具事件
        table.on('tool(table-toolbar)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'del'){
                layer.confirm('真的删除所选项吗？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                $.post('${ctx}/productLine/set/delete', {id: id}, function(result){
                                    if("200" == result){
                                        layer.msg("删除成功");
                                        obj.del();
                                        layer.close(index);
                                    } else {
                                        layer.msg("删除失败");
                                    }
                                });
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        $.post('${ctx}/productLine/set/delete', {id: id}, function(result){
                            if("200" == result){
                                layer.msg("删除成功");
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.msg("删除失败");
                            }
                        });
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    , title: '编辑'
                    , area: ['740px', '400px']
                    , content: '${ctx}/productLine/set/editPage?id=' + id
                })
            }
        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        name: $('#form-name').val(),
                        startTime: $("#startTime").val(),
                        endTime: $("#endTime").val()
                    }
                });
            }
        };

        //开始日期
        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
                });
            }
        });

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 监听头部事件
        table.on('toolbar(table-toolbar)', function(obj) {
            switch (obj.event) {
                case 'addBtn':
                    layer.open({
                        type: 2
                        , title: '新增'
                        , area: ['740px', '400px']
                        , content: '${ctx}/productLine/set/addPage'
                    })
                    break;
            }
        })

        $("#reset").on('click', function () {
            $("#searchForm").find("select").val("");
            $("#searchForm").find("input").val("");
        })
    });
</script>
</body>
</html>
