<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/include.inc.jsp" %>
<%@include file="/WEB-INF/jsp/commons/jstl_message_tld.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath%>">
    <meta charset="UTF-8">
    <title><fmt:message key="app.name" bundle="${commonBundle}"/></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
	<link href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui-for-work.min.css" rel="stylesheet" type="text/css"/>
	<link href="resource/js/layui/css/layui2.css" rel="stylesheet" type="text/css" media="all">
	<link href="resource/css/weixin-work/public.css" rel="stylesheet" type="text/css"/>
	<style type="text/css">
	.weui-form-preview__hd .weui-form-preview__value {font-size: 120%;}
	.weui-form-preview__ft {line-height: 40px;} /* 任务进度/项目文档/操作按钮列高度,默认50px太高了 */
	.weui-msg {padding-top: 5px;}
	</style>
</head>
<body ontouchstart>
	<div class="page__bd" style="margin-bottom: 60px;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
			<legend>我的任务列表</legend>
		</fieldset>
		
		<div id="task-list-box"></div><!-- / #task-list-box -->

		<div id="caozuo-btns">
		    <div class="weui-mask" id="iosMask" style="display: none"></div>
		    <div class="weui-actionsheet" id="iosActionsheet">
		        <div class="weui-actionsheet__menu">
		            <div class="weui-actionsheet__cell">
						<a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" id="btn_update">修 改</a>
					</div>
		            <div class="weui-actionsheet__cell">
		            	<a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" id="btn_delete" style="color: red;">删 除</a>
		            </div>
		        </div>
		        <div class="weui-actionsheet__action">
		            <div class="weui-actionsheet__cell" id="iosActionsheetCancel">取消</div>
		        </div>
		    </div>
		</div>
				
	</div><!-- .page__bd -->

	
	<div id="task-logs-box" style="display:none;">
		<div class="weui-msg">
	        <div class="weui-msg__text-area" style="text-align: left;">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  				<legend>任务进度日志</legend>
				</fieldset>
				<ul class="layui-timeline" id="layui-timeline-box"></ul>
	        </div><!-- .weui-msg__text-area -->
	        <div class="weui-msg__opr-area">
	            <p class="weui-btn-area">
	                <a href="javascript:;" class="weui-btn weui-btn_default" id="task-logs-box-close">返回</a>
	            </p>
	        </div>
	    </div>
	</div> <!-- / #task-logs-box -->


<script type="text/javascript" src="https://lib.baomitu.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="resource/js/layui//layui.js" charset="utf-8"></script>
<script type="text/javascript" src="resource/js/weixin-work/public.js"></script>
<script type="text/javascript">
var pid = null;

var list_item_html = 
	'<div class="weui-form-preview">'+
	'	<div class="weui-form-preview__hd">'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">任务名称</label>'+
	'			<em class="weui-form-preview__value taskname">{taskname}</em>'+
	'		</div>'+
	'	</div>'+
	'	<div class="weui-form-preview__bd">'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">项目名称</label>'+
	'			<span class="weui-form-preview__value">{projectName}</span>'+
	'		</div>'+	
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">时间范围</label>'+
	'			<span class="weui-form-preview__value">{timerange}</span>'+
	'		</div>'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">创建人</label>'+
	'			<span class="weui-form-preview__value">{createUserName}</span>'+
	'		</div>'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">创建时间</label>'+
	'			<span class="weui-form-preview__value">{createTime}</span>'+
	'		</div>'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">进度</label>'+
	'			<span class="weui-form-preview__value">{speed}</span>'+
	'		</div>'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">执行人</label>'+
	'			<span class="weui-form-preview__value">{userNames}</span>'+
	'		</div>'+
	'		<div class="weui-form-preview__item">'+
	'			<label class="weui-form-preview__label">任务内容：</label><br>'+
	'			<span class="weui-form-preview__value" style="text-align:left; margin: 0 10px;">{content}</span>'+
	'		</div>'+
	'	</div>'+
	'	<div class="weui-form-preview__ft btn-parent" dataid="{dataid}" projectId="{projectId}" status="{status}">'+
	'		<a class="weui-form-preview__btn weui-form-preview__btn_default btn-item-prodetail" href="javascript:;">项目详情</a>'+
	'		<a class="weui-form-preview__btn weui-form-preview__btn_default btn-item-progress" href="javascript:;">进度日志</a>'+
	'		<a class="weui-form-preview__btn weui-form-preview__btn_primary btn-item-add" href="javascript:;">添加日志</a>'+
	'	</div>'+
	'</div><br>';

var timeline_item_html = 
	'<li class="layui-timeline-item" dataid="{dataid}">'+
	'<i class="layui-icon layui-timeline-axis">&#xe63f;</i>'+
	'<div class="layui-timeline-content layui-text">'+
	'	<h3 class="layui-timeline-title">{createTime}</h3>'+
	'	<div class="weui-form-preview">'+
	'		<div class="weui-form-preview__bd">'+
	'			<div class="weui-form-preview__item">'+
	'				<label class="weui-form-preview__label">进度日志</label>'+
	'				<span class="weui-form-preview__value">{journal}</span>'+
	'			</div>'+	
	'			<div class="weui-form-preview__item">'+
	'				<label class="weui-form-preview__label">操作人</label>'+
	'				<span class="weui-form-preview__value">{createUserName}</span>'+
	'			</div>'+
	'			<div class="weui-form-preview__item">'+
	'				<label class="weui-form-preview__label">开始时间</label>'+
	'				<span class="weui-form-preview__value">{startTime}</span>'+
	'			</div>'+
	'			<div class="weui-form-preview__item">'+
	'				<label class="weui-form-preview__label">结束时间</label>'+
	'				<span class="weui-form-preview__value">{endTime}</span>'+
	'			</div>'+
	'			<div class="weui-form-preview__item">'+
	'				<label class="weui-form-preview__label">进度说明</label>'+
	'				<span class="weui-form-preview__value">{content}</span>'+
	'			</div>'+
	'		</div>'+
	'	</div>'+
	'</div>'+
	'</li>';
	
    
