<#include "/admin/layout/layout.ftl">
<#assign css>
<style>
</style>
</#assign>
<#assign js>
<script>
$(function(){ 
	layui.use(['laypage', 'layer', 'table', 'laydate'], function(){
		var table = layui.table;
		var laydate = layui.laydate;
		var index = layer.load(1, {shade: [0.5,'#fff']}); 
		var tableVar = table.render({
			id: 'businessId',
			height: 550,
			elem: '#test',
			url: '${ctx!}/dingding/examination/list?datetime='+$('#datetime').val()+'&processCodeId='+$('#searchType').val()+"&businessNum="+$('#businessNum').val()+"&applyDate="+$('#applyDate').val()+"&companyId="+$('#searchCompany').val(),
			cols: [[{type:'checkbox'},
			{field:'businessId', title: '流程实例业务编号', sort: true},
			{field:'title', title: '标题', sort: true},
			{field:'createTime', title: '开始时间', sort: true},
			{field:'finishTime', title: '结束时间', sort: true},
			{field:'status', title: '审批状态', sort: true, templet: function(d){ if (d.status == 'NEW') return '刚新建'; else if (d.status == 'RUNNING') return '运行中'; else if (d.status == 'TERMINATED') return '被终止'; else if (d.status == 'COMPLETED') return '完成';else if (d.status == 'CANCELED') return '取消';else return ""}},
			{field:'result', title: '审批结果', sort: true, templet: function(d){ if (d.result == 'agree') return '同意'; else if (d.result == 'refuse') return '退回';else return ""}},
			{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}
    		]],
    		done: function(res, curr, count){
    			layer.close(index); 
    		}
  		});
  		
		table.on('tool(test)', function(obj){
			var index3 = layer.load(1, {shade: [0.5,'#fff']}); 
		    var data = obj.data;
		    if(obj.event === 'detail'){
			    $.ajax({
	                type: "GET",
	                dataType: "json",
	                url: "${ctx!}/dingding/examination/detail",
	                data : {processInstanceId : data.processInstanceId, processCodeId : $('#searchType').val(), title: data.title, businessId :data.businessId},
	                success: function (res) {
	                	layer.close(index3);
	                    layer.open({
  							type: 2,
  							title:false,
  							area: ['800px', '800px'],
							skin: 'layui-layer-demo', 
							closeBtn: 0, 
							anim: 2,
							shadeClose: true, 
  							content: "/" + res.message
						});
	                },
            		error : function(r,s,m) {
            			layer.close(index3); 
            			layer.msg(r.message, {time: 2000}, function () {
	                    });
            		}
	            });
		    } else if(obj.event === 'down'){
		    	window.location.href = "${ctx!}/dingding/examination/download?processInstanceId=" + data.processInstanceId + "&processCodeId=" + $('#searchType').val() +"&title="+data.title+"&businessId="+data.businessId;
		    	layer.close(index3); 
		    } 
		});
  		
  		var today = new Date();
  		today.setTime(today.getTime());
		var dayRange = today.getFullYear()+"-" + (today.getMonth()+1) + "-" + today.getDate() + " 00:00:00" +  " - " + today.getFullYear()+"-" + (today.getMonth()+1) + "-" + today.getDate() + " 23:59:59";
		
		today.setDate(1);
		var monthFirstDay = today.getFullYear()+"-" + (today.getMonth()+1) + "-" + today.getDate() + " 00:00:00" ;
		
		<!-- 审批结束时间段-->
		laydate.render({elem: '#datetime',type: 'datetime',range: true, value: dayRange, done: function(value, date, endDate){
    			$('#datetime').val(value);
  			}});
  			
  		<!-- 申报开始时间 -->	
		laydate.render({elem: '#applyDate',type: 'datetime', value: monthFirstDay, done: function(value, date, endDate){
    			$('#applyDate').val(value);
  			}});
  		
		$("#search").click(function(){
			if ($('#datetime').val() == "" || $('#datetime').val() == null){
				layer.msg("请选择审批结束时间", {time: 2000}, function () {});
				return;
			}
			var index2 = layer.load(1, {shade: [0.5,'#fff']}); 
			tableVar.reload({
				url: '${ctx!}/dingding/examination/list?datetime='+$('#datetime').val()+'&processCodeId='+$('#searchType').val()+"&businessNum="+$('#businessNum').val()+"&applyDate="+$('#applyDate').val()+"&companyId="+$('#searchCompany').val(),
				done: function(res, curr, count){
    				layer.close(index2); 
    			}
			});
		});
		
		$("#download").click(function(){
			var checkStatus = table.checkStatus('businessId');
			if(checkStatus.data.length == 0){
				layer.msg("请选中数据", {time: 2000}, function () {});
                return;
			}
			
			var index4 = layer.msg('这需要一点时间，请稍后，您可以喝杯咖啡', {icon: 16, shade: 0.5, time:0});
			var processInstanceIds = new Array();
			for (var i = 0; i < checkStatus.data.length; i++){
				processInstanceIds.push(checkStatus.data[i].processInstanceId);
			}
			$.ajax({
			    type: "POST",
			    dataType: "json",
			    url: "${ctx!}/dingding/examination/downloadAll",
			    data : {processInstanceIds : processInstanceIds.join(","), processCodeId : $('#searchType').val() },
			    success: function (res) {
					layer.close(index4); 
	                var path = res.message;
	                window.location.href = "${ctx!}/dingding/examination/downloadFile?filePath=" + res.data.filePath + "&fileName=" + res.data.fileName;
			    },
				error : function(r,s,m) {
					layer.close(index4); 
					layer.msg(r.message, {time: 2000}, function () {});
				}
			});
		});
	});
	
	
	
});
</script>
<script type="text/html" id="barDemo">
 <@shiro.hasPermission name="dingding:examination:detail">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
 </@shiro.hasPermission>
 <@shiro.hasPermission name="dingding:examination:download">
  <a class="layui-btn layui-btn-xs" lay-event="down">下载</a>
  </@shiro.hasPermission>
