<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>项目评估</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        $(document).ready(function() {

            //搜索框收放
            $('#moresee').click(function(){
                if($('#moresees').is(':visible'))
                {
                    $('#moresees').slideUp(0,resizeListWindow2);
                    $('#moresee i').removeClass("glyphicon glyphicon-menu-up").addClass("glyphicon glyphicon-menu-down");
                }else{
                    $('#moresees').slideDown(0,resizeListWindow2);
                    $('#moresee i').removeClass("glyphicon glyphicon-menu-down").addClass("glyphicon glyphicon-menu-up");
                }
            });
            laydate.render({
                elem: '#beginDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus', //响应事件。如果没有传入event，则按照默认的click
                type : 'date'
            });
            laydate.render({
                elem: '#endDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus', //响应事件。如果没有传入event，则按照默认的click
                type : 'date'
            });
        });
        function getWeeklyState(id)
        {
            var result ={};
            result.action = true;
            switch(id)
            {
                case "0":result.label = "reject";result.status="未完成";result.action = false;break;
                case "1":result.label = "signed";result.status="已完成";break;
                default:
                    result.label = "unknown";result.status="未知";break;
            }
            return result;
        }
        function reset() {
            $("#searchForm").resetForm();
        }

        function openDialog(title,url,width,height,target) {

            if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端，就使用自适应大小弹窗
                width = 'auto';
                height = 'auto';
            } else {//如果是PC端，根据用户设置的width和height显示。

            }

            top.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                content: url,
                skin: 'three-btns',
                btn: ['送审', '暂存', '关闭'],
                btn1: function(index, layero){
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(iframeWin.contentWindow.doSubmit(1) ){
                        // top.layer.close(index);//关闭对话框。
                        setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                    }
                },
                btn2:function(index,layero){
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(iframeWin.contentWindow.doSubmit(2) ){
                        // top.layer.close(index);//关闭对话框。
                        setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                    }else {
                        return false;
                    }
                },
                btn3: function (index) {
                }
            });
        }

        function openDialogre(title,url,width,height,target,buttons) {

            if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端，就使用自适应大小弹窗
                width = 'auto';
                height = 'auto';
            } else {//如果是PC端，根据用户设置的width和height显示。

            }
            var split = buttons.split(",");
            top.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                skin: 'three-btns',
                content: url,
                btn: split,
                btn1: function(index, layero){
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(iframeWin.contentWindow.doSubmit(1) ){
                        // top.layer.close(index);//关闭对话框。
                        setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                    }
                },
                btn2:function(index,layero){
                    if(split.length==2){return}
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(iframeWin.contentWindow.doSubmit(2) ){
                        // top.layer.close(index);//关闭对话框。
                        setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                    }else {
                        return false;
                    }
                },
                btn3: function (index) {
                }
            });
        }
	</script>
	<style>
		body{
			background-color:transparent;
			filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#26FFFFFF, endColorstr=#26FFFFFF);
			color:#ffffff;
			background-color:rgba(255,255,255,0);
			height:100%;
		}
	</style>