// 查询任务列表
function getTaskList(){
	var params = {};
	params['page'] = 1;
	params['rows'] = 100;
	showLoading();
	$('#task-list-box').html('');
	$.post('projectTask/my/query.do', params, function(result){
		hideLoading();
		var data = JSON.parse(JSON.stringify(result).trim());
		if(data.total > 0){
			var items = data.rows;
			var html = '';
			for(var i in items){
				html += list_item_html.replaceAll("{dataid}", items[i].id).replaceAll("{projectId}", items[i].projectId)
				.replaceAll("{status}", items[i].status)
				.replaceAll("{taskname}", items[i].name).replaceAll("{projectName}", trimToEmpty(items[i].projectName))
				.replaceAll("{createUserName}", trimToEmpty(items[i].createUserName)).replaceAll("{createTime}", formatDate(items[i].createTime))
				.replaceAll("{speed}", isBlank(items[i].speed)?"0%":(items[i].speed+'%'))
				.replaceAll("{timerange}", formatDate(items[i].startTime)+' -- '+formatDate(items[i].endTime))
				.replaceAll("{userNames}", trimToEmpty(items[i].userNames)).replaceAll("{content}", trimToEmpty(items[i].content));
			}
			$('#task-list-box').html(html);
		}else{
			$('#task-list-box').html('<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>');
		}
	}, 'json');
}


//查询任务日志列表
function getTaskJournalList(taskId){
	var params = {};
	params['page'] = 1;
	params['rows'] = 100;
	params['taskId'] = taskId;
	showLoading();
	$('#layui-timeline-box').html('');
	$.post('projectTask/journal/query.do', params, function(result){
		hideLoading();
		var data = JSON.parse(JSON.stringify(result).trim());
		var b=true;
		if(b&&data.total > 0){
			var items = data.rows;
			var html = '';
			for(var i in items){
				html += timeline_item_html.replaceAll("{dataid}", items[i].id).replaceAll("{createUserName}", items[i].createUserName)
				.replaceAll("{content}", trimToEmpty(items[i].content)).replaceAll("{createTime}", formatDate(items[i].createTime))
				.replaceAll("{startTime}", formatDate(items[i].startTime))
				.replaceAll("{endTime}", formatDate(items[i].endTime))
				.replaceAll("{journal}", trimToEmpty(items[i].journal));
			}
			html+='<li class="layui-timeline-item"><i class="layui-icon layui-timeline-axis">&#xe63f;</i><div class="layui-timeline-content layui-text"></div></li>';
			$('#layui-timeline-box').html(html);
		}else{
			$('#layui-timeline-box').html('<li class="layui-timeline-item"><div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div></li>');
		}
	}, 'json');
}


$(function(){
	getTaskList(); // 加载数据
	
	// 查看项目详情
	$('.page__bd').on('click','.btn-item-prodetail',function(){
		var projectId = $(this).parent('.btn-parent').attr('projectId');
		if(debugMode){
			window.location.href = getSysBaseUrl()+'/pages/weixin-work/project/list.jsp?queryId='+projectId;
		}else{
			window.location.href = getSysBaseUrl()+'/wxwork/pages/project/list.do?queryId='+projectId;
		}
    });
	
	// 添加任务日志
	$('.page__bd').on('click','.btn-item-add',function(){
		var status = $(this).parent('.btn-parent').attr('status');
		if(status != 1){
			toastMsg("项目处于未开始，暂停或结束状态时无法添加进度日志!");
			return false;
		}
    	var dataid = $(this).parent('.btn-parent').attr('dataid');
		var taskname = $(this).parents('.weui-form-preview').find('.taskname').text();
    	taskname = encodeURI(encodeURI(taskname));
    	if(debugMode){
			window.location.href = getSysBaseUrl()+'/pages/weixin-work/project/task/add_journal.jsp?pid='+dataid+'&taskname='+taskname;
		}else{
			window.location.href = getSysBaseUrl()+'/wxwork/pages/project/task/add_journal.do?pid='+dataid+'&taskname='+taskname;
		}
    });
	
	
    // 点击进度详情按钮
    $('.page__bd').on('click','.btn-item-progress',function(){
    	var taskId = $(this).parent('.btn-parent').attr('dataid');
    	$('.page__bd').hide();
    	$('#task-logs-box').show();
    	getTaskJournalList(taskId);
    });
    
    // 关闭进度详情显示
    $('#task-logs-box').on('click','#task-logs-box-close',function(){
    	$('.page__bd').show();
    	$('#task-logs-box').hide();
    });
    
    
});

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