</script>

</#assign>
<@layout title="审批管理" active="examination">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        审批列表
        <small>一切从这里开始</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-cog"></i> 系统</a></li>
        <li><a href="#"><i class="fa fa-list-ul"></i> 审批管理</a></li>
        <li class="active"><i class="fa fa-table"></i> 审批列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <!-- Default box -->
    <div class="box box-primary">
		<div class="box-header layui-form  form-horizontal">
			<div class="form-group">
				<div class="layui-col-md4">
	       			<label class="col-sm-4 control-label">申报开始时间：</label>
	       			<div class="col-sm-8">
	       				<input id="applyDate" name="applyDate" class="form-control" type="text" value="${applyDate}" placeholder="yyyy-MM-dd HH:mm:ss"/>
	       			</div>
        		</div>
			    <div class="layui-col-md4">
	       			<label class="col-sm-4 control-label">审批结束时间：</label>
	       			<div class="col-sm-8">
	       				<input id="datetime" name="datetime" class="form-control" type="text" value="${datetime}" placeholder="yyyy-MM-dd HH:mm:ss"/>
	       			</div>
        		</div>
			</div>
			<div class="form-group">
				<div class="layui-col-md4">
	          		<label class="col-sm-4 control-label">选择审批类型：</label>
	          		<div class="col-sm-8">
		           		<select id="searchType" name="searchType" style="width:50%;">
		           			<#list process as pro>
								<option value="${pro.id}" >${pro.processName}</option>
							</#list>
				        </select>
		  			</div>
	  			</div>
			    <div class="layui-col-md4">
	       			<label class="col-sm-4 control-label">流程实例业务编号：</label>
	       			<div class="col-sm-8">
	       				<input id="businessNum" name="businessNum" class="form-control" type="text" value="${businessNum}" placeholder="支持模糊查询" />
	       			</div>
        		</div>
			</div>
			<div class="form-group">
				<div class="layui-col-md4">
	          		<label class="col-sm-4 control-label">选择单位：</label>
	          		<div class="col-sm-8">
		           		<select id="searchCompany" name="searchCompany" style="width:50%;">
		           			<option value="" >请选择</option>
		           			<#list companys as company>
								<option value="${company.id}" >${company.dataValue}</option>
							</#list>
				        </select>
		  			</div>
	  			</div>
			</div>
			 <@shiro.hasPermission name="dingding:examination:detail">
			<a id="search" class="btn btn-sm btn-success" href="#">查找</a>
			 </@shiro.hasPermission>
			 <@shiro.hasPermission name="dingding:examination:download">
			<a id="download" class="btn btn-sm btn-success" href="#">下载审批单</a>
			 </@shiro.hasPermission>
		</div>
        <div class="box-body">
        	<table class="layui-hide" id="test" lay-filter="test"></table>
        </div>
        <!-- /.box-body -->
    </div>
    <!-- /.box -->

</section>
<!-- /.content -->
</@layout>




