addFeedInventory.jsp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <%@ page contentType="text/html; charset=utf-8" session="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  4. <head>
  5. <title>我的工作台</title>
  6. <%@ include file="../common/header.jsp" %>
  7. <script type="text/javascript" src="${contextPath }/js/calendar/WdatePicker.js"></script>
  8. <script type="text/javascript" language="javascript" src="${contextPath}/js/highslide.js"></script>
  9. <script type="text/javascript">
  10. var mydata,operCount=0,curDate,lastrow,lastcell,invId='${map.invId}';
  11. $(document).ready( function() {
  12. $("input.datebox").bind("click", function() {WdatePicker({maxDate:'${maxDate}'});});
  13. if(invId!=null&&invId.length>0){
  14. loadList();
  15. }
  16. });
  17. $(window).resize(function(){
  18. $("#list").jqGrid("setGridHeight",$(window).height() - 130);
  19. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  20. });
  21. //保存盘点信息
  22. function saveFeedInventory(){
  23. var lpplanStr = "";
  24. $("#list").jqGrid("saveCell",lastrow,lastcell);
  25. var ids = $("#list").jqGrid("getDataIDs");
  26. for ( var i = 0; i < ids.length; i++) {
  27. var rowData = $("#list").jqGrid("getRowData",ids[i]);
  28. var feedid = $.trim(rowData.feedid);
  29. var theoryweight = $.trim(rowData.theoryweight);
  30. var factweight = $.trim(rowData.factweight);
  31. var g = /^-?\d+\.?\d{0,2}$/;
  32. if(factweight.length==0){
  33. alert("第"+(i+1)+"行,【实际重量】不能为空!");
  34. return false;
  35. }else if(!g.test(factweight)){
  36. alert("第"+(i+1)+"行,【实际重量】必须为数字,小数点不超过两位!");
  37. return false;
  38. }else if(factweight.indexOf("-")>-1){
  39. alert("第"+(i+1)+"行,【实际重量】不能为负数!");
  40. return false;
  41. }
  42. if(lpplanStr!=""){
  43. lpplanStr+=";";
  44. }
  45. lpplanStr+="feedid:"+feedid+",theoryweight:"+theoryweight+",factweight:"+factweight;
  46. }
  47. var createUser = $("#createUser").val();
  48. var remark = $("#remark").val();
  49. if(confirm("保存后不可修改,是否继续?")){
  50. $.ajax({
  51. async: false,
  52. type: "post",
  53. dataType:"json", //返回类型json
  54. data: "remark="+remark+"&inventoryDate="+curDate+"&createUser="+createUser+"&lpplanStr="+lpplanStr,
  55. url: "${contextPath }/admin/feedstorage/saveFeedInventory.html",
  56. error: function(){alert("系统错误");},
  57. success: function(json){
  58. if(json.status == "success"){
  59. parent.hsClose();
  60. }
  61. }
  62. });
  63. }
  64. }
  65. //jqgrid初始化
  66. function loadList(){
  67. jQuery("#list").jqGrid("clearGridData");
  68. var flag=true;
  69. if(invId!=null&&invId.length>0){
  70. flag=false;
  71. $("#loadListBtn").hide();
  72. }
  73. jQuery("#list").jqGrid({
  74. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  75. height: "50%", //高度
  76. colNames:["饲料主键","饲料名称","库存重量","实际重量"], //列名
  77. colModel:[
  78. {name: "feedid",index: "feedid",width: 100,align: "center",sortable:false,hidden:true},
  79. {name: "FNAME",index: "FNAME",width: 100,align: "center",sortable:false,editable: false},
  80. {name: "theoryweight",index: "theoryweight",width: 100,align: "center",sortable:false,editable: false},
  81. {name: "factweight",index: "factweight",width: 100,align: "center",sortable:false,editable: flag}
  82. ],
  83. cellEdit: true,
  84. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  85. /**
  86. * 设置水平滚动条 begin
  87. **/
  88. shrinkToFit:false,
  89. autoScroll: true,
  90. autowidth: true, //自动调节宽度
  91. rowNum: 1000, //每页显示条数
  92. /**
  93. * 设置水平滚动条 end
  94. **/
  95. toolbar: [true,"top"],
  96. beforeEditCell:function(rowid,cellname,v,iRow,iCol){
  97. lastrow = iRow;
  98. lastcell = iCol;
  99. },
  100. //单选行时触发
  101. onCellSelect: function(rowid,iCol,cellcontent,e){
  102. },
  103. //双击指标单元格时触发弹出层、让用户选择指标
  104. ondblClickRow: function(rowid,iRow,iCol,e){
  105. }
  106. });
  107. //$("#list").jqGrid("setFrozenColumns"); //设置冻结列
  108. //获取数据集
  109. mydata = getLists();
  110. if(mydata!=null){
  111. for(var i=0;i<=mydata.length;i++){
  112. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  113. }
  114. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  115. if(operCount == 0){
  116. var table="<table><tr><td>盘点日期:</td><td>"+curDate+"</td><td>盘点人:</td><td><input id=\"createUser\" name=\"createUser\" style=\"width:100px;\" value='${map.createUser}'/></td></tr><tr><td>备注:</td><td><input id=\"remark\" name=\"remark\" style=\"width:150px;\" value='${map.remark}'/></td><td colspan='2'><input id='saveFeedInventoryBtn' class='sysub' type='button' value='保存所有信息' onClick='saveFeedInventory()' style='font-size:-2'/></td></tr></table>"
  117. $("#t_list").append(table);
  118. operCount++;
  119. }
  120. }
  121. $("#list").jqGrid("setGridHeight",$(window).height() - 135);
  122. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  123. if(invId!=null&&invId.length>0){
  124. $("#createUser").attr("readonly",true);
  125. $("#remark").attr("readonly",true);
  126. $("#saveFeedInventoryBtn").hide();
  127. }
  128. }
  129. //获取服务器数据
  130. function getLists(){
  131. var inventoryDate=$("#inventoryDate").val();
  132. curDate=inventoryDate;
  133. if(curDate.length==0){
  134. alert("请选择盘点日期");
  135. return;
  136. }
  137. $.ajax({
  138. async: false,
  139. type: 'POST',
  140. dataType:'json', //返回类型json
  141. data: "inventoryDate="+inventoryDate+"&invId="+invId,
  142. url: "${contextPath }/admin/feedstorage/feedInventoryDetailsList.html",
  143. error: function(){alert("系统错误");},
  144. success: function(json){
  145. if(json.status == "success"){
  146. mydata= json.list;
  147. }else if(json.status=="countError"){
  148. alert("盘点日期之前已存在盘点记录或者日期不能小于已盘点记录!");
  149. mydata= null;
  150. }
  151. }
  152. });
  153. return mydata;
  154. }
  155. function hsClose(){
  156. closeBox();
  157. alert("保存成功");
  158. }
  159. hs.Expander.prototype.onAfterClose = function(htmlExpand) {
  160. //window.location.reload();
  161. };
  162. </script>
  163. <body style="background-color: #E0E0E0">
  164. <div>
  165. <table align="center">
  166. <tr id="loadListBtn">
  167. <td>盘点日期:</td>
  168. <td><input id="inventoryDate" name="inventoryDate" readonly="readonly" style="width:100px;" class="datebox" value="${map.inventoryDate}"/></td>
  169. <td><input type="button" value="预览盘点单" onclick="loadList()" class="sysub" /></td>
  170. </tr>
  171. </table>
  172. <table id="list"></table>
  173. <div id="page" style="height:30px;"></div>
  174. </div>
  175. </body>
  176. </html>