producelpplan.jsp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. <link type="text/css" rel="stylesheet" href="${contextPath}/css/style.css" />
  8. <script type="text/javascript" src="${contextPath }/js/calendar/WdatePicker.js"></script>
  9. <script type="text/javascript">
  10. var mydata,operCount=0,lastrow,lastcell;
  11. $(document).ready( function() {
  12. loadList(); //加载jqgrid
  13. $("input.datebox").bind("click", function() {WdatePicker();});
  14. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  15. });
  16. $(window).resize(function(){
  17. });
  18. //jqgrid初始化
  19. function loadList(){
  20. jQuery("#list").jqGrid({
  21. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  22. height: "50%", //高度
  23. colNames:["主键","车次","TMR","配方模板","描述","总量","每车重量"], //列名
  24. colModel:[
  25. {name: "ID",index: "ID",width: 1,align: "center",sorttype: "string",hidden: true},
  26. {name: "SORT",index: "SORT",width: 50,align: "center",sorttype: "int",editable: true,editrules: {integer: true}},
  27. {name: "tmrId",index: "tmrId",width: 70,align: "center",sorttype: "int",editable: true,edittype: "select",
  28. editoptions:{
  29. dataUrl: "${contextPath }/admin/recipeplan/tmrselect.html"
  30. }
  31. },
  32. {name: "feedtempletId",index: "feedtempletId",width: 70,align: "center",sorttype: "int",editable: true,edittype: "select",
  33. editoptions:{
  34. dataUrl: "${contextPath }/admin/recipeplan/plpplanselect.html"
  35. }
  36. },
  37. {name: "remark",index: "remark",width: 70,align: "center",sorttype: "string",editable: true},
  38. {name: "sumWeight",index: "sumWeight",width: 70,align: "center",sorttype: "string",editable: true,editrules: {number: true}},
  39. {name: "sortWeight",index: "sortWeight",width: 70,align: "center",sorttype: "string",editable: true,editrules: {number: true}}
  40. ],
  41. cellEdit: true,
  42. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  43. autowidth: true, //自动调节宽度
  44. rowNum: 1000, //每页显示条数
  45. /**
  46. * 设置水平滚动条 end
  47. **/
  48. toolbar: [true,"top"],
  49. beforeEditCell:function(rowid,cellname,v,iRow,iCol){
  50. lastrow = iRow;
  51. lastcell = iCol;
  52. }
  53. });
  54. if(operCount == 0){
  55. $("#t_list").append("<input id='beginDate' name='beginDate' style='width:100px;font-size:12px;' class='datebox' value=''/>&nbsp;&nbsp;");
  56. $("#t_list").append("<input type='button' value='<' onclick='leftDate();' /><input type='button' value='>' onclick='rightDate();' />&nbsp;&nbsp;");
  57. $("#t_list").append("<input class='sysub' type='button' value='新增车次' onClick='addLpplan()' style='font-size:-2'/> ");
  58. $("#t_list").append("<input class='sysub' type='button' value='删除车次' onClick='delLpplan()' style='font-size:-2'/> ");
  59. $("#t_list").append("<input class='sysub' type='button' value='确认保存' onClick='saveLpplan()' style='font-size:-2'/>");
  60. operCount++;
  61. }
  62. //获取数据集
  63. mydata = getLists();
  64. if(mydata!=null){
  65. for(var i=0;i<=mydata.length;i++){
  66. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  67. }
  68. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  69. }
  70. }
  71. //获取服务器数据
  72. function getLists(){
  73. var beginDate = $("#beginDate").val();
  74. if(beginDate==""){
  75. setNowDate();
  76. beginDate = $("#beginDate").val();
  77. }
  78. $.ajax({
  79. async: false,
  80. type: 'POST',
  81. dataType:'json', //返回类型json
  82. url: "${contextPath }/admin/recipeplan/plpplanlist.html?beginDate="+beginDate,
  83. error: function(){alert("系统错误");},
  84. success: function(json){
  85. mydata = json;
  86. }
  87. });
  88. return mydata;
  89. }
  90. //自定义添加方法
  91. function addLpplan(){
  92. var beginDate = $("#beginDate").val();
  93. var ids = $("#list").jqGrid("getDataIDs");
  94. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  95. $.ajax({
  96. async: false,
  97. type: "POST",
  98. dataType:"json", //返回类型jsond
  99. data: "oper=add&selId=&beginDate="+beginDate,
  100. url: "${contextPath }/admin/recipeplan/plupdate.html",
  101. error: function(){alert("系统错误");},
  102. success: function(json){
  103. $("#list").clearGridData(); //清空原grid数据
  104. loadList(); //重新载入服务器数据
  105. }
  106. });
  107. }
  108. //自定义删除方法
  109. function delLpplan(){
  110. var beginDate = $("#beginDate").val();
  111. var row = $("#list").jqGrid("getGridParam","selrow");
  112. if(row!=null){
  113. var flag = confirm("您确定要删除吗?");
  114. if(flag){
  115. var selRow = $("#list").jqGrid("getRowData",row);
  116. $.ajax({
  117. async: false,
  118. type: "POST",
  119. dataType:"json", //返回类型jsond
  120. data: "oper=del&selId="+selRow.ID+"&beginDate="+beginDate,
  121. url: "${contextPath }/admin/recipeplan/plupdate.html",
  122. error: function(){alert("系统错误");},
  123. success: function(json){
  124. $("#list").clearGridData(); //清空原grid数据
  125. loadList(); //重新载入服务器数据
  126. }
  127. });
  128. }
  129. }else{
  130. alert("请选择记录");
  131. }
  132. }
  133. //确认保存
  134. function saveLpplan(){
  135. $("#list").jqGrid("saveCell",lastrow,lastcell);
  136. //编辑后按过回车状态、可以保存
  137. var beginDate = $("#beginDate").val();
  138. var lpplanStr = "";
  139. var ids = $("#list").jqGrid("getDataIDs");
  140. for ( var i = 0; i < ids.length; i++) {
  141. var rowData = $("#list").jqGrid("getRowData",ids[i]);
  142. var ID = rowData.ID;
  143. var tmrId = $.trim(rowData.tmrId);
  144. var feedtempletId = $.trim(rowData.feedtempletId);
  145. var remark = rowData.remark;
  146. var SORT = rowData.SORT;
  147. var sumWeight = rowData.sumWeight;
  148. var sortWeight = rowData.sortWeight;
  149. if(lpplanStr == ""){
  150. lpplanStr = "ID:"+ID+",tmrId:"+tmrId+",SORT:"+SORT+",feedtempletId:"+feedtempletId+",remark:"+remark+",sumWeight:"+sumWeight+",sortWeight:"+sortWeight;
  151. }else{
  152. lpplanStr += ";" + "ID:"+ID+",tmrId:"+tmrId+",SORT:"+SORT+",feedtempletId:"+feedtempletId+",remark:"+remark+",sumWeight:"+sumWeight+",sortWeight:"+sortWeight;
  153. }
  154. }
  155. $.ajax({
  156. async: false,
  157. type: 'POST',
  158. data: "lpplanStr="+lpplanStr+"&beginDate="+beginDate,
  159. dataType: 'json',
  160. url: "${contextPath}/admin/recipeplan/updateallProduce.html",
  161. error: function(){alert("系统错误");},
  162. success: function(json){
  163. if(json.status == "success"){
  164. $("#list").clearGridData(); //清空原grid数据
  165. //window.location.reload();
  166. loadList();
  167. }
  168. }
  169. });
  170. }
  171. //初始化日期
  172. function setNowDate(){
  173. var myDate = new Date();
  174. var year = myDate.getFullYear();
  175. var month = myDate.getMonth()+1;
  176. var day = myDate.getDate();
  177. var nowdate = year + "-" + month + "-" + day;
  178. $("#beginDate").val(nowdate);
  179. }
  180. //查询数据
  181. function queryDate(){
  182. //清空主表数据重新加载一次
  183. $("#list").clearGridData();
  184. loadList();
  185. }
  186. function leftDate(){
  187. var beginDate = $("#beginDate").val();
  188. var newbDate = checkDate(beginDate,"left");
  189. $("#beginDate").val(newbDate);
  190. queryDate();
  191. }
  192. function rightDate(){
  193. var beginDate = $("#beginDate").val();
  194. var newbDate = checkDate(beginDate,"");
  195. $("#beginDate").val(newbDate);
  196. queryDate();
  197. }
  198. </script>
  199. </head>
  200. <body style="background-color: #E0E0E0">
  201. <div>
  202. <table id="list"></table>
  203. </div>
  204. </body>
  205. </html>