<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
	<link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui-for-work.min.css" />
	<link rel="stylesheet" type="text/css" th:href="@{/libs/layui/css/layui2.css}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/weixin-work/public.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 dropload-box" style="margin-bottom: 60px;">
		<div class="weui-cells__title" id="pagetitle" style="text-align:center;font-weight: bold;"></div>
		
		<div id="task-list-box">
		</div><!-- / #task-list-box -->
				
		<!-- 增加任务按钮,固定在页面底部 -->
		<div class="weui-footer weui-footer_fixed-bottom" id="btn-groups" style="text-align: right; margin: 15px; z-index: 999; display:none;">
            <p class="weui-footer__links">
            	<!-- 返回按钮 -->
            	<a href="javascript:history.back();" class="weui-btn weui-btn_mini weui-btn_default" style="margin-right: 8px;"><i class="layui-icon" style="font-size: 20px;"></i></a>
            	<!-- 新增按钮 -->
       			<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default modifybox" id="btnAddTask"><i class="layui-icon" style="font-size: 20px;">&#xe654;</i></a>
            </p>
        </div><!-- /.weui-footer weui-footer_fixed-bottom -->
	</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.4.0.js"></script>
<script type="text/javascript" th:src="@{/libs/layui//layui.js}"></script>
<script type="text/javascript" th:src="@{/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}</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">{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">{zxrNames}</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}">'+
	'		<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-update" href="javascript:;" style="display:{showdel}">修 改</a>'+
	'		<a class="weui-form-preview__btn weui-form-preview__btn_red btn-item-delete" href="javascript:;" style="display:{showdel}">删 除</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 page=1;
	var params = {};
	params['offset'] = 1;
	params['limit'] = 100;
	params['pid'] = pid;
	showLoading();
	if(isBlank(page) || page==1)$('#task-list-box').html('');
	$.post('[[@{/mobile/api/project/task/getList}]]', params, function(result){
		hideLoading();
		var allowModify = result.allowModify;
		if(allowModify)$('.modifybox').show();
		else $('.modifybox').hide();
		if(result.total > 0){
			var items = result.rows;
		//	var projecturl = getSysBaseUrl()+ (debugMode ? '/pages/weixin-work/project/list.jsp' : '/wxwork/pages/project/list.do') + '?queryId='+pid;
			var projecturl = '';
			$('#pagetitle').html('项目：<a href="javascript:;">'+trimToEmpty(items[0].projectName)+'</a>'); // 设置标题
			var html = '';
			for(var i in items){
				html += list_item_html.replaceAll("{dataid}", items[i].id).replaceAll("{taskname}", items[i].name).replaceAll("{content}", trimToEmpty(items[i].content))
				.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("{zxrNames}", trimToEmpty(items[i].zxrNames))
				.replaceAll("{showdel}", allowModify ? "''" : "none");
			}
			$('#task-list-box').append(html);
		}else{
			if(page==1){ // 没有一条数据的时候,在上面也显示暂无数据，明显点
				$('#task-list-box').html('<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>');
			}
		}
	}, 'json');
}


//查询任务日志列表
function getTaskJournalList(taskId){
	$('#layui-timeline-box').html('');
	$.post('[[@{/mobile/api/project/task/journal/getList}]]', {taskId:taskId}, function(result){
		if(result.ret == 0 && result.rows.length>0){
			var items = result.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 delAction(dataid){
	if(isBlank(dataid)){
		toastMsg('请选择要删除的记录！');
		return false;
	}
	showConfirmDialog('确定要删除该记录吗？', function(){
		hideConfirmDialog();
		showLoading('请稍候...');
		$.post('projectTask/del.do', {projectId: pid, ids: dataid}, function(result){
			hideLoading();
			var data = JSON.parse(JSON.stringify(result).trim());
			if(data.statusCode == 200){
				toastMsg('删除成功！', 1);
				getTaskList(1,null);
			}else{
				toastMsg(data.message);
			}
		}, 'json');
	});
}

$(function(){
	var from = trimToEmpty(getQueryString('from'));
	if(from!='appmsg')$('#btn-groups').show(); // 点击推送消息进来的,refer为空，不显示返回新增按钮，否则显示
	
	pid = getQueryString('pid');
	if(!isBlank(pid)){
	//	getTaskList(); // 加载数据
	}
	
	/* 删除记录按钮点击 */
	$('.page__bd').on('click','.btn-item-delete',function(){
    	var dataid = $(this).parent('.btn-parent').attr('dataid');
    	delAction(dataid);
    });
	
	// 修改任务
	$('.page__bd').on('click','.btn-item-update',function(){
    	var dataid = $(this).parent('.btn-parent').attr('dataid');
    	if(debugMode){
			window.location.href = getSysBaseUrl()+'/pages/weixin-work/project/task/add.jsp?pid='+pid+'&id='+dataid;
		}else{
			window.location.href = getSysBaseUrl()+'/wxwork/pages/project/task/add.do?pid='+pid+'&id='+dataid;
		}
    });
	
	
    // 点击进度详情按钮
    $('.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();
    });
    
    
    // 添加任务
    $('#btnAddTask').on('click', function(){
		if(debugMode){
			window.location.href = getSysBaseUrl()+'/pages/weixin-work/project/task/add.jsp?pid='+pid;
		}else{
			window.location.href = getSysBaseUrl()+'/wxwork/pages/project/task/add.do?pid='+pid;
		}
	});
    
	// 修改操作-点击修改按钮
	$('#btn_update').on('click', function(){
		var dataid = $(this).attr('dataid');
		if(debugMode){
			window.location.href = getSysBaseUrl()+'/pages/weixin-work/project/task/add.jsp?id='+dataid;
		}else{
			window.location.href = getSysBaseUrl()+'/wxwork/pages/project/task/add.do?id='+dataid;
		}
	});
	
});
	
	// 下拉加载更多
	$(function(){
		getTaskList();
	});

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