function sendForm() {
var invOrderModelWrapper = {};
// 头
var objHeader = $('#invOrderForm').serializeObject();
invOrderModelWrapper.invOrderModel = objHeader;
// 明细
var objDetail = {
id: "",
invId: "",
skuId: "", // sku
skuCode: "",
factoryId: "",
price: "", //
stockNum: "", //库存数量
stockAmount: "", // 总成本
lossNum: "",//报损量
lossAmount: "", //报
invNum: "", //盘点量
invAmount: "", //盘点
invLossNum: "", //盘点报
invLossAmount: "", //
remarks: "" //备注
}
var objArrDetail = constructObjectFromTable(objDetail, $('#invOrderDetailForm .table-row-cell')); if (objArrDetail.length == 0) {
$.alert({
title: '提示',
content: "盘点明细不能为空!",
buttons: {"好的": {btnClass: 'btn-blue'}}
});
return false;
} invOrderModelWrapper.invOrderDetailModels = objArrDetail; $.ajax({
type: "POST",
dataType: "json",
cache: false,
contentType: "application/json; charset=utf-8",
url: "/storage/invOrder/saveInvOrderModel",
data: JSON.stringify(invOrderModelWrapper),
success: function (data) {
if (data.code) {
$.alert({
title: '提示',
content: "操作成功!",
buttons: {
"好的": {
btnClass: 'btn-blue',
action: function () {
var invIdTemp = $('#invId').val();
var invTypeTemp = $('#invType').val();
window.location.href = "/storage/invOrder/viewInvOrder?id=" + invIdTemp + "&invType=" + invTypeTemp + "&viewTypeTo=view&modelType=guanli";
}
}
}
}); return;
} else {
$.alert({
title: '提示',
content: "操作失败!",
buttons: {"好的": {btnClass: 'btn-blue'}}
}); }
} }) }
function save() {
    sendForm("");
<section class="content">
 
 <div class="row box box-primary" id="viewDiv">
<div class="col-md-16">
<div class="box-body">
<input type="hidden" id="info" value="${info!}">
<form id="invOrderForm" class="form-horizontal"
data-validator-option="{theme:'bootstrap', timely:2, stopOnError:true}" method="post">
<div class="form-inline">
<input type="hidden" id="invId" name="id" value="${invOrderModel.id}"/>
<input type="hidden" id="invType" name="invType"
value="${invOrderModel.invType}"
placeholder="标记是基础盘点还是库存盘点"/>
<input type="hidden" id="creator" name="creator" value="${invOrderModel.creator}"
placeholder="登陆人">
<input type="hidden" id="auditState" name="auditState" value="${invOrderModel.auditState}"
placeholder="审核状态 0:待提交 1:待审核 2:已审核 3:已驳回"> <label for="invCode">盘点单编码:</label>
<input type="text" id="invCode" name="invCode" class="form-control"
value="${(invOrderModel.invCode)!}" readonly="true"> <label for="storageName">盘点仓库:</label>
<input type="hidden" id="storageId" name="storageId" class="form-control"
value="${(invOrderModel.storageId)!}" readonly="true">
<input type="text" id="storageName" name="storageName" class="form-control"
value="${(invOrderModel.storageName)!}" readonly="true">
<!--添加SKU-->
<a class="btn btn-primary pull-right" href="javascript:addSKU();"><i
class="fa fa-plus"></i> 添加SKU
</a>
</div>
</form>
<div class="form-group">
<div class="box-body table-responsive no-padding col-sm-16">
<form id="invOrderDetailForm" class="form-horizontal"
data-validator-option="{theme:'bootstrap', timely:2, stopOnError:true}" method="post">
<table class="table table-hover tdnowrap">
<thead>
<tr>
<th>系列</th>
<th>产品型号</th>
<th>尺寸</th>
<th>材质</th>
<th>颜色</th>
<th>结构</th>
<th>配套件1</th>
<th>配套件2</th> <th>sku码</th>
<th>生产部</th>
<th>单价</th>
<th>库存量</th>
<th>总成本(元)</th>
<th>报损量</th>
<th>总报损(元)</th>
<th>盘点量</th>
<th>盘点额(元)</th>
<th>盘点报损量</th>
<th>盘点报损额(元)</th>
<th>备注</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<#list invOrderDetailForm as detail>
<tr id="tr_${(detail.skuId)!}" class="table-row-cell">
//                      <td><input id="gvDataList_CheckAll" type="checkbox" name="gvData"/></td>   
<td>${detail.seriesName}</td>
<td>${detail.productModel}</td>
<td>${detail.size}</td>
<td>${detail.material}</td>
<td>${detail.color}</td>
<td>${detail.structure}</td>
<td>${detail.suite1}</td>
<td>${detail.suite2}</td>
<td>
<input type="hidden" name="id" value="${(detail.id)!}"/>
<input type="hidden" id="skuId" name="skuId" value="${(detail.skuId)!}"/>
<input type="hidden" name="invId"
value="${invOrderModel.id}"/>
<input type="text" id="skuCode" name="skuCode" readonly
value="${(detail.skuCode)!}"/> </td>
<td>
<input type="hidden" id="factoryId" name="factoryId"
value="${(detail.factoryId)!}"/>
<input type="text" id="factoryName" name="factoryName" readonly
value="${(detail.factoryName)!}"/>
</td>
<td>
<input type="text" id="price_${(detail.skuId)}" name="price" readonly
value="${(detail.price)!}"/> </td>
<td>
<input type="text" id="stockNum" name="stockNum" readonly
value="${(detail.stockNum)!}" placeholder="库存量"/>
</td>
<td>
<input type="text" id="stockAmount" name="stockAmount" readonly
value="${(detail.stockAmount)!}" placeholder="总成本(元)"/>
</td>
<td>
<input type="text" id="lossNum" name="lossNum" readonly
value="${(detail.lossNum)!}" placeholder="报损量"/>
</td>
<td>
<input type="text" id="lossAmount" name="lossAmount" readonly
value="${(detail.lossAmount)!}" placeholder="总报损(元)"/>
</td>
<td>
<input type="text" id="invNum" name="invNum" class="form-control"
value="${(detail.invNum)!}" placeholder="盘点量"
onblur="numChange(this.value,'${(detail.skuId)}','#invAmount_${(detail.skuId)}_${(detail.factoryId)}')"/>
</td>
<td>
<input type="text" id="invAmount_${(detail.skuId)}_${(detail.factoryId)}"
style="width: 100px;"
name="invAmount"
readonly
value="${(detail.invAmount)}"/>
</td>
<td>
<input type="text" id="invLossNum"
name="invLossNum"
value="${(detail.invLossNum)}" class="form-control"
placeholder="盘点报损量"
onblur="numChange(this.value,'${(detail.skuId)}','#invLossAmount_${(detail.skuId)}_${(detail.factoryId)}')"/> </td>
<td>
<input type="text"
id="invLossAmount_${(detail.skuId)}_${(detail.factoryId)}"
name="invLossAmount" readonly style="width: 100px;"
value="${(detail.invLossAmount)}"
placeholder="盘点报损量金额"> </td>
<td>
<input type="text" id="remarks" class="form-control" style="width:200px;"
name="remarks"
placeholder="备注" value="${(detail.remarks)}">
</td>
<td><input type="button" onclick="$('#tr_${(detail.skuId)}').remove()"
value="删除"></td>
</tr>
</#list>
</tbody>
<tbody id="invOrderDetailList"> </tbody>
</table>
</form>
</div><!-- /.box-body -->
</div> <div class="form-group">
<label class="col-sm-4 control-label"> </label>
<div class="col-sm-6">
<input type="button" id="save_btn" onclick="save()" class="btn btn-primary" value="保存">
<input type="button" id="submitAudit_btn" onclick="submitAudit()" class="btn btn-primary"
value="提交审核">
<a class="btn btn-danger" href="/storage/invOrder/list/1"> 返回</a>
</div>
</div>
</div>
</div><!--/.col (left) -->
</div>
</section><!-- /.content -->
//表单封装json
function constructObjectFromTable(object, $object) {
var javaObjArray = []; $object.each(function(i) {
// var $ck = $(this).find('input[name^=gvdata]');
// if($ck.length != 0){
// if(!$ck.attr('checked')){
// return true;
// }
// }
var javaObj = {}; for (var p in object) {
var $val = $(this).find('input[name="'+p+'"]');
if ($val.length === 0) {
javaObj[p] = $(this).find('select[name="'+p+'"]').val();
} else {
javaObj[p] = $val.val();
}
} javaObjArray.push(javaObj);
}); return javaObjArray;
}
/**
* 保存/提交审核
*
* @param invOrderModelWrapper
* @return
*/
@RequestMapping(value = "/saveInvOrderModel")
@ResponseBody
public Map saveInvOrderModel(@RequestBody InvOrderModelWrapper invOrderModelWrapper) { boolean code = invOrderDetailModelService.saveInvOrderModelWrapper(invOrderModelWrapper);
Map returnMap = new HashMap();
returnMap.put("code", code);
return returnMap;
}
/**
* 保存头和明细/提交审核
*
* @param invOrderModelWrapper
*/
@Override
public boolean saveInvOrderModelWrapper(InvOrderModelWrapper invOrderModelWrapper) {
boolean retflag = false;
// 头信息
InvOrderModel invOrderModel = invOrderModelWrapper.getInvOrderModel();
Integer counts = invOrderModelMapper.searchCountInvOrder(invOrderModel.getId());
if (counts > 0) { // 表中已经存在,说明是 编辑
retflag = this.doEdit(invOrderModelWrapper);
} else { // 表中不存在,是新增
retflag = this.doSave(invOrderModelWrapper);
}
return retflag;
} importorg.codehaus.jackson.annotate.JsonIgnoreProperties; import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class InvOrderModelWrapper {
private InvOrderModel invOrderModel;
private List<InvOrderDetailModel> invOrderDetailModels; public InvOrderModel getInvOrderModel() {
return invOrderModel;
} public void setInvOrderModel(InvOrderModel invOrderModel) {
this.invOrderModel = invOrderModel;
} public List<InvOrderDetailModel> getInvOrderDetailModels() {
return invOrderDetailModels;
} public void setInvOrderDetailModels(List<InvOrderDetailModel> invOrderDetailModels) {
this.invOrderDetailModels = invOrderDetailModels;
}
}

<script src="/plugins/jQuery/serializeObject.js"></script>

/*
* .serializeObject (c) Dan Heberden
* danheberden.com
*
* Gives you a pretty object for your form elements
*/
(function ($) {
$.fn.serializeObject = function () {
if (!this.length) {
return false;
} var $el = this,
data = {},
lookup = data; //current reference of data $el.find(':input[type!="checkbox"][type!="radio"], input:checked').each(function () {
// data[a][b] becomes [ data, a, b ]
var named = this.name.replace(/([^]+)?\]/g, ',$1').split(','),
cap = named.length - 1,
i = 0; for (; i < cap; i++) {
// move down the tree - create objects or array if necessary
lookup = lookup[named[i]] = lookup[named[i]] ||
( named[i + 1] == "" ? [] : {} );
} // at the end, psuh or assign the value
if (lookup.length != undefined) {
lookup.push($(this).val());
} else {
lookup[named[cap]] = $(this).val();
} // assign the reference back to root
lookup = data;
}); return data;
};
})(jQuery);

  

 

