废话不多说走起
<tr>
<td colspan="4" style="padding: 0px;">
<table id="tctjTable" class="table_type_A hbBuildSuperviseBody" style="margin: 0px;">
<thead>
<tr>
<td style="width: 11%">
<span class="addRow" onclick="addRow(this,true,9,'bztBody',true)"> ⊕ </span>序号</td>
<td style="width: 11%">合同工程量清单项目编号</td>
<td style="width: 11%">分包工作名称</td>
<td style="width: 11%">单位</td>
<td style="width: 11%">合同工程量</td>
<td style="width: 11%">合同单价(元)</td>
<td style="width: 11%">合同金额(元)</td>
<td style="width: 11%">分包工作金额(元)</td>
<td style="width: 11%">分包工作金额占签约合同价的比例(%)</td>
</tr>
</thead>
<tbody id="bztBody"></tbody>
</table>
</td>
</tr>
<jsp:include page="BuildSuperviseBody.jsp"></jsp:include>
<script>
require([ "ckeditor/ckeditor","laydate"], function() {});
$(function () {
window.getDataInitialization(9,"bztBody",true);
});
function huizongData(){
//获得表单信息
var bztBody = window.getTableDataId("bztBody");
var total1 = window.getDataToJson(bztBody);//table_1
var dateAllTable = [total1];
$("#BuildSuperviseBodyJson").val(JSON.stringify(dateAllTable));
}
</script>
<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<style>
/*动态增加样式*/
.addRow{position: absolute;left: -20px;bottom: -8px;font-weight: bolder;cursor: pointer;font-size: 20px;color:gray}
.deleteRow{position: absolute;left: -20px; bottom: 17px;;font-weight: bolder;cursor: pointer;font-size: 15px;color: gray;}
</style>
<%
String root = request.getContextPath();
%>
<script type="text/javascript">
// var column; /*tr 1-n*/
var idTable;/*id*/
var dynamic; /*number true false*/
var jADD=1;
function imgAdd(){
$(".addRow").html("<img src='<%=root%>/hb/buildSupervise/hebeiSpecialWorkflow/addTableTr/jia.png'/>")
$(".deleteRow").html("<img src='<%=root%>/hb/buildSupervise/hebeiSpecialWorkflow/addTableTr/jian.png'/>")
}
window.getDataInitialization = function (columns,idTables,dynamics,dataTypeTheads){
// column=columns;
idTable=idTables;
dynamic=dynamics;
this.addRow(undefined,true,columns,idTables,dynamics,dataTypeTheads)
imgAdd()
}
function addRow(dom,isOne,columns,idTables,dynamics,dataTypeTheads) {
var myMap = new Map()
if (dataTypeTheads!=undefined){
var splits = dataTypeTheads.split(";")
for(var str in splits){
var nub = splits[str].split(",")
myMap.set(nub[0],nub[1])
}
}
if (dataTypeTheads!=undefined){
dataTypeTheads="'"+dataTypeTheads+"'"
}
var html=new Array();
html.push("<tr>");
var columnsFor = columns;
var numberCol = 0;
if (col(myMap.get("1"))!="false"){
numberCol=parseInt(col(myMap.get("1"))[1]);
html.push("<td colspan='"+numberCol+"'>");
columnsFor = columns-(numberCol-1);
}else {
html.push("<td >");
}
for(var [key, value] of myMap){
if (key!="1"){
if(col(value)!="false"){
numberCol=parseInt(col(value)[1]);
columnsFor = columnsFor-(numberCol-1);
}
}
}
dynamic=dynamics;
html.push("<input type='text' hidden/>");
if(dynamic){
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',true,"+dataTypeTheads+")\"></span>");
html.push("<span></span>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',true,"+dataTypeTheads+")\"> </span>");
}else {
if (myMap.get("1")!=undefined){
// add one date
if (myMap.get("1")=="date"){
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='text' class='classLaydate' onClick=\"laydate()\" readonly/>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}else if (myMap.get("1")=="person"){
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='hidden' id='deptFzrId"+jADD+"' />");
html.push("<input id='deptFzrName"+jADD+"' type='text' selector='true' singleselect='true' hidField='deptFzrId"+jADD+"' selector_icon='people01_icon' onClick=\"spf_selector(this,'person')\" />");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}else if (col(myMap.get("1"))!="false"){
if (col(myMap.get("1"))[2]=="date"){
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='text' class='classLaydate' onClick=\"laydate()\" readonly/>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}else if (col(myMap.get("1"))[2]=="person"){
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='hidden' id='deptFzrId"+jADD+"' />");
html.push("<input id='deptFzrName"+jADD+"' type='text' selector='true' singleselect='true' hidField='deptFzrId"+jADD+"' selector_icon='people01_icon' onClick=\"spf_selector(this,'person')\" />");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}else {
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='text'/>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}
html.push("</td>");
}else {
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='text'/>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}
}else {
html.push("<span class=\"addRow\" onclick=\"addRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
html.push("<input type='text'/>");
html.push("<span class=\"deleteRow\" onclick=\"deleteRow(this,false,"+columns+",'"+idTables+"',false,"+dataTypeTheads+")\"> </span>");
}
}
html.push("</td>");
for (var i = 1; i < columnsFor; i++) {
if (myMap.get(""+(i+1)+"")!=undefined){
// add one date
if (myMap.get(""+(i+1)+"")=="date"){
html.push("<td>");
html.push("<input type='text' class='classLaydate' onClick=\"laydate()\" readonly/>");
html.push("</td>");
}else if (myMap.get(""+(i+1)+"")=="person"){
html.push("<td>");
html.push("<input type='hidden' id='deptFzrId"+jADD+i+"' />");
html.push("<input id='deptFzrName"+jADD+i+"' type='text' selector='true' singleselect='true' hidField='deptFzrId"+jADD+i+"' selector_icon='people01_icon' onClick=\"spf_selector(this,'person')\" />");
html.push("</td>");
}else if (myMap.get(""+(i+1)+"")=="select1"){//新增安全管理
html.push("<td>");
html.push("<input type='hidden' class='nameInput' value=''/>");
html.push(" <select onchange='openValue(this)' class=\"spf_input_option\">\n" +
"<option value =\"未检查\">未检查</option>\n" +
"<option value =\"已检查\">已检查</option>\n" +
"<option value =\"未落实\">未落实</option>\n" +
"<option value =\"已落实\">已落实</option>\n" +
"</select>");
html.push("</td>");
}else if (col(myMap.get(""+(i+1)+""))!="false"){
numberCol=parseInt(col(myMap.get(""+(i+1)+""))[1]);
html.push("<td colspan='"+numberCol+"'>")
if (col(myMap.get(""+(i+1)+""))[2]=="date"){
html.push("<input type='text' class='classLaydate' onClick=\"laydate()\" readonly/>");
}else if (col(myMap.get(""+(i+1)+""))[2]=="person"){
html.push("<input type='hidden' id='deptFzrId"+jADD+i+"' />");
html.push("<input id='deptFzrName"+jADD+i+"' type='text' selector='true' singleselect='true' hidField='deptFzrId"+jADD+i+"' selector_icon='people01_icon' onClick=\"spf_selector(this,'person')\" />");
}else {
html.push("<input type='text'/>");
}
html.push("</td>");
}else {
html.push("<td>");
html.push("<input type='text'/>");
html.push("</td>");
}
}else {
html.push("<td>");
html.push("<input type='text'/>");
html.push("</td>");
}
}
html.push("</tr>");
idTable=idTables;
if (isOne){
if (idTables!=undefined){
$("#"+idTables).append(html.join(""))
}else {
$("#"+idTable).append(html.join(""))
}
}else {
$(dom).parent().parent().after(html.join(""));
}
if(dynamic){
reflushNo();
}
jADD++;
imgAdd()
try {//调用回调函数
if(typeof(window.saveAddRow(dom))=="function"){
}
}catch(e){
//这是捕捉异常
}
}
function col(Col) {
if (Col!=undefined){
var cop = Col.split("_")
if(cop.length>=2){
return cop;
}else {
return "false";
}
}else {
return "false";
}
}
function deleteRow(dom) {
try {//调用回调函数
if(typeof(window.saveDelRow(dom))=="function"){
}
}catch(e){
//这是捕捉异常
}
$(dom).parent().parent().remove();
if(dynamic){
reflushNo();
}
}
function deleteRow2(dom) {
$(dom).remove();
if(dynamic){
reflushNo();
}
}
function reflushNo() {
$("#"+idTable+" tr").each(function (index) {
$(this).children("td").eq(0).children("span").eq(1).html(index+1);
})
}
function reflushNo2(idTable2) {
$("#"+idTable2+" tr").each(function (index) {
$(this).children("td").eq(0).children("span").eq(1).html(index+1);
})
}
//jquery table data all
window.getTableDataAll = function (){
var milasUrl={};
var subMilasUrlArr={};
var tableData={};
$("#tctjTable tbody tr").each(function(trindex,tritem){
tableData[trindex]=new Array();
$(tritem).find("input:Visible").each(function(index,value){
tableData[trindex][index]=$(value).val();
subMilasUrlArr[trindex]=tableData[trindex];
});
});
for(var key in subMilasUrlArr){
milasUrl[key]=subMilasUrlArr[key];
}
return milasUrl;
}
//jquery table data all by id
window.getTableDataId = function (nameid){
var milasUrl={};
var subMilasUrlArr={};
var tableData={};
$("#"+nameid+" tr").each(function(trindex,tritem){
tableData[trindex]=new Array();
$(tritem).find("input:Visible").each(function(index,value){
tableData[trindex][index]=$(value).val();
subMilasUrlArr[trindex]=tableData[trindex];
});
});
for(var key in subMilasUrlArr){
milasUrl[key]=subMilasUrlArr[key];
}
return milasUrl;
}
//jquery table data all by id
window.getTableDataIdNotHidde = function (nameid){
var milasUrl={};
var subMilasUrlArr={};
var tableData={};
$("#"+nameid+" tr").each(function(trindex,tritem){
tableData[trindex]=new Array();
$(tritem).find("input").each(function(index,value){
tableData[trindex][index]=$(value).val();
subMilasUrlArr[trindex]=tableData[trindex];
});
});
for(var key in subMilasUrlArr){
milasUrl[key]=subMilasUrlArr[key];
}
return milasUrl;
}
//data to all
var number = 1;
window.getDataToJson = function (arr){
var count = 1;
var Json = {};
$.each(arr,function(name,value) {
Json[count] = value;
count++;
});
var table = "table_"+number;
number++;
var map = new Map();
map.set(table,Json);
return _mapToJson(map);
}
//map to json
function _strMapToObj(strMap){
let obj= Object.create(null);
for (let[k,v] of strMap) {
obj[k] = v;
}
return obj;
}
function _mapToJson(map){
return JSON.stringify(this._strMapToObj(map));
}
</script>