surplus.jsp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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)","转投舍栏ID","转投舍栏"], //列名
  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: "Remain",index: "Remain",align: "center",sorttype: "number",editable: true,editrules: {number: true},formatter:"number"},
  30. {name: "ztFeedpId",index: "ztFeedpId",width: 1,align: "center",sorttype: "string",hidden: true},
  31. {
  32. name: "ztFeedpName",
  33. index: "ztFeedpName",
  34. align: "center",
  35. sorttype: "int",
  36. editable: true,
  37. edittype: "select",
  38. editoptions:{
  39. dataUrl: "${contextPath }/admin/produce/produceselect.html",
  40. dataEvents: [{
  41. type: 'change', //下拉选择的时候
  42. fn: function(e){
  43. var currentValue = this.value;
  44. var ztFeedpId = currentValue.substring(0,currentValue.indexOf(","));
  45. var row = $("#list").jqGrid("getGridParam","selrow");
  46. if(ztFeedpId == ""){
  47. $("#list").setCell(row,"ztFeedpId",null);
  48. }else{
  49. $("#list").setCell(row,"ztFeedpId",ztFeedpId);
  50. }
  51. }
  52. }]
  53. }
  54. }
  55. ],
  56. cellEdit: true,
  57. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  58. beforeEditCell:function(rowid,cellname,v,iRow,iCol){
  59. lastrow = iRow;
  60. lastcell = iCol;
  61. },
  62. rowNum: 1000, //每页显示条数
  63. /**
  64. * 设置水平滚动条 begin
  65. **/
  66. shrinkToFit:false,
  67. autoScroll: true,
  68. autowidth: true, //自动调节宽度
  69. /**
  70. * 设置水平滚动条 end
  71. **/
  72. altRows: true, //设置表格是否允许行交替变色值
  73. altclass:"tdbgmouseover", //自定义隔行变色的样式
  74. toolbar: [true,"top"],
  75. caption: "栏舍剩料量" //标题
  76. });
  77. if(operCount == 0){
  78. $("#t_list").append("<input id='beginDate' name='beginDate' style='width:100px;font-size:12px;' class='datebox' value=''/>&nbsp;&nbsp;");
  79. $("#t_list").append("<input type='button' value='<' onclick='leftDate();' /><input type='button' value='>' onclick='rightDate();' />&nbsp;&nbsp;");
  80. $("#t_list").append("<input type='button' class='sysub' value='查询' onclick='queryDate()' />&nbsp;&nbsp;");
  81. $("#t_list").append("<input type='button' value='确认保存' onClick='saveLpplan()' class='sysub' /> ");
  82. operCount++;
  83. }
  84. //获取数据集
  85. mydata = getLists();
  86. if(mydata!=null){
  87. for(var i=0;i<=mydata.length;i++){
  88. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  89. }
  90. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  91. }
  92. }
  93. //获取服务器数据
  94. function getLists(){
  95. var beginDate = $("#beginDate").val();
  96. if(beginDate==""){
  97. setNowDate();
  98. beginDate = $("#beginDate").val();
  99. }
  100. $.ajax({
  101. async: false,
  102. type: 'POST',
  103. dataType:'json', //返回类型json
  104. url: "${contextPath }/admin/produce/surpluslist.html?beginDate="+beginDate,
  105. error: function(){alert("系统错误");},
  106. success: function(json){
  107. mydata = json;
  108. }
  109. });
  110. return mydata;
  111. }
  112. //确认保存
  113. function saveLpplan(){
  114. $("#list").jqGrid("saveCell",lastrow,lastcell);
  115. var beginDate = $("#beginDate").val();
  116. var milkStr = "";
  117. var ids = $("#list").jqGrid("getDataIDs");
  118. for ( var i = 0; i < ids.length; i++) {
  119. var rowData = $("#list").jqGrid("getRowData",ids[i]);
  120. var ID = rowData.ID;
  121. var BNAME = $.trim(rowData.BNAME);
  122. var Remain = rowData.Remain;
  123. var ztFeedpId = rowData.ztFeedpId;
  124. var ztFeedpName = rowData.ztFeedpName;
  125. if(milkStr == ""){
  126. milkStr = "ID:"+ID+",BNAME:"+BNAME+",Remain:"+Remain+",ztFeedpId:"+ztFeedpId+",ztFeedpName:"+ztFeedpName;
  127. }else{
  128. milkStr += ";" + "ID:"+ID+",BNAME:"+BNAME+",Remain:"+Remain+",ztFeedpId:"+ztFeedpId+",ztFeedpName:"+ztFeedpName;
  129. }
  130. }
  131. $.ajax({
  132. async: false,
  133. type: 'POST',
  134. data: "milkStr="+milkStr+"&beginDate="+beginDate,
  135. dataType: 'json',
  136. url: "${contextPath}/admin/produce/surplusallupdate.html",
  137. error: function(){alert("系统错误");},
  138. success: function(json){
  139. if(json.status == "success"){
  140. $("#list").clearGridData(); //清空原grid数据
  141. loadList();
  142. }
  143. }
  144. });
  145. }
  146. //初始化日期
  147. function setNowDate(){
  148. var myDate = new Date();
  149. var year = myDate.getFullYear();
  150. var month = myDate.getMonth()+1;
  151. var day = myDate.getDate();
  152. var nowdate = year + "-" + month + "-" + day;
  153. $("#beginDate").val(nowdate);
  154. }
  155. //查询数据
  156. function queryDate(){
  157. //清空主表数据重新加载一次
  158. $("#list").clearGridData();
  159. loadList();
  160. }
  161. function leftDate(){
  162. var beginDate = $("#beginDate").val();
  163. var newbDate = checkDate(beginDate,"left");
  164. $("#beginDate").val(newbDate);
  165. queryDate();
  166. }
  167. function rightDate(){
  168. var beginDate = $("#beginDate").val();
  169. var newbDate = checkDate(beginDate,"");
  170. $("#beginDate").val(newbDate);
  171. queryDate();
  172. }
  173. </script>
  174. </head>
  175. <body>
  176. <div>
  177. <div class="navfrm">
  178. <span>当前位置:</span>
  179. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  180. <span>&nbsp;>>&nbsp;</span>
  181. <span>栏舍剩料量</span>
  182. </div>
  183. <table id="list"></table>
  184. </div>
  185. </body>
  186. </html>