<%@ 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" />
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.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="BDGL_BXSZ_T" html='<a href="${ctx}/insurance/list"><li class="layui-this">保险设置</li></a>'/>
            </ul>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<!-- toolbar -->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <sfTags:pagePermission authFlag="BXSZ_XZ_B" html='<button class="layui-btn layui-btn-sm" lay-event="addBtn" id="addBtn"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
        <sfTags:pagePermission authFlag="BXSZ_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
    </div>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script>
    var entrycount=0;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form', 'upload', 'laytpl'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        laytpl = layui.laytpl;
        table = tableExt.getLayTable();

        tableExt.render({
            elem: '#test'
            , title:'保险设置'
            , height: 'full-95'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/insurance/insuranceListData'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field : 'id', minWidth : 200 , title: '操作', align : 'center',rowspan:'2' , fixed: 'left',
                    templet: function (d) {
                        var add = '';
                        if('${fns:checkPagePermission(request, "BXSZ_BJ_B")}'){
                            add += '<a class="layui-table-opt-link" lay-event="edit">编辑</a>';
                        }
                        if (d.status=='0') {
                            if('${fns:checkPagePermission(request, "BXSZ_JY_B")}'){
                                add += ' <a class="layui-table-opt-link" lay-event="disable"> 禁用</a>';
                            }
                        }else if(d.status='1'){
                            if('${fns:checkPagePermission(request, "BXSZ_QY_B")}'){
                                add += ' <a class="layui-table-opt-link" lay-event="enable"> 启用</a>'
                            }
                            if('${fns:checkPagePermission(request, "BXSZ_SC_B")}'){
                                add += ' <a class="layui-table-opt-link" lay-event="del"> 删除</a>'
                            }
                        }
                        return add;
                    },
                }
                , {field: 'status', title: '状态',minWidth: 200, sort: false, align: 'center', fixed: 'left',exportable:true
                    , templet: function(d){
                        if(d.status=='0'){
                            return '启用';
                        }else{
                            return '禁用';
                        }
                    },expFormat:function (d){
                        //0.财产 1.商业 2.交强 3.其他
                        if(d.status=='0'){
                            return '启用';
                        }else{
                            return '禁用';
                        }
                    }
                    }
                , {field : 'name', minWidth : 200 , title: '保单名称', align : 'center',rowspan:'2' , fixed: 'left',exportable:true}
                , {field : 'type', minWidth : 200 , title: '保险类型', align : 'center',rowspan:'2' , fixed: 'left',exportable:true
                    , templet: function (d) {
                        //0.财产 1.商业 2.交强 3.其他
                        if(d.type=='0'){
                            return "财产险";
                        } else if(d.type=='1'){
                            return "商业险";
                        } else if(d.type=='2'){
                            return "交强险";
                        } else if(d.type=='3'){
                            return "其他";
                        }
                    },expFormat:function (d){
                        //0.财产 1.商业 2.交强 3.其他
                        if(d.type=='0'){
                            return "财产险";
                        } else if(d.type=='1'){
                            return "商业险";
                        } else if(d.type=='2'){
                            return "交强险";
                        } else if(d.type=='3'){
                            return "其他";
                        }
                    }
                }
                , {field : 'company_name', minWidth : 200 , title: '投保公司', align : 'center',rowspan:'2' , fixed: 'left',exportable:true}
                , {field : 'policyholder', minWidth : 200 , title: '投保人', align : 'center',rowspan:'2' , fixed: 'left',exportable:true}
                , {field : 'insurant', minWidth : 200 , title: '被投人', align : 'center',rowspan:'2' , fixed: 'left',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"));
                }
            },done: function(res, curr, count){
                //得到数据总量
                entrycount = count;
            }
        });

        table.on('toolbar(test)',function(obj) {
            if (obj.event === 'addBtn') {
                layer.open({
                    type: 2,
                    content: "${ctx}/insurance/toAddPage"
                    , title: "新增保单"
                    , area: ["60%", "55%"]
                });
            }
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'disable') {
                layer.confirm('您确定要禁用该条记录吗？', {
                    btn: ['确定', '取消'],
                    end: function () {
                        layer.closeAll();
                    },
                    yes: function () {
                        $.ajax({
                            url: '${ctx}/insurance/disable/' + data.id,
                            method: 'get',
                            dataType: 'JSON',
                            contentType:"application/json",
                            success: function (res) {
                                if (res.code == "200") {
                                    table.reload('test');
                                    top.layer.msg("操作成功", {time: 2000});
                                    layer.closeAll();
                                } else {
                                    layer.msg(res.errMsg, {time: 2000});
                                }
                            },
                            error: function (data) {
                            }
                        });
                    }
                });
            }else if (obj.event === 'enable') {
                layer.confirm('您确定要启用该条记录吗？', {
                    btn: ['确定', '取消'],
                    end: function () {
                        layer.closeAll();
                    },
                    yes: function () {
                        $.ajax({
                            url: '${ctx}/insurance/enable/' + data.id,
                            method: 'get',
                            dataType: 'JSON',
                            contentType:"application/json",
                            success: function (res) {
                                if (res.code == "200") {
                                    table.reload('test');
                                    top.layer.msg("操作成功", {time: 2000});
                                    layer.closeAll();
                                } else {
                                    layer.msg(res.errMsg, {time: 2000});
                                }
                            },
                            error: function (data) {
                            }
                        });
                    }
                });
            }else if (obj.event === 'del') {
                layer.confirm('您确定要删除该条记录吗？', {
                    btn: ['确定', '取消'],
                    end: function () {
                        layer.closeAll();
                    },
                    yes: function () {
                        $.ajax({
                            url: '${ctx}/insurance/del/' + data.id,
                            method: 'get',
                            dataType: 'JSON',
                            contentType: "application/json",
                            success: function (res) {
                                if (res.code == "200") {
                                    table.reload('test');
                                    top.layer.msg("操作成功", {time: 2000});
                                    layer.closeAll();
                                } else {
                                    layer.msg(res.errMsg, {time: 2000});
                                }
                            },
                            error: function (data) {
                            }
                        });
                    }
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    content: "${ctx}/insurance/toEditPage/" + data.id
                    , title: "编辑保单信息"
                    , area: ["60%", "55%"]
                });
            }
        });


    })

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

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

