<%@ 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">
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            var idArr = $("#workItemCollarCatalogList tr:visible");
            if(idArr.length<1){
                parent.layer.msg("请添加物品申请明细!", {icon: 5});
                return false;
            }
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
        var validateForm;
        var count = 0;
        $(document).ready(function() {
            checkContentKeyUp('collarFor',255);
            if($("#collarDate").val()==null || $("#collarDate").val()==''){
                $("#collarDate").val(getNowFormatDate());
            }
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                rules:{
                },
                messages:{
                },
                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);
                    }
                }
            });

            laydate.render({
                elem: '#collarDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                format: 'yyyy-MM-dd',
                type : 'date'
            });


        });

        function deleteRow(obj,index){
            $(obj).parent().parent().remove();
            str[index] = " ";
            mon[index] = 0;

        }
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            month = (month < 10)?"0"+month:month;
            strDate = (strDate < 10)?"0"+strDate:strDate;
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

        function addRow(list, idx, tpl, row){
            var idx1 = $("#workMonthlyPlanThisList tr").length;
            //tpl = tpl.replace("workMonthlyPlanThisList[0]_workClientInfoId","workMonthlyPlanThisList["+idx1+"].workClientInfoId");

            bornTemplete(list, idx, tpl, row, idx1);
        }
        function bornTemplete(list, idx, tpl, row, idx1){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,
                order:idx1 + 1
            }));
            $(list+idx).find("select").each(function(){
                $(this).val($(this).attr("data-value"));
            });
            $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                var ss = $(this).attr("data-value").split(',');
                for (var i=0; i<ss.length; i++){
                    if($(this).val() == ss[i]){
                        $(this).attr("checked","checked");
                    }
                }
            });

        }
        function delRow(obj, prefix){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                delFlag.val("1");
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
                $(obj).parent().parent().addClass("hide");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }


        function isNumber(val){
            if(val === "" || val ==null){
                return false;
            }
            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
            if(regPos.test(val) || regNeg.test(val)){
                return true;
            }else{
                return false;
            }

        }
        function setCatalogInfo(data){
            for(var i=0;i<data.length;i++){
                var idArr = $("#workItemCollarCatalogList tr:visible .workCatalogueItemId");
                if(data[i].id!=''&&!hasInArr(data[i].id,idArr)){
                    addRow('#workItemCollarCatalogList', workItemCollarCatalogListRowIdx, workItemCollarCatalogListTpl);
                    workItemCollarCatalogListRowIdx = workItemCollarCatalogListRowIdx + 1;
                    var row = workItemCollarCatalogListRowIdx - 1 ;
                    $("#"+"workItemCollarCatalogList"+row+"_workCatalogueItemid").val(data[i].id);
                    $("#"+"workItemCollarCatalogList"+row+"_1").val(data[i].number);
                    $("#"+"workItemCollarCatalogList"+row+"_2").val(data[i].name);
                    $("#"+"workItemCollarCatalogList"+row+"_3").val(data[i].type);
                    $("#"+"workItemCollarCatalogList"+row+"_4").val(data[i].model);
                    $("#"+"workItemCollarCatalogList"+row+"_5").val(data[i].primaryUnit);
                    $("#"+"workItemCollarCatalogList"+row+"_6").val(data[i].isAssets);
                    $("#"+"workItemCollarCatalogList"+row+"_8").val(0);
                }
            }
        }
        function hasInArr(id,idArr) {
            for(var i=0;i<idArr.length;i++){
                if(id==$(idArr[i]).val()){
                    return true;
                }
            }
            return false;
        }
        function setAssetsInfo(d){
            addRow('#workItemCollarItemList', workItemCollarItemListRowIdx, workItemCollarItemListTpl);workItemCollarItemListRowIdx = workItemCollarItemListRowIdx + 1;
            var row = workItemCollarItemListRowIdx - 1 ;
            $("#"+"workItemCollarItemList"+row+"_workAssetsId").val(d.id);
            $("#"+"workItemCollarItemList"+row+"_1").val(d.number);
            $("#"+"workItemCollarItemList"+row+"_2").val(d.itemName);
            $("#"+"workItemCollarItemList"+row+"_3").val(d.itemNumber);
            $("#"+"workItemCollarItemList"+row+"_4").val(d.type);
            $("#"+"workItemCollarItemList"+row+"_5").val(d.model);
            $("#"+"workItemCollarItemList"+row+"_6").val(d.primaryUnit);
        }

	</script>
	<style>
		/*超过5个汉字，调整label的长度，以下是配套的*/
		.layui-item .layui-form-label{
			width:90px;
		}
		.form-group .layui-item .layui-input-block,
		.query .layui-input-block {
			margin-left: 116px;
		}
	</style>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workItemCollar" action="${ctx}/workitemcollar/workItemCollar/save" method="post" class="form-horizontal" >
			<form:hidden path="id"/>
			<form:hidden path="home"/>
			<form:hidden path="act.taskId"/>
			<form:hidden path="act.taskName"/>
			<form:hidden path="act.taskDefKey"/>
			<form:hidden path="act.procInsId"/>
			<form:hidden path="act.procDefId"/>
			<form:hidden id="flag" path="act.flag"/>
			<div class="form-group layui-row first">
				<div class="form-group-label"><h2>基础信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>领用人：</label>
					<div class="layui-input-block">
						<form:input id="leader" path="userName" readonly="true" htmlEscape="false" class="form-control  layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>领用编号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:input path="number" htmlEscape="false"  readonly="true"  class="form-control  layui-input"/>
							<span class="input-group-btn">
                                <label class="form-status"><c:choose><c:when test="${not empty workItemCollar.state}">${fns:getDictLabel(workItemCollar.state, 'audit_state', '')}</c:when><c:otherwise>新添</c:otherwise></c:choose></label>
                             </span>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>领用日期：</label>
					<div class="layui-input-block">
						<input id="collarDate" name="collarDate" type="text"  maxlength="20" class="laydate-icondate form-control layer-date  layui-input laydate-icon"
							   value="<fmt:formatDate value="${workItemCollar.collarDate}" pattern="yyyy-MM-dd"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>领用部门：</label>
					<div class="layui-input-block">
						<form:input id="officeName" readonly="true" path="officeName" htmlEscape="false" class="form-control   layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12  with-textarea">
					<label class="layui-form-label">领用事由：</label>
					<div class="layui-input-block">
						<form:textarea path="collarFor" htmlEscape="false" rows="4" onkeyup="checkContentKeyUp('collarFor',255);"   maxlength="255" class="form-control "/>
					</div>
					<span id="contentMsg" style="float: right"></span>
				</div>
			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>物品申请明细</h2></div>
				<div class="layui-item nav-btns">
					<sys:gridselectCatalog url="${ctx}/workcatalogueitem/workCatalogueItem/selectCatalog" id="contentData" title="选择物品目录"
										   fieldLabels="" fieldKeys=""  searchLabel="" searchKey="name"></sys:gridselectCatalog>

				</div>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="contentTable" class="table table-bordered table-condensed can-edit no-bottom-margin">
						<thead>
						<tr>
							<th width="200px">物品编号</th>
							<th width="200px">物品名称</th>
							<th width="150px">物品分类</th>
							<th width="200px">规格型号</th>
							<th width="200px">计量单位</th>
							<th width="200px">是否固定资产</th>
							<th width="200px"><font color="red">*</font>申请数量</th>
							<th width="200px">发放数量</th>
							<th width="200px">操作</th>
						</tr>
						</thead>
						<tbody id="workItemCollarCatalogList">
						<c:if test="${not empty workItemCollar.workItemCollarCatalogList}">
							<c:forEach items="${workItemCollar.workItemCollarCatalogList}" var="workItemCollarCatalog" varStatus="index">
								<tr id="workItemCollarCatalogList${index.index}">
									<td class="hide">
										<input id="workItemCollarCatalogList${index.index}_id" name="workItemCollarCatalogList[${index.index}].id" type="hidden" value="${workItemCollarCatalog.id}"/>
										<input id="workItemCollarCatalogList${index.index}_workCatalogueItemid" name="workItemCollarCatalogList[${index.index}].workCatalogueItem.id" type="hidden" value="${workItemCollarCatalog.workCatalogueItem.id}" class="workCatalogueItemId"/>
										<input id="workItemCollarCatalogList${index.index}_delFlag" name="workItemCollarCatalogList[${index.index}].delFlag" type="hidden" value="0"/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_1"  readonly="true"   name="workItemCollarCatalogList[${index.index}].workCatalogueItem.number" type="text" value="${workItemCollarCatalog.workCatalogueItem.number}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_2"  readonly="true"   name="workItemCollarCatalogList[${index.index}].workCatalogueItem.name" type="text" value="${workItemCollarCatalog.workCatalogueItem.name}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_3"  readonly="true"   name="workItemCollarCatalogList[${index.index}].workCatalogueItem.type" type="text" value="${fns:getDictLabel(workItemCollarCatalog.workCatalogueItem.type, 'item_type', '')}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_4"  readonly="true"   name="workItemCollarCatalogList[${index.index}].workCatalogueItem.model" type="text" value="${workItemCollarCatalog.workCatalogueItem.model}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_5"  readonly="true"   name="workItemCollarCatalogList[${index.index}].workCatalogueItem.primaryUnit" type="text" value="${fns:getDictLabel(workItemCollarCatalog.workCatalogueItem.primaryUnit, 'full_count_unit', '')}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_6" readonly="true"    name="workItemCollarCatalogList[${index.index}].workCatalogueItem.isAssets" type="text" value="${workItemCollarCatalog.workCatalogueItem.isAssets}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_7"    name="workItemCollarCatalogList[${index.index}].applyNum" type="text" value="${workItemCollarCatalog.applyNum}"     class="form-control  number required"/>
									</td>
									<td>
										<input id="workItemCollarCatalogList${index.index}_8"   name="workItemCollarCatalogList[${index.index}].grantNum" type="text" value="${workItemCollarCatalog.grantNum}" readonly="true"   class="form-control number"/>
									</td>
									<td class="text-center op-td" >
										<span class="op-btn op-btn-delete" id="workItemCollarCatalogList${index.index}_span" onclick="delRow(this, '#workItemCollarCatalogList${index.index}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
					<script type="text/template" id="workItemCollarCatalogListTpl">//<!--
                                    <tr id="workItemCollarCatalogList{{idx}}">
                                        <td class="hide">
                                            <input id="workItemCollarCatalogList{{idx}}_id" name="workItemCollarCatalogList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
                                            <input id="workItemCollarCatalogList{{idx}}_workCatalogueItemid" name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.id" type="hidden" value="{{row.workCatalogueItem.id}}" class="workCatalogueItemId"/>
                                            <input id="workItemCollarCatalogList{{idx}}_delFlag" name="workItemCollarCatalogList[{{idx}}].delFlag" type="hidden" value="0"/>
                                        </td>
                                        <td>
                                            <input id="workItemCollarCatalogList{{idx}}_1"   name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.number" type="text" value="{{row.workCatalogueItem.number}}"  readonly="true"   class="form-control "/>
                                        </td>
                                        <td>
                                            <input id="workItemCollarCatalogList{{idx}}_2"  name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.name" type="text" value="{{row.workCatalogueItem.name}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_3"  name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.type" type="text" value="{{row.workCatalogueItem.type}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_4"  name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.model" type="text" value="{{row.workCatalogueItem.model}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_5"  name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.primaryUnit" type="text" value="{{row.workCatalogueItem.primaryUnit}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_6"  name="workItemCollarCatalogList[{{idx}}].workCatalogueItem.isAssets" type="text" value="{{row.workCatalogueItem.isAssets}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_7"  name="workItemCollarCatalogList[{{idx}}].applyNum" type="text" value="{{row.applyNum}}"    class="form-control number required"/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarCatalogList{{idx}}_8"  name="workItemCollarCatalogList[{{idx}}].grantNum" type="text" value="{{row.grantNum}}"  readonly="true"   class="form-control "/>
                                        </td>
                                        <td class="text-center op-td" >
                                            {{#delBtn}}<span class="op-btn op-btn-delete" id="workItemCollarCatalogList{{idx}}_span" onclick="delRow(this, '#workItemCollarCatalogList{{idx}}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>{{/delBtn}}
                                        </td>
                                    </tr>//-->
					</script>
					<script type="text/javascript">
                        var workItemCollarCatalogListRowIdx = ${fn:length(workItemCollar.workItemCollarCatalogList)}, workItemCollarCatalogListTpl = $("#workItemCollarCatalogListTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                        if($("#id").val()){
                            workItemCollarCatalogListIdx = ${fn:length(workItemCollar.workItemCollarCatalogList)};
                        }
                        $(document).ready(function() {
                        });
					</script>
				</div>
			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>固定资产明细</h2></div>
				<%--<div class="layui-item nav-btns">
					<sys:gridselectAssets url="${ctx}/workitem/workItem/selectItem" id="contentData1" title="选择物品一览"
										  fieldLabels="" fieldKeys=""  searchLabel="" searchKey="name"></sys:gridselectAssets>

				</div>--%>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="contentTable1" class="table table-bordered table-condensed can-edit no-bottom-margin">
						<thead>
						<tr>
							<th width="200px">固定资产编号</th>
							<th width="200px">物品名称</th>
							<th width="150px">物品编号</th>
							<th width="150px">物品分类</th>
							<th width="200px">规格型号</th>
							<th width="200px">计量单位</th>
							<th width="200px">操作</th>
						</tr>
						</thead>
						<tbody id="workItemCollarItemList">
						<c:if test="${not empty workItemCollar.workItemCollarItemList}">
							<c:forEach items="${workItemCollar.workItemCollarItemList}" var="workItemCollarItem" varStatus="index">
								<tr id="workItemCollarItemList${index.index}">
									<td class="hide">
										<input id="workItemCollarItemList${index.index}_id" name="workItemCollarItemList[${index.index}].id" type="hidden" value="${workItemCollarItem.id}"/>
										<input id="workItemCollarItemList${index.index}_workAssetsId" name="workItemCollarItemList[${index.index}].itemId" type="hidden" value="${workItemCollarItem.itemId}"/>
										<input id="workItemCollarItemList${index.index}_delFlag" name="workItemCollarItemList[${index.index}].delFlag" type="hidden" value="0"/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_1"  readonly="true"   name="workItemCollarItemList[${index.index}].itemNumber" type="text" value="${workItemCollarItem.itemNumber}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_2"  readonly="true"   name="workItemCollarItemList[${index.index}].itemName" type="text" value="${workItemCollarItem.itemName}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_3"  readonly="true"   name="workItemCollarItemList[${index.index}].itemCatalogNumber" type="text"  value="${workItemCollarItem.itemCatalogNumber}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_4"  readonly="true"   name="workItemCollarItemList[${index.index}].itemType" type="text"  value="${workItemCollarItem.itemType}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_5"  readonly="true"   name="workItemCollarItemList[${index.index}].itemModel" type="text" value="${workItemCollarItem.itemModel}"   class="form-control "/>
									</td>
									<td>
										<input id="workItemCollarItemList${index.index}_6"  readonly="true"   name="workItemCollarItemList[${index.index}].itemPrimaryUnit" type="text"  value="${workItemCollarItem.itemPrimaryUnit}"  class="form-control "/>
									</td>
									<td class="text-center op-td" >
										<span class="op-btn op-btn-delete" id="workItemCollarItemList${index.index}_span" onclick="delRow(this, '#workItemCollarItemList${index.index}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
					<script type="text/template" id="workItemCollarItemListTpl">//<!--
                                    <tr id="workItemCollarItemList{{idx}}">
                                        <td class="hide">
                                            <input id="workItemCollarItemList{{idx}}_id" name="workItemCollarItemList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
                                            <input id="workItemCollarItemList{{idx}}_workAssetsId" name="workItemCollarItemList[{{idx}}].itemId" type="hidden" value="{{row.itemId}}"/>
                                            <input id="workItemCollarItemList{{idx}}_delFlag" name="workItemCollarItemList[{{idx}}].delFlag" type="hidden" value="0"/>
                                        </td>
                                        <td>
                                            <input id="workItemCollarItemList{{idx}}_1"   name="workItemCollarItemList[{{idx}}].itemNumber" type="text" value="{{row.itemNumber}}"  readonly="true"   class="form-control "/>
                                        </td>
                                        <td>
                                            <input id="workItemCollarItemList{{idx}}_2"  name="workItemCollarItemList[{{idx}}].itemName" type="text" value="{{row.itemName}}"   readonly="true"  class="form-control "/>
                                        </td>
                                        <td>
                                            <input id="workItemCollarItemList{{idx}}_3"  name="workItemCollarItemList[{{idx}}].itemCatalogNumber" type="text" value="{{row.itemCatalogNumber}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarItemList{{idx}}_4"  name="workItemCollarItemList[{{idx}}].itemType" type="text" value="{{row.itemType}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarItemList{{idx}}_5"  name="workItemCollarItemList[{{idx}}].itemModel" type="text" value="{{row.itemModel}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workItemCollarItemList{{idx}}_6"  name="workItemCollarItemList[{{idx}}].itemPrimaryUnit" type="text" value="{{row.itemPrimaryUnit}}"   readonly="true"  class="form-control "/>
                                        </td>

                                        <td class="text-center op-td" >
                                            {{#delBtn}}<span class="op-btn op-btn-delete" id="workItemCollarItemList{{idx}}_span" onclick="delRow(this, '#workItemCollarItemList{{idx}}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>{{/delBtn}}
                                        </td>
                                    </tr>//-->
					</script>
					<script type="text/javascript">
                        var workItemCollarItemListRowIdx = 0, workItemCollarItemListTpl = $("#workItemCollarItemListTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                        if($("#id").val()){
                            workItemCollarItemListIdx = ${fn:length(workItemCollar.workItemCollarItemList)};
                        }
                        $(document).ready(function() {
                        });
					</script>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>

</body>
</html>