<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('弹框配置列表')" />
    <style>
        .tableImage_s{
            border-radius:2px;
            width: 24px;
            height: 22px;
        }
        .tableImage_m{
            border-radius:2px;
            width: 36px;
            height: 30px;
        }
        .tableImage_l{
            border-radius:2px;
            width: 73px;
            height: 32px;
        }
        .preview-item{
            width: 100%;
            height: 100%;
            flex-direction: row;
            display: flex;
            justify-content: center;
            align-items: center;
            position: fixed;
            z-index: 100;
            background-color: rgba(0,0,0,0.7);
        }
        .preview-img{
            width: 300px;
            max-height: 400px;
            overflow-y: scroll;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
         <div id="previewImg" class="preview-item" onclick="closePreview()">
             <div class="preview-img">
                 <img id="previewImage" src="" style="width: 100%;">
             </div>
         </div>
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>弹框内容：</p>
                                <input type="text" name="alertContent"/>
                            </li>
                            <li class="select-time">
                                <p>弹框开始时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="alertStartTime"/>

                            </li>
                            <li class="select-time">
                                <p>弹框结束时间：</p>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="alertEndTime"/>
                            </li>
                            <li>
                                <p>用户类型</p>
                                <select name="userType" th:with="type=${@dict.getType('sys_lantern_permission')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>是否启动</p>
                                <select name="alertStatus">
                                    <option value="">所有</option>
                                    <option value="0">未启动</option>
                                    <option value="1">启动</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:configuration:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:configuration:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:configuration:remove')}]];
        var prefix = ctx + "system/configuration";

        $(function() {
            $("#previewImg").hide();
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "弹框配置",
                columns: [
                {
                    field : 'alertId', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'alertTitle',
                    title : '弹框标题'
                },
                {
                    field : 'alertContent', 
                    title : '弹框内容',
                    width : '200px',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                    {
                        field : 'photoUrl',
                        title : '弹框图片',
                        width : '100px',
                        formatter: function(value, row, index) {
                            if (value != null){
                                // return $.table.imageView(value,600,300,"tableImage_s img-view");
                                var valueStr = value + '';
                                console.log('url1',value);
                                console.log('url2',valueStr);
                                return '<img width="24" height="22" src="' + value + '" onclick="imgPreview(\'' + valueStr + '\')"/>'
                            }
                        }
                    },
                {
                    field : 'alertStartTime', 
                    title : '开始时间'
                },
                {
                    field : 'alertEndTime', 
                    title : '结束时间'
                },
                {
                    field : 'alertNum', 
                    title : '次数'
                },
                    {
                        field : 'orgName',
                        title : '通知部门'
                    },
                {
                    field : 'userType',
                    title : '用户类型',
                    formatter: function(value, row, index) {
                        if (value.indexOf('0') != -1 && value.indexOf('1') != -1 && value.indexOf('2') != -1 && value.indexOf('3') != -1){
                            return '全部人员';
                        } else {
                            var userStr = '';
                            if (value.indexOf('0') != -1){
                                userStr += '立邦员工 ';
                            }
                            if (value.indexOf('1') != -1){
                                userStr += '经销商 ';
                            }
                            if (value.indexOf('2') != -1){
                                userStr += '服务商 ';
                            }
                            if (value.indexOf('3') != -1){
                                userStr += '金牌店 ';
                            }
                            return userStr;
                        }
                    }
                },
                    {
                        visible: editFlag == 'hidden' ? false : true,
                        title: '是否启动',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return statusTools(row);
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.alertStatus == 1) {
                            actions.push('<a class="btn btn-default btn-xs ' + editFlag + '" href="javascript:void(0)"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-default btn-xs ' + removeFlag + '" href="javascript:void(0)"><i class="fa fa-remove"></i>删除</a>');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.alertId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.alertId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 启动状态显示 */
        function statusTools(row) {
            if (row.alertStatus == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.alertId + '&' + row.userType + '&' + row.salesLevel + '&' + row.orgCode + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.alertId + '&' + row.userType + '&' + row.salesLevel + '&' + row.orgCode + '\')"></i> ';
            }
        }

        /* 停用 */
        function disable(row) {
            var arrayTingyong = row.split('&');
            $.modal.confirm("确认关闭该通知吗？", function() {
                $.operate.post(prefix + "/release", { "alertId": arrayTingyong[0], "alertStatus": 0, "userType": arrayTingyong[1], "salesLevel": arrayTingyong[2], "orgCode": arrayTingyong[3] });
            })
        }

        /* 启用 */
        function enable(row) {
            var arrayQiyong = row.split('&');
            $.modal.confirm("确认启用该通知吗？", function() {
                $.operate.post(prefix + "/release", { "alertId": arrayQiyong[0], "alertStatus": 1, "userType": arrayQiyong[1], "salesLevel": arrayQiyong[2], "orgCode": arrayQiyong[3] });
            })
        }

        $("#previewImage").on('click',function (event) {
            event.stopPropagation();
        })

        function closePreview() {
            $("#previewImg").hide();
        }

        function imgPreview(url) {
            $("#previewImage").attr('src',url);
            $("#previewImg").show();
        }
    </script>
</body>
</html>