templetdry.jsp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/Kg)","价格(元/Kg鲜样)"], //列名
  26. colModel:[
  27. {name: "ID",index: "ID",width: 1,align: "center",sorttype: "string",hidden: true},
  28. {name: "TNAME",index: "TNAME",align: "center",sorttype: "String",editable: false},
  29. {name: "tdry",index: "tdry",align: "center",sorttype: "number",editable: true,editrules: {number: true},formatter:"number"},
  30. {name: "tprice",index: "tprice",align: "center",sorttype: "number",editable: true,editrules: {number: true},formatter:"number"}
  31. ],
  32. cellEdit: true,
  33. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  34. beforeEditCell:function(rowid,cellname,v,iRow,iCol){
  35. lastrow = iRow;
  36. lastcell = iCol;
  37. },
  38. rowNum: 1000, //每页显示条数
  39. /**
  40. * 设置水平滚动条 begin
  41. **/
  42. shrinkToFit:false,
  43. autoScroll: true,
  44. autowidth: true, //自动调节宽度
  45. /**
  46. * 设置水平滚动条 end
  47. **/
  48. altRows: true, //设置表格是否允许行交替变色值
  49. altclass:"tdbgmouseover", //自定义隔行变色的样式
  50. toolbar: [true,"top"],
  51. caption: "配方干物质" //标题
  52. });
  53. if(operCount == 0){
  54. $("#t_list").append("<input id='beginDate' name='beginDate' style='width:100px;font-size:12px;' class='datebox' value=''/>&nbsp;&nbsp;");
  55. $("#t_list").append("<input type='button' value='<' onclick='leftDate();' /><input type='button' value='>' onclick='rightDate();' />&nbsp;&nbsp;");
  56. $("#t_list").append("<input type='button' class='sysub' value='查询' onclick='queryDate()' />&nbsp;&nbsp;");
  57. $("#t_list").append("<input type='button' value='确认保存' onClick='saveLpplan()' class='sysub' /> ");
  58. $("#t_list").append("<input type='button' value='自动生成' onClick='createDate(0)' class='sysub' /> ");
  59. $("#t_list").append("<input type='button' value='复制上次' onClick='createDate(1)' class='sysub' /> ");
  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/produce/templetdrylist.html?beginDate="+beginDate,
  83. error: function(){alert("系统错误");},
  84. success: function(json){
  85. mydata = json;
  86. }
  87. });
  88. return mydata;
  89. }
  90. //确认保存
  91. function saveLpplan(){
  92. $("#list").jqGrid("saveCell",lastrow,lastcell);
  93. var beginDate = $("#beginDate").val();
  94. var milkStr = "";
  95. var ids = $("#list").jqGrid("getDataIDs");
  96. for ( var i = 0; i < ids.length; i++) {
  97. var rowData = $("#list").jqGrid("getRowData",ids[i]);
  98. var ID = rowData.ID;
  99. var TNAME = $.trim(rowData.TNAME);
  100. var tdry = rowData.tdry;
  101. var tprice = rowData.tprice;
  102. if(milkStr == ""){
  103. milkStr = "ID:"+ID+",TNAME:"+TNAME+",tdry:"+tdry+",tprice:"+tprice;
  104. }else{
  105. milkStr += ";" + "ID:"+ID+",TNAME:"+TNAME+",tdry:"+tdry+",tprice:"+tprice;
  106. }
  107. }
  108. $.ajax({
  109. async: false,
  110. type: 'POST',
  111. data: "milkStr="+milkStr+"&beginDate="+beginDate,
  112. dataType: 'json',
  113. url: "${contextPath}/admin/produce/templetdryallupdate.html",
  114. error: function(){alert("系统错误");},
  115. success: function(json){
  116. if(json.status == "success"){
  117. $("#list").clearGridData(); //清空原grid数据
  118. loadList();
  119. }
  120. }
  121. });
  122. }
  123. //初始化日期
  124. function setNowDate(){
  125. var myDate = new Date();
  126. var year = myDate.getFullYear();
  127. var month = myDate.getMonth()+1;
  128. var day = myDate.getDate();
  129. var nowdate = year + "-" + month + "-" + day;
  130. $("#beginDate").val(nowdate);
  131. }
  132. //查询数据
  133. function queryDate(){
  134. //清空主表数据重新加载一次
  135. $("#list").clearGridData();
  136. loadList();
  137. }
  138. function leftDate(){
  139. var beginDate = $("#beginDate").val();
  140. var newbDate = checkDate(beginDate,"left");
  141. $("#beginDate").val(newbDate);
  142. queryDate();
  143. }
  144. function rightDate(){
  145. var beginDate = $("#beginDate").val();
  146. var newbDate = checkDate(beginDate,"");
  147. $("#beginDate").val(newbDate);
  148. queryDate();
  149. }
  150. //自动生成0、复制上次1
  151. function createDate(type){
  152. var beginDate = $("#beginDate").val();
  153. $.ajax({
  154. async: false,
  155. type: 'POST',
  156. data: "type="+type+"&beginDate="+beginDate,
  157. dataType: 'json',
  158. url: "${contextPath}/admin/produce/createDate.html",
  159. error: function(){alert("系统错误");},
  160. success: function(json){
  161. if(json.status == "success"){
  162. $("#list").clearGridData(); //清空原grid数据
  163. loadList();
  164. }
  165. }
  166. });
  167. }
  168. </script>
  169. </head>
  170. <body>
  171. <div>
  172. <div class="navfrm">
  173. <span>当前位置:</span>
  174. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  175. <span>&nbsp;>>&nbsp;</span>
  176. <span>配方干物质</span>
  177. </div>
  178. <table id="list"></table>
  179. </div>
  180. </body>
  181. </html>