<!DOCTYPE html>
<html lang=zh-cn>
    <head>
	<meta charset=utf-8>
	<title>纵横计量支付系统</title>
	<meta name=description content=计量支付>
	<meta name=copyright content=smartcost.com.cn>
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
	<link rel=stylesheet href="{{rootUrl}}global/css/bootstrap.css">
	<link rel=stylesheet href={{rootUrl}}global/css/style.css>
	<script src={{rootUrl}}global/js/jquery-1.9.1.min.js></script>
	<script src={{rootUrl}}global/js/bootstrap.js></script>
	<script src={{rootUrl}}global/js/jl.js></script>
    </head>
    <body>
	<!-- include "top" -->
	<div class="wrapContent">
	    <!-- include "left" -->
	    <div class="mainContainer">
		<!--内容-->
		<div class="mainContent">
		    <div class="title clearfix">
			<div class="fR">
			    <!--			    <div class="btn-group">
							    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
								排序
								<span class="caret"></span>
							    </a>
							    <ul class="dropdown-menu">
								<li><a href="">创建时间</a></li>
								<li><a href="">最近审批</a></li>
								<li><a href="">进度完成度</a></li>
							    </ul>
							</div>-->
			    <a class="btn btn-primary"  href="#addpoj" data-toggle="modal" ><i class="icon-plus icon-white"></i>&nbsp;添加项目</a>
			</div>
			<h1>这些是您创建的项目</h1>
		    </div>
		    <div class="project">
			<!-- loop pros -->
			<div class="projectEntry odd clearfix">
			    <div class="pojIcon fL c{{pros' value.index}}"><div data-icon="I" aria-hidden="true"></div></div>
			    <div class="pojDetail fL">
				<div class="title fL"><h5><a href="{{rootUrl}}project/{{pros' value.pid}}/overview">{{pros' value.pname}}</a></h5><a id="idt_{{pros' value.pid}}" pid="{{pros' value.pid}}" pname="{{pros' value.pname}}" href="#editpoj" data-toggle="modal"><span data-icon="S" aria-hidden="true" class="closePanel" data-placement="bottom" data-toggle="tooltip" data-original-title="修改项目名称"></span></a>&nbsp;<a href="#share" data-toggle="modal" onclick="setproject('{{pros' value.pid}}');"><span data-icon="n" aria-hidden="true" class="closePanel" data-placement="bottom" data-toggle="tooltip" data-original-title="分享链接"></span></a></div>
				<div class="detail fR"><p data-original-title="总价：￥{{pros' value.bcontracttotal}} 变更：+￥{{pros' value.bchangTotal}}" data-placement="bottom" data-toggle="tooltip">总价：￥{{pros' value.bcontracttotal}}元 (<span class="colRed">+￥{{pros' value.bchangTotal}}</span>)</p>
				    <div class="progress">
					<div class="progress-bar progress-bar-success" style="width: {{pros' value.pcurrdone}};">{{pros' value.pcurrdone}}</div>
				    </div></div>
				<div class="detail2 fR"><p>标段总计：{{pros' value.numMeasure}}</p><p>{{formatDate(pros' value.intime,'Y-m-d')}}</p></div>
			    </div>
			</div>
			<!-- endloop -->
		    </div>
		</div>
		<!--内容-->
	    </div>
	</div>
	<!-- 添加项目弹出 -->
	<div id="addpoj" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h4 class="modal-title">添加项目</h4>
				</div>
				<form class="form-horizontal" method="post" name="proform">
					<div class="modal-body">
						<div class="form">
							<div class="form-group">
								<label class="control-label col-sm-2">项目名称</label>
								<div class="col-sm-8">
									<input class="form-control" name="pname" id="pname" type="text" placeholder="输入项目名称">
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
						<input type="submit" class="btn btn-primary" id="pform" name="pform" value="保存" />
					</div>
				</form>
			</div>
		</div>
	</form>
    </div>
    <!-- 添加项目弹出 -->
    <!-- 编辑项目弹出 -->
    <div id="editpoj" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<form class="form-horizontal" method="post">
					<input type="hidden" id="ppid" name="ppid" value="0" />
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title">修改项目名称</h4>
					</div>
					<div class="modal-body">
						<div class="form">
							<div class="form-group">
								<label class="control-label col-sm-2" for="target_pname">项目名称</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" id="target_pname" name="target_pname" placeholder="输入项目名称" value="黄金大桥项目">
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
						<input type="submit" class="btn btn-primary" value="保存" />
					</div>
				</form>
			</div>
		</div>
    </div>
    <!-- 编辑项目弹出 -->
	<!-- 分享链接弹出 -->
	<div id="share" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h4 class="modal-title">项目分享</h4>
				</div>
				<div class="modal-body">
					<div class="form">
						<!--按项目分享-->
						<div class="form-horizontal" >
							<input type="hidden" id="projectid" value="">
							<div class="form-group">
								<label class="control-label col-sm-3">选择分享类型</label>
								<div class="col-sm-8">
									<label class="radio-inline">
										<input type="radio" name="selectshare" value="1" checked> 分享项目
									</label>
									<label class="radio-inline">
										<input type="radio" name="selectshare" value="2"> 分享标段类型
									</label>
									<label class="radio-inline">
										<input type="radio" name="selectshare" value="3"> 分享标段
									</label>
								</div>
							</div>
							<div id="selectshare1" class="sharediv">
							</div>

							<!--按标段类型分享-->
							<div id="selectshare2" class="sharediv" style="display:none;">
							</div><!--按标段分享-->

							<div id="selectshare3" class="sharediv" style="display: none">
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<!-- 分享链接弹出 -->

	<script type="text/javascript">autoFlashHeight();</script>
    <script type="text/javascript">
	$(function () {
	    $("#pname").keydown(function (event) {
		if (event.which == 13) {
		    document.proform.submit();
		}
	    });
	    $("[id^='idt_']").click(function (e) {
		var pid = $(this).attr('pid');
		var pname = $(this).attr('pname');
		$("#target_pname").val(pname);
		$("#ppid").val(pid);
	    });

		$('input[name="selectshare"]').on('click',function(){
			$('.sharediv').hide();

			if($(this).val() == 1 && $('#selectshare'+$(this).val()).html().trim() == ''){
				$.ajax({
					type: 'post',
					url: '/share/get/project',
					data: {pid:$('#projectid').val()},
					dataType: 'json',
					success:function(result){
						var html = '';
						$.each(result,function(k,v){
							if(v.ischeckd == 0){
								html += '<div class="form-group" id="control_project_'+ v.id +'"> <label class="control-label col-sm-3"></label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="1"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
							}else{
								html += '<div class="form-group" id="control_project_'+ v.id +'"> <label class="control-label col-sm-3"></label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="1"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/project/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
							}
						});
						$('#selectshare1').html(html);

						$('.setshare').unbind('click').on('click',function(e){
							if ($(e.target).is("label"))
								return;
							send($(this).children('input').is(':checked'),$(this).attr('data-id'),$(this).attr('data-type'));
						})
					}
				})
			}else if($(this).val() == 2 && $('#selectshare'+$(this).val()).html().trim() == ''){
				$.ajax({
					type: 'post',
					url: '/share/get/section',
					data: {pid:$('#projectid').val()},
					dataType: 'json',
					success:function(result){
						var html = '';
						$.each(result,function(k,v){
							if(v.ischeckd == 0){
								html += '<div class="form-group" id="control_section_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="2"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
							}else{
								html += '<div class="form-group" id="control_section_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="2"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/section/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
							}
						});
						$('#selectshare2').html(html);

						$('.setshare').unbind('click').on('click',function(e){
							if ($(e.target).is("label"))
								return;
							send($(this).children('input').is(':checked'),$(this).attr('data-id'),$(this).attr('data-type'));
						})
					}
				})
			}else if($(this).val() == 3 && $('#selectshare'+$(this).val()).html().trim() == ''){
				$.ajax({
					type: 'post',
					url: '/share/get/tender',
					data: {pid:$('#projectid').val()},
					dataType: 'json',
					success:function(result){
						var html = '';
						$.each(result,function(k,v){
							if(v.ischeckd == 0){
								html += '<div class="form-group" id="control_tender_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="3"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
							}else{
								html += '<div class="form-group" id="control_tender_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="3"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/tender/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
							}
						});
						$('#selectshare3').html(html);

						$('.setshare').unbind('click').on('click',function(e){
							if ($(e.target).is("label"))
								return;
							send($(this).children('input').is(':checked'),$(this).attr('data-id'),$(this).attr('data-type'));
						})
					}
				})
			}
			$('#selectshare'+$(this).val()).show();
		});
	});
	function setproject(pid){
		if(pid != $('#projectid').val()){
			$('#selectshare1').html('');
			$('#selectshare2').html('');
			$('#selectshare3').html('');
			$.ajax({
				type: 'post',
				url: '/share/get',
				data: {pid:pid},
				dataType: 'json',
				success:function(result) {
					var html = '';
					if(result.page == null){
						$("input[name='selectshare']").eq(0).prop("checked",true);
						html += '<div class="form-group" id="control_project_'+ pid +'"> <label class="control-label col-sm-3"></label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ pid +'" data-type="1"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
						$('#selectshare1').html(html);
					}else if(result.page == 1) {
						$("input[name='selectshare']").eq(0).prop("checked",true);
						$.each(result.filearray,function(k,v){
							html += '<div class="form-group" id="control_project_'+ pid +'"> <label class="control-label col-sm-3"></label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ pid+'" data-type="1"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/project/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
						});
						$('#selectshare1').html(html);
					}else if(result.page == 2) {
						$("input[name='selectshare']").eq(1).prop("checked",true);
						$.each(result.filearray,function(k,v){
							if(v.ischeckd == 0){
								html += '<div class="form-group" id="control_section_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="2"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
							}else{
								html += '<div class="form-group" id="control_section_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="2"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/section/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
							}
						});
						$('#selectshare2').html(html);
						$('.sharediv').hide();
						$('#selectshare2').show();
					}else if(result.page == 3) {
						$("input[name='selectshare']").eq(2).prop("checked",true);
						$.each(result.filearray,function(k,v){
							if(v.ischeckd == 0){
								html += '<div class="form-group" id="control_tender_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="3"> <input type="checkbox"> 启用 </label> </div> </div> </div>';
							}else{
								html += '<div class="form-group" id="control_tender_'+ v.id +'"> <label class="control-label col-sm-3">'+ v.name +'</label> <div class="col-sm-8"> <div class="checkbox"> <label style="display: inline-block;" class="setshare" data-id="'+ v.id+'" data-type="3"> <input type="checkbox" checked> 启用 </label> </div> </div> <label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="{{rootUrl}}share/tender/'+ v.hashcode+'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div> </div>';
							}
						});
						$('#selectshare3').html(html);
						$('.sharediv').hide();
						$('#selectshare3').show();
					}

					$('.setshare').unbind('click').on('click',function(e){
						if ($(e.target).is("label"))
							return;
						send($(this).children('input').is(':checked'),$(this).attr('data-id'),$(this).attr('data-type'));
					})
				}
			})
		}
		$('#projectid').val(pid);
//		$('#share').modal('show');
	}

	function send(check,id,type){
		$.ajax({
			type: 'post',
			url : '/share/set',
			data:{check:check,id:id,type:type},
			dataType:'json',
			success:function(result){
				var type2 = type == 1 ? 'project' : (type == 2 ? 'section' : 'tender');
				if(check){
					var html = '';
					var url = '{{rootUrl}}share/'+ type2 + '/' + result.sharecode;
					html += '<label class="control-label col-sm-3">链接</label> <div class="col-sm-8"> <input class="form-control" type="text" placeholder="这是该项目的KEY" value="'+ url +'" readonly class="span4" onfocus="this.select()" onmouseover="this.focus()"> <p>分享以上链接即可免登录查阅标段类型下的标段汇总信息。</p> </div>';
					$('#control_'+type2+'_'+id).append(html);
				}else{
					$('#control_'+type2+'_'+id).children('.control-label').eq(1).remove();
					$('#control_'+type2+'_'+id).children('.col-sm-8').eq(1).remove();
				}
			}
		});
	}
    </script>
</body>