feedpackage.jsp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/themes/easyui.css" />
  8. <script type="text/javascript" src="${contextPath }/js/jquery.easyui.min.js"></script>
  9. <script type="text/javascript">
  10. var mydata,operType,panelCHeight=0,loadCount = 0;
  11. $(document).ready( function() {
  12. loadList(); //加载jqgrid
  13. panelC = $("body").layout("panel","center").panel();
  14. panelCHeight = panelC.height();
  15. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  16. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 30);
  17. $("body").layout("panel","south").panel({
  18. onClose: function(){
  19. panelC = $("body").layout("panel","center").panel();
  20. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  21. },
  22. onExpand: function(){
  23. panelS = $("body").layout("panel","south").panel();
  24. panelCHeight = document.body.clientHeight - panelS.height();
  25. $("#list").jqGrid("setGridHeight",panelCHeight-135);
  26. },
  27. onResize: function(){
  28. panelS = $("body").layout("panel","south").panel();
  29. panelCHeight = document.body.clientHeight - panelS.height();
  30. $("#list").jqGrid("setGridHeight",panelCHeight-135);
  31. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 30);
  32. $("#listFtdetail").jqGrid("setGridHeight",panelS.height()-75);
  33. $("#listFtdetail").jqGrid("setGridWidth",document.body.clientWidth - 30);
  34. }
  35. });
  36. });
  37. $(window).resize(function(){
  38. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 10);
  39. $("#listFtdetail").jqGrid("setGridWidth",document.body.clientWidth - 10);
  40. });
  41. //jqgrid初始化
  42. function loadList(){
  43. jQuery("#list").jqGrid({
  44. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  45. height: 170, //高度
  46. colNames:["主键","自配料名称","搅拌延时(分钟)","备注"], //列名
  47. colModel:[
  48. {
  49. name: "feedpackageId",
  50. index: "feedpackageId",
  51. align: "center",
  52. sorttype: "string",
  53. editable: true,
  54. hidden: true
  55. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  56. },
  57. {
  58. name: "feedpackageName",
  59. index: "feedpackageName",
  60. align: "center",
  61. sorttype: "string",
  62. editable: true,
  63. editrules:{
  64. required: true,
  65. custom: true,
  66. custom_func: checkName
  67. }
  68. },
  69. {
  70. name: "stirDelay",
  71. index: "stirDelay",
  72. align: "center",
  73. sorttype: "int",
  74. editable: true
  75. },
  76. {
  77. name: "Remark",
  78. index: "Remark",
  79. align: "center",
  80. sorttype: "int",
  81. editable: true
  82. }
  83. ],
  84. cellEdit: true,
  85. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  86. afterEditCell: function(rowid,name,val,iRow,iCol){
  87. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  88. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  89. $("#ftdetailResult").load("${contextPath }/admin/recipeplan/feedpackagedetail.html?currentTfId="+rowData.feedpackageId);
  90. },
  91. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  92. var rowData = $("#list").jqGrid("getRowData",rowid);
  93. $.ajax({
  94. async: false,
  95. type: "POST",
  96. dataType:"json", //返回类型jsond
  97. data: "ID="+rowData.feedpackageId+"&colName="+name+"&colValue="+val,
  98. url: "${contextPath }/admin/recipeplan/feedpackageupdatedyg.html",
  99. error: function(){alert("系统错误");},
  100. success: function(json){
  101. }
  102. });
  103. },
  104. pager: "#page", //#page分页控件绑定的位置对象
  105. pginput: false, //不显示分页文本框
  106. pgbuttons: false, //不显示翻页按钮
  107. rowNum: 1000, //每页显示条数
  108. viewrecords: true, //是否显示总条数
  109. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  110. autowidth: true, //自动调节宽度
  111. sortname: "SORT" //按SORT进行排序 默认asc
  112. });
  113. //获取数据集
  114. mydata = getLists();
  115. if(mydata!=null){
  116. for(var i=0;i<=mydata.length;i++){
  117. jQuery("#list").jqGrid("addRowData",i+1,mydata[i]);
  118. }
  119. //jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  120. }
  121. //绑定、设置工具栏
  122. jQuery("#list").jqGrid("navGrid","#page",{
  123. add: true, addtext: "添加",
  124. edit: false, edittext: "编辑",
  125. del: true, deltext: "删除",refresh: false,
  126. addfunc: addRow, //自定义添加方法
  127. delfunc: deleteRow, //自定义删除方法
  128. searchtext: "搜索",search: false,
  129. refreshtext: "刷新",
  130. alerttext:"请选择一条记录!"
  131. });
  132. }
  133. //获取服务器数据
  134. function getLists(){
  135. $.ajax({
  136. async: false,
  137. type: "POST",
  138. dataType:"json", //返回类型json
  139. url: "${contextPath }/admin/recipeplan/feedpackagelist.html",
  140. error: function(){alert("系统错误");},
  141. success: function(json){
  142. mydata = json;
  143. }
  144. });
  145. return mydata;
  146. }
  147. //自定义添加方法
  148. function addRow(){
  149. var ids = $("#list").jqGrid("getDataIDs");
  150. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  151. $.ajax({
  152. async: false,
  153. type: "POST",
  154. dataType:"json", //返回类型jsond
  155. data: "oper=add&selId=",
  156. url: "${contextPath }/admin/recipeplan/feedpackageupdate.html",
  157. error: function(){alert("系统错误");},
  158. success: function(json){
  159. $("#list").clearGridData(); //清空原grid数据
  160. loadList(); //重新载入服务器数据
  161. }
  162. });
  163. }
  164. //自定义删除方法
  165. function deleteRow(){
  166. var count = 0;
  167. var flag = confirm("您确定要删除吗?");
  168. if(flag){
  169. var row = $("#list").jqGrid("getGridParam","selrow");
  170. var selRow = $("#list").jqGrid("getRowData",row);
  171. $.ajax({
  172. async: false,
  173. type: "POST",
  174. dataType:"json", //返回类型jsond
  175. data: "selId="+selRow.feedpackageId,
  176. url: "${contextPath }/admin/recipeplan/queryfeedpackageyy.html",
  177. error: function(){alert("系统错误");},
  178. success: function(json){
  179. count = json.status;
  180. }
  181. });
  182. if(count == 0){
  183. $.ajax({
  184. async: false,
  185. type: "POST",
  186. dataType:"json", //返回类型jsond
  187. data: "oper=del&selId="+selRow.feedpackageId,
  188. url: "${contextPath }/admin/recipeplan/feedpackageupdate.html",
  189. error: function(){alert("系统错误");},
  190. success: function(json){
  191. $("#list").clearGridData(); //清空原grid数据
  192. window.location.reload();
  193. }
  194. });
  195. }else{
  196. alert("该记录被引用、不能删除!!!");
  197. }
  198. }
  199. }
  200. //自定义验证名称是否存在方法
  201. function checkName(value, colname){
  202. var flag = 0;
  203. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  204. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  205. $.ajax({
  206. async: false,
  207. type: "POST",
  208. data: "entityName="+value+"&entityId="+rowData.feedpackageId,
  209. dataType: "json",
  210. url: "${contextPath}/admin/recipeplan/feedpackagecheck.html",
  211. error: function(){alert("系统错误");},
  212. success: function(json){
  213. flag = json.status;
  214. }
  215. });
  216. if(flag == 0){
  217. return [true,""];
  218. }else{
  219. return [false,"自配料已经存在!"];
  220. }
  221. }
  222. </script>
  223. </head>
  224. <body class="easyui-layout">
  225. <div region="center" title="自配料" style="padding:5px;background:#eee;">
  226. <table id="list"></table>
  227. <div id="page"></div>
  228. <input type="hidden" />
  229. </div>
  230. <div region="south" split="true" title="饲料" style="padding:5px;height:230px;">
  231. <div id="ftdetailResult"></div>
  232. </div>
  233. </body>
  234. </html>