<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>工程项目信息管理</title>
	<meta name="decorator" content="default"/>
    <script src="${ctxStatic}/layer-v2.3/laydate/laydate.js"></script>
	<script type="text/javascript">
		var validateForm;
		function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
              // 回调函数，在编辑和保存动作时，供openDialog调用提交表单。
              if(obj == 3) {
                  $("#remarks").val("yes");
              }else if(obj == 4){
                  $("#remarks").val("no");
              }
			  $("#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);
					}
				}
			});
            $("input[name='isExt']").on('ifChecked', function(event){
                var radioVal = $(this).val();
                if(radioVal == 0){
                    $("#td1").removeClass("hide");
                    $("#td3").removeClass("hide");
                    $("#td4").removeClass("hide");
                    $("#td2").addClass("hide");
                    $("#tr1").show()
                }else{
                    $("#td1").addClass("hide");
                    $("#td3").addClass("hide");
                    $("#td4").addClass("hide");
                    $("#td2").removeClass("hide");
                    $("#tr1").hide()
                }
            });
            if("${workEngineeringProject.isExt}" == "1"){
                $("#ext1").iCheck('check')
            }else{
                $("#ext").iCheck('check')
            }
		});
        function  chooseType() {
            if($("#psort").val()==1){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").show();$("#ssort12").show();$("#ssort13").show();
                $("#ssort21").hide();$("#ssort22").hide();$("#ssort23").hide();$("#ssort24").hide();
                $("#ssort31").hide();$("#ssort32").hide();$("#ssort33").hide();$("#ssort34").hide();$("#ssort35").hide();$("#ssort36").hide();
                $("#ssort41").hide();$("#ssort42").hide();
                $("#ssort51").hide();$("#ssort52").hide();$("#ssort53").hide();$("#ssort54").hide();$("#ssort55").hide();
                $("#ssort101").hide();$("#ssort102").hide();
            }
            else if($("#psort").val()==2){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").hide();$("#ssort12").hide();$("#ssort13").hide();
                $("#ssort21").show();$("#ssort22").show();$("#ssort23").show();$("#ssort24").show();
                $("#ssort31").hide();$("#ssort32").hide();$("#ssort33").hide();$("#ssort34").hide();$("#ssort35").hide();$("#ssort36").hide();
                $("#ssort41").hide();$("#ssort42").hide();
                $("#ssort51").hide();$("#ssort52").hide();$("#ssort53").hide();$("#ssort54").hide();$("#ssort55").hide();
                $("#ssort101").hide();$("#ssort102").hide();
            }
            else if($("#psort").val()==3){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").hide();$("#ssort12").hide();$("#ssort13").hide();
                $("#ssort21").hide();$("#ssort22").hide();$("#ssort23").hide();$("#ssort24").hide();
                $("#ssort31").show();$("#ssort32").show();$("#ssort33").show();$("#ssort34").show();$("#ssort35").show();$("#ssort36").show();
                $("#ssort41").hide();$("#ssort42").hide();
                $("#ssort51").hide();$("#ssort52").hide();$("#ssort53").hide();$("#ssort54").hide();$("#ssort55").hide();
                $("#ssort101").hide();$("#ssort102").hide();
            }
            else if($("#psort").val()==4){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").hide();$("#ssort12").hide();$("#ssort13").hide();
                $("#ssort21").hide();$("#ssort22").hide();$("#ssort23").hide();$("#ssort24").hide();
                $("#ssort31").hide();$("#ssort32").hide();$("#ssort33").hide();$("#ssort34").hide();$("#ssort35").hide();$("#ssort36").hide();
                $("#ssort41").show();$("#ssort42").show();
                $("#ssort51").hide();$("#ssort52").hide();$("#ssort53").hide();$("#ssort54").hide();$("#ssort55").hide();
                $("#ssort101").hide();$("#ssort102").hide();
            }
            else if($("#psort").val()==5){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").hide();$("#ssort12").hide();$("#ssort13").hide();
                $("#ssort21").hide();$("#ssort22").hide();$("#ssort23").hide();$("#ssort24").hide();
                $("#ssort31").hide();$("#ssort32").hide();$("#ssort33").hide();$("#ssort34").hide();$("#ssort35").hide();$("#ssort36").hide();
                $("#ssort41").hide();$("#ssort42").hide();
                $("#ssort51").show();$("#ssort52").show();$("#ssort53").show();$("#ssort54").show();$("#ssort55").show();
                $("#ssort101").hide();$("#ssort102").hide();
            }
            else if($("#psort").val()==10){
                $("#ssort ").attr("value","");
                document.getElementById( "t1").style.display= "";
                document.getElementById( "t2").style.display= "";
                $("#ssort11").hide();$("#ssort12").hide();$("#ssort13").hide();
                $("#ssort21").hide();$("#ssort22").hide();$("#ssort23").hide();$("#ssort24").hide();
                $("#ssort31").hide();$("#ssort32").hide();$("#ssort33").hide();$("#ssort34").hide();$("#ssort35").hide();$("#ssort36").hide();
                $("#ssort41").hide();$("#ssort42").hide();
                $("#ssort51").hide();$("#ssort52").hide();$("#ssort53").hide();$("#ssort54").hide();$("#ssort55").hide();
                $("#ssort101").show();$("#ssort102").show();
            }else{
                document.getElementById( "t1").style.display= "none";
                document.getElementById( "t2").style.display= "none";
            }
        }
        function setValue(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workreimbursement/workReimbursement/getProjectInfoo',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#projectNumber").val(d.projectNumber);
                }
            })
        }

        var linkManList_contract = null;
        function setContractValue(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workengineeringproject/workEngineeringProject/getContractInfo',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = linkManList_contract = JSON.parse(data);
                    $("#linkman_list").html("");
                    $(".linkman_attr").val("");
                    var defaultLinkMan = d[0];
                    if(defaultLinkMan != null && defaultLinkMan != undefined && defaultLinkMan !=""){
                        $("#contractNum").val(defaultLinkMan.contractNum);
                        $("#clientName").val(defaultLinkMan.clientName);
                        $("#clientId").val(defaultLinkMan.clientId);
                        $("#linkmanName").val(defaultLinkMan.linkmanName);
                        $("#linkmanPhone").val(defaultLinkMan.linkmanPhone);
                        $("#linkmanEmail").val(defaultLinkMan.linkmanEmail);
                        $("#linkmanPosition").val(defaultLinkMan.linkmanPosition);

                        $.each(d,function(n,value) {
                            var optionTag = '<option id="linkman_attr_'+n+'" type="text" value='+n+'>'+value.linkmanName+'</option>';
                            $("#linkman_list").append(optionTag);
                        });
                        $("#linkman_list option:first").prop("selected","selected").text(defaultLinkMan.linkmanName);
                    }
                }
            })
        }

        var linkManList = null;
        function setValuee(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workengineeringproject/workEngineeringProject/getClientInfo',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    linkManList = d;
                    console.log("d==="+d);
                    var defaultLinkMan = d[0];
                    $("#linkman_list").html("");
                    $(".linkman_attr").val("");
                    if(defaultLinkMan != null && defaultLinkMan != undefined && defaultLinkMan !=""){
                        $("#clientName").val(defaultLinkMan.clientName);
                        $("#clientId").val(defaultLinkMan.clientId);
                        //$("#linkmanName").val(defaultLinkMan.linkmanName);
                        $("#linkmanPhone").val(defaultLinkMan.linkmanPhone);
                        $("#linkmanEmail").val(defaultLinkMan.linkmanEmail);
                        $("#linkmanPosition").val(defaultLinkMan.linkmanPosition);

                        $.each(d,function(n,value) {
                            var optionTag = '<option id="linkman_attr_'+n+'" type="text" value='+n+'>'+value.linkmanName+'</option>';
                            $("#linkman_list").append(optionTag);
                        });
                        $("#linkman_list option:first").prop("selected","selected").text(defaultLinkMan.linkmanName);
                    }

                }
            })
        }

        /**
         * 查看联系人（需要用到linkManList）
         */
        function selectLinkman(index,target) {
            console.log("linkManList==="+linkManList);
            if(target=='linkman'){
                var manList = null ;
                //以自选为主
                if(linkManList != null){
                    manList = linkManList; //自选的
                    console.log(1);
                }else{
                    manList = linkManList_contract; //合同关联的
                    console.log(2);
                }
                if(manList ==null){
                    console.log(3);
                    manList = JSON.parse('${requestScope.linkmanList}');
                }
                var linkman = manList[index];
                $("#linkmanPosition").val(linkman.linkmanPosition==undefined?"":linkman.linkmanPosition);
                $("#linkmanPhone").val(linkman.linkmanPhone==undefined?"":linkman.linkmanPhone);
                $("#linkmanEmail").val(linkman.linkmanEmail==undefined?"":linkman.linkmanEmail);
            }
        }

        function display(n){
            if(n==0){
                $("#contractIdtd").show();
                $("#numtd").show();
                $("#contractNumtd").show();
                $("#contractInfoNametd").hide();
            }else{
                $("#contractIdtd").hide();
                $("#numtd").hide();
                $("#contractNumtd").hide();
                $("#contractInfoNametd").show();
            }
        }

        function display1(){
            var id =$("#bidCompanyId")[0].defaultValue;
            $.get("${ctx}/workclientinfo/workClientInfo/selectLinkman", { clientId: id},
                function(data,textStatus){
                    data = data.body.list;
                    if(data !=null){
                        for (var i=0; i<data.length; i++){
                            addRow('#workClientLinkmanList', workClientLinkmanRowIdx, workClientLinkmanTpl, data[i]);
                            workClientLinkmanRowIdx = workClientLinkmanRowIdx + 1;
                        }
                    }
                });
        }
	</script>
