<style>
    .ukefu-report{
		position: absolute;
		margin-top: 10px;
    	width: auto;
    }	
	.ukefu-report td{
		max-width:150px;
		min-width:50px;
	}
	.layui-form-label{
		padding-left: 0px;
	}
</style>
<div class="layui-side layui-bg-black">
	<div class="layui-side-scroll">
		<#include "/apps/service/include/left.html">
	</div>
</div>
<div class="layui-body">
	<div class="layui-side-scroll">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="site-h1" style="border-top:1px solid #e6e6e6;">
					客服坐席
					<span>
						<div class="ukefu-bt-text-content">
							<form class="layui-form" name="search"	action="/service/stats/agent.html" method="get" style="float: left;margin-right:5px;">
								<div class="layui-form-item">
									<div class="layui-inline" style="margin-right:0px;">
										<div class="layui-input-inline" style="width: auto">
											<label class="layui-form-label" style="width: auto;">技能组：</label>
											<div class="layui-input-inline" style="width: auto;margin-right:0px;">
										    	<select name="skill" class="ukefu-input" lay-ignore id="skill" onchange="renderAgentsByOrgan(this.value)" >
										    		<option value="">请选择技能组</option>
										    		<#if skillGroups??>
										    		<#list skillGroups as tpskill>
														<option value="${tpskill.id}" <#if skill?? && skill == tpskill.id>selected="selected"</#if>>${tpskill.name!''}</option>
										    		</#list>
										    		</#if>
												</select>
										    </div>
										</div>
									</div>
									<div class="layui-inline" style="margin-right:0px;">
										<div class="layui-input-inline" style="width: auto;margin-right:0px;">
											<label class="layui-form-label" style="width: auto;">坐席：</label>
											<div class="layui-input-inline" style="width: auto;margin-right:0px;">
										    	<select name="agent" class="ukefu-input" lay-ignore id="agent">
										    		<option value="">请选择坐席</option>
										    		<#if agentList??>
										    		<#list agentList as useragent>
														<option value="${useragent.id}" <#if agent?? && agent == useragent.id>selected="selected"</#if>>${useragent.uname!''}</option>
										    		</#list>
										    		</#if>
												</select>
										    </div>
										</div>
									</div>
									<div class="layui-inline" style="margin-left:10px;">
										<div class="layui-input-inline" style="width: auto;margin-right:0px;">
											<label class="layui-form-label" style="width: auto;">日期范围：</label>
											<div class="layui-input-inline" style="width: auto;margin-right:0px;">
										      <input name="begin" id="start_time" class="layui-input ukefu-input" placeholder="开始日期" value="${begin!''}" >
										    </div>
											<label class="layui-form-label" style="width: auto;">~</label>
											<div class="layui-input-inline" style="width: auto;margin-right:0px;">
										      <input name="end" id="end_time" class="layui-input ukefu-input" placeholder="结束日期" value="${end!''}" >
										    </div>
										</div>
									</div>
									<div class="layui-inline" style="margin-right:0px;">
										<div class="layui-input-inline" style="width: auto;margin-right:0px;">
											<div class="layui-input-inline" style="width: auto;margin-right:0px;">
										      <button class="layui-btn layui-btn-small layui-btn-primary" type="submit" style="color:#ffffff;">
												  <i class="layui-icon"></i>
												</button>
										    </div>
										</div>
									</div>
								</div>
							</form>
							<div class="layui-btn-group ukefu-btn-group" style="margin-top:2px;">
								<a href="/service/stats/agent/exp.html?t=${.now?long}<#if skill??>&skill=${skill!''}</#if><#if agent??>&agent=${agent!''}</#if><#if begin??>&begin=${begin!''}</#if><#if end??>&end=${end!''}</#if>">
								<button class="layui-btn layui-btn-small dropdown-menu">
									<i class="kfont">&#xe672;</i> 导出 
								</button>
								</a>
							</div>
						</div>
					</span>
				</h1>
				<#include "/apps/service/stats/report.html">
			</div>
		</div>
	</div>
</div>
<script src="/js/CSKeFu_Rest_Request.v1.js"></script>
<script>
//Demo
layui.use('form', function(){
  var form = layui.form();
  form.render(); //更新全部
});
layui.use('laydate', function() {
	var laydate = layui.laydate;
});

function getNowFormatDate() {
	var date = new Date();
	var seperator = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = year + seperator + month + seperator + strDate;
	return currentdate;
}

var start = {
	istime: true,
	format: 'YYYY-MM-DD',
	max:getNowFormatDate(),//默认最大值为当前日期
	istoday: true,
	choose: function (datas) {
		end.min = datas; //开始日选好后，重置结束日的最小日期
	}
};

var end = {
	istime: true,
	format: 'YYYY-MM-DD',
	max:getNowFormatDate(),//默认最大值为当前日期
	istoday: true,
	choose: function (datas) {
		start.max = datas; //结束日选好后，重置开始日的最大日期
	}
};

document.getElementById('start_time').onclick = function () {
	start.elem = this;
	laydate(start);
};
document.getElementById('end_time').onclick = function () {
	end.elem = this;
	laydate(end);
};

function renderAgentsByOrgan(organid){
		restApiRequest({
			silent: true,
			path: 'user',
			data: {
				ops: 'findByOrgan',
				organ: organid
			}
		}).then(function(result){
			if(result.rc == 0){
				$("#agent").html('<option value="">所有坐席</option>');
				for (var i=0 ; i<result.data.length ; i++) {
					$("#agent").prepend('<option value="' + result.data[i].id + '">' + result.data[i].uname + '</option>')
				};
			}
		}, function(error){
			// 服务器异常
			top.layer.msg('服务器抽风，请稍后再试！', {icon: 2, offset: 'b', time: 3000})
		})
}
</script>