</head>
<body>
<div class="wrapper wrapper-content">
	<sys:message content="${message}"/>
	<div class="layui-row">
		<div class="full-width fl">
			<div class="layui-row contentShadow shadowLR" id="queryDiv">
				<form:form id="searchForm" modelAttribute="projectPlanWeekly" action="${ctx}/projectplan/weekly/" method="post" class="form-inline">
					<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
					<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
					<table:sortColumn id="orderBy" name="orderBy" value="${page.orderBy}" callback="sortOrRefresh();"/><!-- 支持排序 -->
					<div class="commonQuery lw6">
						<div class="layui-item query athird ">
							<label class="layui-form-label double-line"><span class="require-item">*</span>任务完成状态：</label>
							<div class="layui-input-block">
								<select id="weeklyStatus" name="weeklyStatus" class="form-control simple-select required" lay-verify="">
									<option value="0" <c:if test="${weeklyStatus eq '0' }">selected</c:if>>未完成</option>
									<option value="1" <c:if test="${weeklyStatus eq '1' }">selected</c:if>>已完成</option>
								</select>
							</div>
						</div>
						<div class="layui-item query athird ">
							<label class="layui-form-label">任务计划时间：</label>
							<div class="layui-input-block">
								<input id="beginDate" name="beginDate" placeholder="开始时间" type="text" readonly="readonly" maxlength="20" class="laydate-icondate form-control layer-date layui-input laydate-icon query-group"
									   value="<fmt:formatDate value="${beginDate}" pattern="yyyy-MM-dd"/>"/>
								</input>
								<span class="group-sep">-</span>
								<input id="endDate" name="endDate" placeholder="结束时间" type="text" readonly="readonly" maxlength="20" class="laydate-icondate form-control layer-date layui-input laydate-icon query-group"
									   value="<fmt:formatDate value="${endDate}" pattern="yyyy-MM-dd"/>"/>
								</input>
							</div>
						</div>
						<div class="layui-item athird">
							<div class="input-group">
								<a href="#" id="moresee"><i class="glyphicon glyphicon-menu-down"></i></a>
								<button id="searchReset" class="fixed-btn searchReset fr" onclick="resetSearch()">重置</button>
								<button id="searchQuery" class="fixed-btn searchQuery fr" onclick="search()">查询</button>
							</div>
						</div>
						<div style="clear:both;"></div>
					</div>
				</form:form>
			</div>
		</div>
		<div class="full-width fl">
			<div class="layui-form contentDetails contentShadow shadowLBR">
				<div class="nav-btns">
					<a href="javascript:void(0)" onclick="openDialog('新增个人周报', '${ctx}/projectplan/weekly/form?tabId=1','95%','95%')" class="nav-btn nav-btn-add" ><i class="fa fa-plus"></i>&nbsp;添加</a>
					<button class="nav-btn nav-btn-refresh" data-toggle="tooltip" data-placement="left" onclick="sortOrRefresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i>&nbsp;刷新</button>
					<div style="clear: both;"></div>
				</div>
				<table class="oa-table layui-table" id="workPlanWeekly"></table>

				<!-- 分页代码 -->
				<table:page page="${page}"></table:page>
				<div style="clear: both;"></div>
			</div>
		</div>
	</div>
	<div id="changewidth"></div>
</div>

