plussurplus.jsp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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">
  9. var mydata,operCount=0,lastrow,lastcell;
  10. $(document).ready( function() {
  11. loadList(); //加载jqgrid
  12. $("input.datebox").bind("click", function() {WdatePicker();});
  13. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  14. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  15. });
  16. $(window).resize(function(){
  17. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  18. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  19. });
  20. //jqgrid初始化
  21. function loadList(){
  22. jQuery("#list").jqGrid({
  23. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  24. height: "60%", //高度
  25. colNames:["主键","舍栏名称","转投补料量(kg)"], //列名
  26. colModel:[
  27. {name: "ID",index: "ID",width: 1,align: "center",sorttype: "string",hidden: true},
  28. {name: "BNAME",index: "BNAME",align: "center",sorttype: "String",editable: false},
  29. {name: "Plus",index: "Plus",align: "center",sorttype: "number",editable: true,editrules: {number: true},formatter:"number"}
  30. ],
  31. cellEdit: true,
  32. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  33. beforeEditCell:function(rowid,cellname,v,iRow,iCol){
  34. lastrow = iRow;
  35. lastcell = iCol;
  36. },
  37. rowNum: 1000, //每页显示条数
  38. /**
  39. * 设置水平滚动条 begin
  40. **/
  41. shrinkToFit:false,
  42. autoScroll: true,
  43. autowidth: true, //自动调节宽度
  44. /**
  45. * 设置水平滚动条 end
  46. **/
  47. altRows: true, //设置表格是否允许行交替变色值
  48. altclass:"tdbgmouseover", //自定义隔行变色的样式
  49. toolbar: [true,"top"],
  50. caption: "栏舍补料量" //标题
  51. });
  52. if(operCount == 0){
  53. $("#t_list").append("<input id='beginDate' name='beginDate' style='width:100px;font-size:12px;' class='datebox' value=''/>&nbsp;&nbsp;");
  54. $("#t_list").append("<input type='button' value='<' onclick='leftDate();' /><input type='button' value='>' onclick='rightDate();' />&nbsp;&nbsp;");
  55. $("#t_list").append("<input type='button' class='sysub' value='查询' onclick='queryDate()' />&nbsp;&nbsp;");
  56. $("#t_list").append("<input type='button' value='确认保存' onClick='saveLpplan()' class='sysub' /> ");
  57. operCount++;
  58. }
  59. //获取数据集
  60. mydata = getLists();
  61. if(mydata!=null){
  62. for(var i=0;i<=mydata.length;i++){
  63. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  64. }
  65. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  66. }
  67. }
  68. //获取服务器数据
  69. function getLists(){
  70. var beginDate = $("#beginDate").val();
  71. if(beginDate==""){
  72. setNowDate();
  73. beginDate = $("#beginDate").val();
  74. }
  75. $.ajax({
  76. async: false,
  77. type: 'POST',
  78. dataType:'json', //返回类型json
  79. url: "${contextPath }/admin/produce/plussurpluslist.html?beginDate="+beginDate,
  80. error: function(){alert("系统错误");},
  81. success: function(json){
  82. mydata = json;
  83. }
  84. });
  85. return mydata;
  86. }
  87. //确认保存
  88. function saveLpplan(){
  89. $("#list").jqGrid("saveCell",lastrow,lastcell);
  90. var beginDate = $("#beginDate").val();
  91. var milkStr = "";
  92. var ids = $("#list").jqGrid("getDataIDs");
  93. for ( var i = 0; i < ids.length; i++) {
  94. var rowData = $("#list").jqGrid("getRowData",ids[i]);
  95. var ID = rowData.ID;
  96. var BNAME = $.trim(rowData.BNAME);
  97. var Plus = rowData.Plus;
  98. if(milkStr == ""){
  99. milkStr = "ID:"+ID+",BNAME:"+BNAME+",Plus:"+Plus;
  100. }else{
  101. milkStr += ";" + "ID:"+ID+",BNAME:"+BNAME+",Plus:"+Plus;
  102. }
  103. }
  104. $.ajax({
  105. async: false,
  106. type: 'POST',
  107. data: "milkStr="+milkStr+"&beginDate="+beginDate,
  108. dataType: 'json',
  109. url: "${contextPath}/admin/produce/plussurplusupdate.html",
  110. error: function(){alert("系统错误");},
  111. success: function(json){
  112. if(json.status == "success"){
  113. $("#list").clearGridData(); //清空原grid数据
  114. loadList();
  115. }
  116. }
  117. });
  118. }
  119. //初始化日期
  120. function setNowDate(){
  121. var myDate = new Date();
  122. var year = myDate.getFullYear();
  123. var month = myDate.getMonth()+1;
  124. var day = myDate.getDate();
  125. var nowdate = year + "-" + month + "-" + day;
  126. $("#beginDate").val(nowdate);
  127. }
  128. //查询数据
  129. function queryDate(){
  130. //清空主表数据重新加载一次
  131. $("#list").clearGridData();
  132. loadList();
  133. }
  134. function leftDate(){
  135. var beginDate = $("#beginDate").val();
  136. var newbDate = checkDate(beginDate,"left");
  137. $("#beginDate").val(newbDate);
  138. queryDate();
  139. }
  140. function rightDate(){
  141. var beginDate = $("#beginDate").val();
  142. var newbDate = checkDate(beginDate,"");
  143. $("#beginDate").val(newbDate);
  144. queryDate();
  145. }
  146. </script>
  147. </head>
  148. <body>
  149. <div>
  150. <div class="navfrm">
  151. <span>当前位置:</span>
  152. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  153. <span>&nbsp;>>&nbsp;</span>
  154. <span>栏舍补料量</span>
  155. </div>
  156. <table id="list"></table>
  157. </div>
  158. </body>
  159. </html>