serializeObject 的应用的更多相关文章

  1. 利用JsonConvert.SerializeObject()实现类对象的json化

    现阶段的项目是采用前后端分离的思想,前端使用的是Angular.JS,后端使用ABP框架,在后端我们通过WebAPI技术来向前端提供json数据.以前是通过MVC来写前端的代码,感觉后端有点在控制前端 ...

  2. 将复杂form表单序列化serialize-object.js

    <form class="form-horizontal" role="form" id="myform" action=" ...

  3. Newtonsoft.Json序列化和反序列之javascriptConvert.SerializeObject,DeserializeObject,JsonWriter,JsonReader

    这里下载:http://www.newtonsoft.com/products/json/安装:   1.解压下载文件,得到Newtonsoft.Json.dll   2.在项目中添加引用.. jav ...

  4. jQuery - 基于serializeArray的serializeObject

    将表单序列化成JSON对象,注意不管是自实现的serializeObject()还是原生的serializeArray(),所要序列化的控件都必须要有name,而不是id jQuery.prototy ...

  5. @Html.Raw() 与Newtonsoft.Json.JsonConvert.SerializeObject()

    一.后台 ViewBag.TypeList = typeList; 二.前台C# @{     var typeListFirst = ViewBag.TypeList;} 三.前台js中 var t ...

  6. 自定义$('#form').serialize() var params = $('#xxx_form').serializeObject();

    //注意:获取之前 $("#id").removeAttr("disabled"); $.fn.serializeObject = function () { ...

  7. JsonConvert.SerializeObject 空值处理

    var settings = new JsonSerializerSettings() { ContractResolver= new NullToEmptyStringResolver() }; v ...

  8. form表单序列化serialize-object.js

    <form class="form-horizontal" role="form" id="myform" action=" ...

  9. JsonConvert.SerializeObject() 输出josn格式 也就是序列化。

    JsonConvert.SerializeObject() 输出josn格式  也就是序列化. JSON.parse 反序列化  http://www.cnblogs.com/ahlx/p/52280 ...

  10. Json.net的常用语句JsonConvert.SerializeObject(对象)

    在ajax的已不请求中,常常返回json对象.可以利用json.net给我们提供的api达到快速开发. 例子: using System;using System.Collections;using ...