<script src="${ctxStatic}/layer-v2.3/layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use('table', function(){
        layui.table.render({
            limit:${ page.pageSize }
            ,elem: '#workPlanWeekly'
            ,page: false
            ,cols: [[
                {field:'index',align:'center', title: '序号',width:40}
                ,{align:'center',title:'周报内容',width:200,templet:function(d){
                    var xml = "";
                    if (d.remarks != undefined && d.remarks != '' && d.remarks != null) {
                      xml+= "<a class=\"attention-info\" title=\"" + d.remarks + "\" href=\"javascript:void(0);\" onclick=\"openDialogView('查看项目', '${ctx}/projectplan/weekly/view?id=" + d.id +"&projectId="+d.projectId+"','95%', '95%')\">" + d.remarks + "</a>";
                    }
					return xml;
				}}
                ,{align:'center',width:150, title: '项目信息',templet:function(d){
                        var xml = "";
                        if (d.projectId != undefined && d.projectId != '' && d.projectId != null ){
                            xml = "<a class=\"attention-info\" title=\"" + d.projectName + "\" href=\"javascript:void(0);\" onclick=\"openDialogView('查看项目', '${ctx}/project/projectRecords/view?id=" + d.projectId +"','95%', '95%')\">" + d.projectName + "</a>";
                        }else {
                            xml = "<span>无项目</span>";
                        }
                        return xml;
                    }}
                ,{field:'createBy',align:'center', title: '负责人',width:100}
                ,{field:'createDate',align:'center', title: '计划创建日期',width:100}
                ,{field:'beginDate',align:'center', title: '计划开始日期',width:100}
                ,{field:'endDate',align:'center', title: '计划结束日期',width:100}
                ,{align:'center',width:100, title: '状态' ,templet:function(d){
                        var st = getWeeklyState(d.weeklyStatus);
                        if(st.action)
                            var xml = "<span style=\"cursor:default;\" class=\"status-label status-label-" + st.label + "\" >" + st.status + "</span>";
                        else
                            var xml = "<span style=\"cursor:default;\" class=\"status-label status-label-" + st.label + "\" >" + st.status + "</span>";
                        return xml;
                }}
                ,{align:'center',width:150, title: '备注信息',templet:function(d){
                    var xml = "";
                    if (d.remarksReason != undefined){
                        xml += "<span id=reason"+d.id+">"+d.remarksReason+"</span>";
                    }else {
                        xml += "<span id=reason"+d.id+"></span>";
                    }
                    return xml;
				}}
                ,{field:'op',align:'center',width:300,title:"操作",templet:function(d){
                        ////对操作进行初始化
                        var xml="";
                        if(d.weeklyStatus != undefined && d.weeklyStatus =="0")
                        {
                            if (d.btnAgent != undefined && d.btnAgent == '0'){
                                xml+="<a href=\"#\" onclick=\"openDialog('修改周报信息', '${ctx}/projectplan/weekly/form?id=" + d.id +"','95%', '95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i> 修改</a>";
                            	xml+="<a href=\"${ctx}/projectplan/weekly/sureWeeklyStatus?id=" + d.id + "&projectId="+d.projectId+"\" onclick=\"return confirmx('确认要完成该工作计划吗？', this.href)\" class=\"op-btn op-btn-op-btn-revert\" style=\"color: white;background: darkseagreen\"><i class=\"fa fa-check\"></i>确认完成</a>";
                            	xml+="<a href=\"#\" onclick=\"weeklyText('" + d.id+"','"+d.projectId+"')\" class=\"op-btn op-btn-op-btn-revert\" style=\"color: white;background: #ffa44e\" ><i class=\"fa fa-plus-square-o\"></i> 备注</a>";
                            	xml+="<a href=\"${ctx}/projectplan/weekly/delete?id=" + d.id + "&projectId="+d.projectId+"\" onclick=\"return confirmx('确认要删除该计划信息吗？', this.href)\" class=\"op-btn op-btn-delete\"><i class=\"fa fa-trash\"></i> 删除</a>";
                            }
						}
                        return xml;

                }}
            ]]
            ,data: [
                <c:if test="${ not empty page.list}">
                <c:forEach items="${page.list}" var="projectPlanWeekly" varStatus="index">
                <c:if test="${index.index != 0}">,</c:if>
                {
                    "index":"${index.index+1}"
                    ,"id":"${projectPlanWeekly.id}"
                    ,"remarks":"${projectPlanWeekly.remarks}"
					,"createBy":"${projectPlanWeekly.createBy.id}"
					,"createDate":"<fmt:formatDate value="${projectPlanWeekly.createDate}" pattern="yyyy-MM-dd"/>"
                    ,"beginDate":"<fmt:formatDate value="${projectPlanWeekly.beginDate}" pattern="yyyy-MM-dd"/>"
                    ,"endDate":"<fmt:formatDate value="${projectPlanWeekly.endDate}" pattern="yyyy-MM-dd"/>"
                    ,"weeklyStatus":"${projectPlanWeekly.weeklyStatus}"
                    ,"projectId":"${projectPlanWeekly.projectRecords.id}"
                    ,"projectName":"${projectPlanWeekly.projectRecords.projectName}"
                    ,"remarksReason":"${projectPlanWeekly.remarksReason}"
					,"btnAgent":"${projectPlanWeekly.btnAgent}"
                }
                </c:forEach>
                </c:if>
            ]
        });
    })

    resizeListTable();
    $("a").on("click",addLinkVisied);
</script>
<script>
    resizeListWindow2();
    $(window).resize(function(){
        resizeListWindow2();
    });

    function openDialog(title,url,width,height,target) {
        if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端，就使用自适应大小弹窗
            width = 'auto';
            height = 'auto';
        } else {//如果是PC端，根据用户设置的width和height显示。
        }
        top.layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            skin: 'three-btns',
            btn: ['确定', '关闭'],
            btn1: function(index, layero){
                var body = top.layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if(target){
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                }else{
                    top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                }
                inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                if(iframeWin.contentWindow.doSubmit(1) ){
                    top.layer.close(index);//关闭对话框。
                    setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                }
            },
            btn2: function (index) {
            }
        });
    }

    function weeklyText(id,projectId){
        top.layer.prompt({title: '请填写未完成原因'},function(val, index){
            $.post("${ctx}/projectplan/weekly/saveRemarksReason",{"id":id,"projectId":projectId,"remarksReason":val},function(data){
                if(data.success){
                    parent.layer.msg(data.msg, {icon:1});
                    $("#reason"+id).html(val);
                    top.layer.close(index);
                }else{
                    parent.layer.msg(data.msg, {icon:2});
                    top.layer.close(index);
                }
            })
        });
    }

    function weeklySure(id,projectId) {
        $.post("${ctx}/projectplan/weekly/sureWeeklyStatus",{"id":id,"projectId":projectId},function(data){
            if(data.success){
                parent.layer.msg(data.msg, {icon:1});
                window.location.reload();
            }else{
                parent.layer.msg(data.msg, {icon:2});
            }
        })
    }
</script>
</body>
</html>