后端:form保存表单控件,entity保存表单数据
@RequiresPermissions("archcodeapplydetail:archcodeApplyDetail:view")
@RequestMapping(value = "getFormByArchtypeid")
@ResponseBody
public Map getFormByArchtypeid(String archid,String tableid,String archtypeid, Map map) {
String type = StringUtils.split(tableid, '_')[2];
if ("project".equals(type)) {
logger.info("project");
SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
map.put("form", sarchiveTypeTree.getProjconf());
ProjectV project = projectVService.getOne(tableid, "0", archid);
map.put("entity", project);
return map;
} else if ("volume".equals(type)) {
logger.info("volume");
SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
map.put("form", sarchiveTypeTree.getVolconf());
VolumeV volume = volumeVService.getOne(tableid, "0", archid);
map.put("entity", volume);
return map;
} else if ("box".equals(type)) {
logger.info("box");
SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
BoxV box = boxVService.getOne(tableid, "0", archid);
map.put("entity", box);
map.put("form", sarchiveTypeTree.getBoxconf());
return map;
} else if ("document".equals(type)) {
logger.info("document");
SarchiveTypeTree sarchiveTypeTree=sarchiveTypeTreeService.get(archtypeid);
map.put("form", sarchiveTypeTree.getDocconf());
DocumentV document = documentVService.getOne(tableid, "0", archid);
map.put("entity", document);
return map;
} else {
logger.info("else");
return null;
}
}
前端
var form=data.form;
var entity=data.entity;
var v1=form.substring(1,form.length-1);
var v2=eval("(" + v1 + ")");
var content='';
for (var i = 0; i < v2.length; i++) {
var temp1='';
var temp2='';
for(var j in entity){
if(j==v2[i].value){
temp1='<div class="col-xs-3">' +
'<div class="form-group">' +
'<label class="control-label col-sm-4" title="">' +
'<span class="required hide">*</span> '+v2[i].text+':<i class="fa icon-question hide"></i></label>' +
'<div class="col-sm-8">' +
'<input type="text" class="form-control" id="'+v2[i].value+'" name="'+v2[i].value+'" readonly="true" value="'+entity[j]+'">'+
'</div>' +
'</div>' +
'</div>';
}else {
temp2='<div class="col-xs-3">' +
'<div class="form-group">' +
'<label class="control-label col-sm-4" title="">' +
'<span class="required hide">*</span> '+v2[i].text+':<i class="fa icon-question hide"></i></label>' +
'<div class="col-sm-8">' +
'<input type="text" class="form-control" id="'+v2[i].value+'" name="'+v2[i].value+'" readonly="true" value="">'+
'</div>' +
'</div>' +
'</div>';
}
}
if(temp1!=''){
content+=temp1;
}
else {
content+=temp2;
}
}
//填充表单
$('#inputForm').find('div').eq(0).html(content);