</head>
<body class="hideScroll">
		<form:form id="inputForm" modelAttribute="workEngineeringProject" action="${ctx}/workengineeringproject/workEngineeringProject/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="remarks"/>
		<sys:message content="${message}"/>

			<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
               <tbody>
                      <%--<tr>
                          <td class="width-20 active" rowspan="3"><label class="pull-right">合同信息:</label></td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"> 是否签署合同  ：</label></td>
                          <td class="width-35" colspan="3">
                              <input type="radio" class="i-checks" name="isExt" checked id="ext" value="0">
                              <label for="ext">系统内合同</label>
                              <input type="radio" class="i-checks" name="isExt" id="ext1" value="1">
                              <label for="ext1">系统外合同</label>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">合同名称：<font color="red">*</font></label></td>
                          <td class="width-25" id="td1">
                              <sys:gridselectContract url="${ctx}/workengineeringproject/workEngineeringProject/selectcontractId" id="contractId" isTotal="" name="contractId.id" type="1,2"  value="${workEngineeringProject.contractId.id}"  title="选择合同名称" labelName="contractId.name"
                                                      labelValue="${workEngineeringProject.contractId.name}" cssClass="form-control required" fieldLabels="合同信息" fieldKeys="name" searchLabel="合同名称" searchKey="name" ></sys:gridselectContract>
                          </td>
                          <td class="width-15 active" id="td3"><label class="pull-right">合同编号：<font color="red">*</font></label></td>
                          <td class="width-25" id="td4">
                              <form:input path="contractId.contractNum" id="contractNum" htmlEscape="false"  readonly="true"   class="form-control required" cssStyle="width: 200px;"/>
                          </td>
                          <td class="width-35 hide" colspan="3" id="td2">
                              <form:input path="contractInfoName" id="contractInfoName" htmlEscape="false"    class="form-control required"/>
                          </td>
                      </tr>--%>
                      <tr>
                          <td class="width-20 active" rowspan="3" ><label class="pull-right">是否签署合同:</label></td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">合同标识：</label></td>
                          <td class="width-25" colspan="3">
                              <input type="radio" class="i-checks" name="isExt" checked id="ext" value="0">
                              <label for="ext">系统内合同</label>
                              <input type="radio" class="i-checks" name="isExt" id="ext1" value="1">
                              <label for="ext1">系统外合同</label>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">合同名称：</label></td>
                          <td class="width-25" id="td1">
                            <%--  <sys:gridselectContract url="${ctx}/workengineeringproject/workEngineeringProject/selectcontractId" id="contractId" isTotal="" name="contractId.id" type="1,2"  value="${workEngineeringProject.contractId.id}"  title="选择合同名称" labelName="contractId.name"
                                                      labelValue="${workEngineeringProject.contractId.name}" cssClass="form-control required" fieldLabels="合同信息" fieldKeys="contractName" searchLabel="合同名称" searchKey="name" ></sys:gridselectContract>--%>
                                <sys:gridselectContract url="${ctx}/workengineeringproject/workEngineeringProject/selectcontractId" type="1,2" isTotal="" id="contractId" name="contractId.id"  value="${workEngineeringProject.contractId.id}"  title="选择合同" labelName="contractId.name"
                                                        labelValue="${workEngineeringProject.contractId.name}" cssClass="form-control required" fieldLabels="合同信息" fieldKeys="name" searchLabel="合同名称" searchKey="name" ></sys:gridselectContract>
                          </td>
                          <td  class="width-25 hide" colspan="3" id="td2">
                              <form:input path="contractInfoName" id="contractInfoName" htmlEscape="false"    class="form-control required"/>
                          </td>
                          <td class="width-15 active" id="td3"><label class="pull-right">合同编号：</label></td>
                          <td class="width-25" id="td4">
                              <form:input path="contractId.contractNum" id="contractNum" htmlEscape="false"  readonly="true"   class="form-control required"/>
                          </td>
                      </tr>
                      <%--<tr >
                          <td class="width-15 active" id="td3"><label class="pull-right">合同编号：</label></td>
                          <td class="width-25" id="td4">
                              <form:input path="contractId.contractNum" id="contractNum" htmlEscape="false"  readonly="true"   class="form-control required" cssStyle="width: 200px;"/>
                          </td>
                      </tr>--%>
                      <tr>
                          <td class="width-20 active" rowspan="8"><label class="pull-right">项目信息:</label></td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">总项目名称：</label></td>
                          <td class="width-25" colspan="3">
                              <c:choose>
                                  <c:when test="${not empty workEngineeringProject.totalProjectName}">
                                      <form:input path="totalProjectName" readonly="true" class="form-control" />
                                  </c:when>
                                  <c:otherwise>
                                      <sys:gridselectcalltotalproject url="${ctx}/workengineeringproject/workEngineeringProject/selectprojectTotal" id="totalProjectId" name="totalProjectId" isTotal="1"  value="${workEngineeringProject.totalProjectId}"  title="选择总项目" labelName="workEngineeringProject.totalProjectName"
                                                                      labelValue="${workEngineeringProject.totalProjectName}" cssClass="form-control" fieldLabels="工程" fieldKeys="totalProjectName" searchLabel="工程名称" searchKey="name" ></sys:gridselectcalltotalproject>
                                  </c:otherwise>
                              </c:choose>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>项目名称：</label></td>
                          <td class="width-25">
                                  <form:input path="projectId.name" id="" htmlEscape="false"  class="form-control required" />
                          </td>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>项目编号：</label></td>
                          <td class="width-25">
                              <form:input path="projectId.number" id="projectNumber" htmlEscape="false"  readonly="true"   class="form-control required" />
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">行业分类：</label></td>
                          <td class="width-35">
                              <form:select id="psort" path="psort" class="form-control" onChange="chooseType()"><%--onChange="changeTypeExplain(this)"--%>
                                  <form:option value="" label=""/>
                                  <form:options items="${fns:getDictList('psort')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                              </form:select>
                          </td>
                          <td class="width-15 active" id="t1" style="display:none"><label class="pull-right">详细分类：</label></td>
                          <td class="width-35" id="t2" style="display:none">
                              <form:select path="ssort" class="form-control" onChange="changeTypeExplain(this)">
                                  <form:option value="" label=""/>
                                  <form:options id="ssort1" items="${fns:getDictList('ssort1')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                  <form:options id="ssort2" items="${fns:getDictList('ssort2')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                  <form:options id="ssort3" items="${fns:getDictList('ssort3')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                  <form:options id="ssort4" items="${fns:getDictList('ssort4')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                  <form:options id="ssort5" items="${fns:getDictList('ssort5')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                  <form:options id="ssort10" items="${fns:getDictList('ssort10')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                              </form:select>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>工作开始时间：</label></td>
                          <td class="width-25">
                              <input class="form-control required layer-date laydate-icon" id="workStartDate" name="workStartDate" value="<fmt:formatDate value="${workEngineeringProject.workStartDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
                          </td>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>业务类型：</label></td>
                          <td class="width-25">
                              <form:select path="businessType" class="form-control required">
                                  <form:option value="" label=""/>
                                  <form:options items="${fns:getMainDictList('business_type')}" itemLabel="label" itemValue="value" htmlEscape="false" />
                              </form:select>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"> <label class="pull-right"><font color="red">*</font>工作结束时间：</label></td>
                          <td class="width-25">
                              <input class="form-control required layer-date laydate-icon" id="workEndDate" name="workEndDate" value="<fmt:formatDate value="${workEngineeringProject.workEndDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
                          </td>
                          <td class="width-15 active"><label class="pull-right">预送审金额(元)：</label></td>
                          <td class="width-25">
                              <form:input path="preTrialAmount" htmlEscape="false"    class="form-control  number"/>

                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">业主要求：</label></td>
                          <td class="width-25" colspan="3">
                              <form:textarea path="emploperRequire" htmlEscape="false" rows="3"    class="form-control "/>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>所属公司/部门：</label></td>
                          <td class="width-25">
                              <sys:treeselect id="office" name="office.id" value="${workEngineeringProject.office.id}" labelName="office.name" labelValue="${workEngineeringProject.office.name}"
                                              title="部门" url="/sys/office/treeDataAll?type=2" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>

                          </td>
                          <td class="width-15 active"><label class="pull-right"><font color="red">*</font>工程所在地：</label></td>
                          <td class="width-25">
                              <sys:treeselect id="area" name="area.id" value="${workEngineeringProject.area.id}" labelName="area.name" labelValue="${workEngineeringProject.area.name}"
                                              title="区域" url="/sys/area/treeData" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>

                          </td>
                      </tr>
                      <tr>
                          <td class="width-20 active" rowspan="4"><label class="pull-right">客户信息：</label></td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"> <font color="red">*</font>客户单位：</label></td>
                          <td class="width-25" colspan="3">
                              <sys:gridselect url="${ctx}/workbidproject/workBidProject/selectbidCompany" id="client" name="workClientInfo.id"  value="${workEngineeringProject.workClientInfo.id}"  title="选择客户单位" labelName="workClientInfo.name"
                                              labelValue="${workEngineeringProject.workClientInfo.name}" cssClass="form-control required" fieldLabels="客户" fieldKeys="name" searchLabel="客户名称" searchKey="name"  ></sys:gridselect>

                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right">查看联系人：</label></td>
                          <td class="width-25">
                              <select id="linkman_list" onchange="selectLinkman(this.value,'linkman')" class="linkman_list max-width-250 form-control" />
                          </td>
                          <td class="width-15 active"><label class="pull-right">职务：</label></td>
                          <td class="width-25">
                              <form:input path="workClientInfo.workClientLinkmanList[0].position" id="linkmanPosition" readonly="true" class="form-control linkman_attr"/>
                          </td>
                      </tr>
                      <tr>
                          <td class="width-15 active"><label class="pull-right"> 联系方式：</label></td>
                          <td class="width-25">
                                  <form:input path="workClientInfo.workClientLinkmanList[0].linkPhone" id="linkmanPhone" readonly="true" class="form-control linkman_attr"/>
                          </td>
                          <td class="width-15 active"><label class="pull-right">E-mail：</label></td>
                          <td class="width-25">
                                  <form:input path="workClientInfo.workClientLinkmanList[0].email" id="linkmanEmail" readonly="true" class="form-control linkman_attr"/>
                          </td>
                      </tr>
                 </tbody>
            </table>
	</form:form>
</body>
</html>