<!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('值班配置列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="dutyConfig-form">
					<div class="select-list">
						<ul>
							<li>
								配置名称：<input type="text" name="configName"/>
							</li>
							<li>
								状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li class="select-time">
								<label>开始时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginStartTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endStartTime]"/>
							</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.addTab()" shiro:hasPermission="system:dutyConfig:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	             <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:dutyConfig:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
	            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:dutyConfig:remove">
	                <i class="fa fa-remove"></i> 删除
	            </a>
	            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:dutyConfig:export">
		            <i class="fa fa-download"></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:dutyConfig:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:dutyConfig:remove')}]];
		var prefix = ctx + "system/dutyConfig";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "值班配置",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'id',
		            title: '配置ID',
		            visible: false
		        },
		        {
		            field: 'configName',
		            title: '配置名称',
		            sortable: true
		        },
		        {
		            field: 'startTime',
		            title: '开始时间',
		            sortable: true,
		            formatter: function(value, row, index) {
		                return $.table.tooltip(value);
		            }
		        },
		        {
		            field: 'endTime',
		            title: '结束时间',
		            sortable: true,
		            formatter: function(value, row, index) {
		                return $.table.tooltip(value);
		            }
		        },
		        {
		            field: 'dutyUserNames',
		            title: '值班人员',
		            formatter: function(value, row, index) {
		                if (value && value.length > 20) {
		                    return '<span title="' + value + '">' + value.substring(0, 20) + '...</span>';
		                }
		                return value || '';
		            }
		        },
		        {
		            field: 'isActive',
		            title: '是否生效',
		            align: 'center',
		            formatter: function(value, row, index) {
		                if (value) {
		                    return '<span class="label label-success">生效中</span>';
		                } else {
		                    return '<span class="label label-default">未生效</span>';
		                }
		            }
		        },
		        {
		        	visible: editFlag == 'hidden' ? false : true,
		        	title: '状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-eye"></i>详情</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});
		
		/* 值班配置状态显示 */
		function statusTools(row) {
		    if (row.status == '0') {
		        return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
		    } else {
		        return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
		    }
		}

		/* 值班配置管理-停用 */
		function disable(id) {
		    $.modal.confirm("确认要停用该值班配置吗？", function() {
		        $.operate.post(prefix + "/changeStatus", { "id": id, "status": "0" });
		    })
		}

		/* 值班配置管理-启用 */
		function enable(id) {
		    $.modal.confirm("确认要启用该值班配置吗？", function() {
		        $.operate.post(prefix + "/changeStatus", { "id": id, "status": "1" });
		    })
		}
		
		/* 详情 */
		function detail(id) {
		    var url = prefix + '/detail/' + id;
		    $.modal.openTab("值班配置详情", url);
		}
	</script>
</body>
</html>