随机推荐

  1. JWT (JSON WEB Token)正确使用场景

    https://www.jianshu.com/p/af8360b83a9f 讲真,别再使用JWT了! ThoughtWorks中国 2017.08.16 08:51* 字数 2882 阅读 7154 ...

  2. Bootstrap 模态框 禁止点击空白关闭模态框事件

    在模态框的div中加上 aria-hidden="true" data-backdrop="static" <div class="modal ...

  3. 无法重启ssh

    rm /dev/null mknod /dev/null c 1 3 chmod 666 /dev/null

  4. 【Redis】DENIED Redis is running in protected mode

    .修改redis服务器的配置文件 vi redis.conf 注释以下绑定的主机地址 # bind 127.0.0.1 .修改redis服务器的参数配置 修改redis的守护进程为no ,不启用 &g ...

  5. 蓝牙nrf52832的架构和开发(转载)

    相比TI的CC254X.DIALOG的DA1458X,nordic推出的nrf51822和nrf52832在架构和开发商都有自己独特的地方.这几颗产品都是蓝牙低功耗芯片.DA1458X使用OTP硬件架 ...

  6. SQL_1_简介

    了解一门语言,还是应该从名字开始.SQL中的S即Structured(结构),L即Language(语言),Q即Query(查询),但不仅仅只是查询,还可以建立数据库,添加和删除数据,对数据作联合,当 ...

  7. strcpy和strncpy用法和区别

    1. strcpy函数:顾名思义字符串复制函数:原型:extern char *strcpy(char *dest,char *src); 功能:把从src地址开始且含有NULL结束符的字符串赋值到以 ...

  8. NAT(地址转换技术)详解(转载)

    作者:逃离地球的小小呆 来源:CSDN 原文:https://blog.csdn.net/gui951753/article/details/79593307版权声明:本文为博主原创文章,转载请附上博 ...

  9. Ubuntu下安装anaconda和pycharm

    折腾了一上午,终于装好了,如下:Python环境的安装: 安装anaconda 建议去https://www.anaconda.com/download/#linux直接用Ubuntu界面的搜狐浏览器 ...

  10. grunt-nodemon参数配置

    grunt-nodemon参数配置 nodemon0.2.0版本后参数名称做了较大改动,调整了下nodemon的参数配置,有需要的同学可以参考下: 1 2 3 4 5 6 7 8 9 10 11 12 ...