<%@ 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" src="${ctxStatic}/helloweba_editable-select/jquery.editable-select.min.js"></script>
	<link rel='stylesheet' type="text/css" href="${ctxStatic}/helloweba_editable-select/jquery.editable-select.min.css"/>
	<script type="text/javascript">
		var validateForm;
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $("#inputForm").submit();
			  return true;
		  }
		  return false;
		}
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});

		function changeUser(ids,names) {
		    var projectId = $("#id").val();
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'${ctx}/project/projectRecordUsers/getProjectRecordUsers',
                data:{"ids":ids,"projectId":projectId},
                cache:false,
                success: function(data) {
                    var str = "";
                    var userIds = $("#userIds").val();
                    var msgInfo = "";
                    for (var i=0; i<data.length; i++) {
                        var msg = data[i].msg;
                        if(msg == "del") {
                            var id = data[i].id;
                            $("#delFlag"+id).val("正常");
                            $("#del"+id).css("display","inline-block");
                        } else if (msg == "msg") {
                            var id = data[i].id;
                            var name = data[i].name;
                            var office = data[i].officeId;
                            var no = data[i].no;
                            var mobile = data[i].mobile;
                            var email = data[i].email;
                            var jobName = data[i].jobName;
                            userIds += id + ",";
                            str += '<tr id="'+id+'">' +
                                '<td>' +
                                no +
                                '</td>' +
                                '<td>' +
                                name +
                                '</td>' +
                                '<td>' +
                                office +
                                '</td>' +
                                '<td>' +
                                jobName+
                                '</td>' +
                                '<td>' +
                                mobile +
                                '</td>' +
                                '<td>' +
                                email +
                                '</td>' +
                                '<td style="padding: 0px">' +
                                '<input id="delFlag'+id+'" name="delFlag" type="text"  readonly="true" value="正常" class="form-control layui-input"/>' +
                                '</td>' +
                                '<td>' +
                                '<span id="del'+id+'" onclick="delRow(this,\''+id+'\')" title="移除" class="op-btn op-btn-delete"><i class="fa fa-trash"></i>&nbsp;移除</span>' +
                                '</td>' +
                                '</tr>';
                        } else {
                            msgInfo = msg;
                        }
                    }
                    $("#usersList").append(str);
                    if (msgInfo!= null && msgInfo != '' && msgInfo!= undefined){
                        parent.layer.msg("新增项目成员成功！"+msgInfo,{icon:1});
                    }else {
                        parent.layer.msg("新增项目成员成功！",{icon:1});
                    }
                },
                error:function () {
                    parent.layer.msg("获取用户信息失败！！！",{icon:2});
                    parent.layer.close(loadingMessage);
                }
            });
        }

        function delRow(obj,id){
            var projectId = $("#id").val();
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'${ctx}/project/projectRecordUsers/removeProjectRecordUsers',
                data:{"userId":id,"projectId":projectId},
                cache:false,
                success: function(data) {
                    if (data!= null && data != '' && data!= undefined){
                        var msg = data.msg;
                        if (msg){
                            parent.layer.msg("移除用户成功！！！",{icon:1});
                        }else {
                            parent.layer.msg("项目负责人不能被移除！！！",{icon:2});
                        }
                    }else {
                        parent.layer.msg("移除用户失败！！！",{icon:2});
                    }
                },
                error:function () {
                    parent.layer.msg("移除用户失败！！！",{icon:2});
                }
            });
		    $("#delFlag"+id).val("移除");
		    $("#del"+id).css("display","none");
        }
        function getSelectUserIds() {
            return "";
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="projectRecords" action="${ctx}/project/projectRecordUsers/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="workContractInfo.client.id" id="contractClientId" value="${workContractInfo.client.id}"/>
			<div class="form-group layui-row first">
				<div class="form-group-label"><h2>项目成员信息</h2></div>
				<div class="layui-item layui-col-sm12 lw6">
					<label class="layui-form-label">项目名称：</label>
					<div class="layui-input-block">
						<input readonly="true" htmlEscape="false" class="form-control layui-input"  value="${projectRecords.projectName}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 lw6">
					<label class="layui-form-label">项目编号：</label>
					<div class="layui-input-block">
						<input readonly="true" htmlEscape="false" class="form-control layui-input"  value="${projectRecords.projectId}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 lw6">
					<label class="layui-form-label">项目负责人：</label>
					<div class="layui-input-block">
						<input readonly="true" htmlEscape="false" class="form-control layui-input"  value="${projectRecords.leaderNameStr}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 lw6">
					<label class="layui-form-label">合同名称：</label>
					<div class="layui-input-block">
						<input readonly="true" htmlEscape="false" class="form-control layui-input"  value="${projectRecords.workContractInfo.name}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 lw6">
					<label class="layui-form-label">委托方：</label>
					<div class="layui-input-block">
						<input readonly="true" htmlEscape="false" class="form-control layui-input"  value="${projectRecords.workContractInfo.client.name}"/>
					</div>
				</div>
			</div>

	<div class="form-group layui-row">
		<div class="form-group-label"><h2>成员明细</h2></div>
		<div class="layui-item nav-btns">
			<sys:treeselectusers id="members" name="projectMembers" value="${projectRecords.memberIds}" labelName="memberNameStr" labelValue="${projectRecords.memberNameStr}"
								 title="用户" url="/sys/office/treeDataAll?type=3" checked="true" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
			<%--<a class="nav-btn nav-btn-add" onclick="addRow('#workAccountList', workAccountListRowIdx, workAccountListTpl);workAccountListRowIdx = workAccountListRowIdx + 1;" title="新增"><i class="fa fa-plus"></i>&nbsp;新增</a>--%>
		</div>
		<div class="layui-item layui-col-xs12 form-table-container" >
			<table  class="table table-bordered table-condensed no-bottom-margin details">
				<thead>
				<tr>
					<th>工号</th>
					<th>姓名</th>
					<th>部门</th>
					<th>职级</th>
					<th>手机号</th>
					<th>邮箱</th>
					<th width="80px;">状态</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody id="usersList">
				<c:if test="${not empty users}">
					<c:forEach items="${users}" var="user">
						<tr id="${user.id}">
							<td>
									${user.no}
							</td>
							<td>
									${user.name}
							</td>
							<td>
									${user.office.name}
							</td>
							<td>
									${user.basicInfo.jobGrade.name}
							</td>
							<td>
									${user.mobile}
							</td>
							<td>
									${user.email}
							</td>
							<td style="padding:0px;">
								<c:choose>
									<c:when test="${user.delFlag == 0}">
										<input id="delFlag${user.id}" name="delFlag" type="text"  readonly="true" value="正常" class="form-control layui-input"/>
									</c:when>
									<c:otherwise>
										<input id="delFlag${user.id}" name="delFlag" type="text"  readonly="true" value="移除" class="form-control layui-input"/>
									</c:otherwise>
								</c:choose>
							</td>
							<td>
								<c:if test="${user.delFlag == 0}">
									<span id="del${user.id}" onclick="delRow(this,'${user.id}')" title="移除" class="op-btn op-btn-delete"><i class="fa fa-trash"></i>&nbsp;移除</span>
								</c:if>
								<c:if test="${user.delFlag != 0}">
									<span id="del${user.id}" onclick="delRow(this,'${user.id}')" title="移除" style="display: none;" class="op-btn op-btn-delete"><i class="fa fa-trash"></i>&nbsp;移除</span>
								</c:if>

							</td>
						</tr>
					</c:forEach>
				</c:if>
				</tbody>
			</table>
		</div>
		<div class="form-group layui-row page-end"></div>
	</div>
	</form:form>
	</div>
</div>
</body>
</html>