feed.jsp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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">
  8. var mydata,operType,loadCount = 0;
  9. $(document).ready( function() {
  10. loadList(); //加载jqgrid
  11. $("#list").jqGrid("setGridHeight",$(window).height() - 100);
  12. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  13. });
  14. $(window).resize(function(){
  15. $("#list").jqGrid("setGridHeight",$(window).height() - 100);
  16. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  17. });
  18. //jqgrid初始化
  19. function loadList(){
  20. jQuery("#list").jqGrid({
  21. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  22. height: "70%", //高度
  23. colNames:['主键','饲料名称','饲料分类', '打印组', '允许误差数(kg)', '包装单位重量', '单价(元)', '干物质(kg/kg)', '跳转重量域(公斤)', '跳转延时(秒)', '确认开始', '继电器位置', '顺序', '是否启用'], //列名
  24. colModel:[
  25. {
  26. name: "ID",
  27. index: "ID",
  28. align: "center",
  29. sorttype: "string",
  30. editable: true,
  31. hidden: true
  32. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  33. },
  34. {
  35. name: "FNAME",
  36. index: "FNAME",
  37. align: "center",
  38. sorttype: "string",
  39. editable: true,
  40. editrules:{
  41. required: true,
  42. custom: true,
  43. custom_func: checkName
  44. }
  45. },
  46. {
  47. name: "FCNAME",
  48. index: "FCNAME",
  49. align: "center",
  50. sorttype: "int",
  51. editable: true,
  52. edittype: "select",
  53. editoptions:{
  54. dataUrl: "${contextPath }/admin/basicdata/feedselect.html"
  55. }
  56. },
  57. {
  58. name: "PrintGroup",
  59. index: "PrintGroup",
  60. align: "center",
  61. sorttype: "string",
  62. editable: true,
  63. edittype:"select",
  64. editoptions:{value:{"无":"无","铲车":"铲车","精料":"精料"}}
  65. },
  66. {
  67. name: "AllowRatio",
  68. index: "AllowRatio",
  69. align: "center",
  70. sorttype: "number",
  71. editable: true,
  72. editrules: {required:true,number: true}
  73. },
  74. {
  75. name: "UnitWeight",
  76. index: "UnitWeight",
  77. align: "center",
  78. sorttype: "number",
  79. editable: true,
  80. editrules: {number: true}
  81. },
  82. {
  83. name: "Uprice",
  84. index: "Uprice",
  85. align: "center",
  86. sorttype: "number",
  87. editable: true,
  88. editrules: {number: true}
  89. },
  90. {
  91. name: "dry",
  92. index: "dry",
  93. align: "center",
  94. sorttype: "number",
  95. editable: true,
  96. editrules: {number: true}
  97. },
  98. {
  99. name: "autozone",
  100. index: "autozone",
  101. align: "center",
  102. sorttype: "number",
  103. editable: true,
  104. editrules: {number: true}
  105. },
  106. {
  107. name: "autosecond",
  108. index: "autosecond",
  109. align: "center",
  110. sorttype: "string",
  111. editable: true,
  112. edittype:"select",
  113. editoptions:{value:{"0":"禁用","1":"3秒","2":"6秒","3":"9秒"}}
  114. },
  115. {
  116. name: "NeedBegin",
  117. index: "NeedBegin",
  118. align: "center",
  119. sorttype: "string",
  120. editable: true,
  121. edittype:"select",
  122. editoptions:{value:{"0":"禁用","1":"启用"}}
  123. },
  124. {
  125. name: "TrgAddress",
  126. index: "TrgAddress",
  127. align: "center",
  128. sorttype: "int",
  129. editable: true,
  130. editrules:{
  131. required: true,
  132. integer: true
  133. }
  134. },
  135. {
  136. name: "SORT",
  137. index: "SORT",
  138. align: "center",
  139. sorttype: "int",
  140. editable: true,
  141. editrules:{
  142. required: true,
  143. integer: true
  144. }
  145. },
  146. {
  147. name: "ENABLE",
  148. index: "ENABLE",
  149. align: "center",
  150. sorttype: "string",
  151. editable: true,
  152. edittype: "select",
  153. editoptions: {value:{"Yes":"是","No":"否"}}
  154. }
  155. ],
  156. caption: "饲料管理", //标题
  157. cellEdit: true,
  158. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  159. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  160. var rowData = $("#list").jqGrid("getRowData",rowid);
  161. var id = rowData.ID;
  162. if(id==1000 && iCol==2){
  163. alert("该饲料名称不能修改");
  164. }else{
  165. $.ajax({
  166. async: false,
  167. type: 'POST',
  168. dataType:'json', //返回类型jsond
  169. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  170. url: "${contextPath }/admin/basicdata/feedupdatedyg.html",
  171. error: function(){alert("系统错误");},
  172. success: function(json){
  173. }
  174. });
  175. }
  176. },
  177. pager: "#page", //#page分页控件绑定的位置对象
  178. rowNum: 1000, //每页显示条数
  179. rowList: [100,200,300,400], //分页下拉选项内容
  180. rownumbers: true, //是否显示行数
  181. viewrecords: true, //是否显示总条数
  182. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  183. autowidth: true, //自动调节宽度
  184. sortname: 'SORT', //按SORT进行排序 默认asc
  185. altRows: true, //设置表格是否允许行交替变色值
  186. altclass:"tdbgmouseover" //自定义隔行变色的样式
  187. });
  188. //获取数据集
  189. mydata = getLists();
  190. if(mydata!=null){
  191. for(var i=0;i<=mydata.length;i++){
  192. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  193. }
  194. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  195. }
  196. //绑定、设置工具栏
  197. jQuery("#list").jqGrid("navGrid","#page",{
  198. add: true, addtext: "添加",
  199. edit: false, edittext: "编辑",
  200. del: true, deltext: "删除",refresh: false,
  201. addfunc: addRow, //自定义添加方法
  202. delfunc: deleteRow, //自定义删除方法
  203. searchtext: "搜索",
  204. refreshtext: "刷新",
  205. alerttext:"请选择一条记录!"
  206. });
  207. if(loadCount == 0){
  208. $("#list").navButtonAdd("#page",{
  209. caption:"批量修改配方模版饲料顺序",
  210. buttonicon:"ui-icon-document",
  211. position: "last",
  212. title:"批量修改配方模版饲料顺序",
  213. cursor: "pointer", //光标类型
  214. onClickButton: viewRow
  215. });
  216. }
  217. }
  218. //获取服务器数据
  219. function getLists(){
  220. $.ajax({
  221. async: false,
  222. type: 'POST',
  223. dataType:'json', //返回类型json
  224. url: "${contextPath }/admin/basicdata/feedlist.html",
  225. error: function(){alert("系统错误");},
  226. success: function(json){
  227. mydata = json;
  228. }
  229. });
  230. return mydata;
  231. }
  232. //自定义添加方法
  233. function addRow(){
  234. loadCount = 1;
  235. var ids = $("#list").jqGrid("getDataIDs");
  236. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  237. $.ajax({
  238. async: false,
  239. type: "POST",
  240. dataType:"json", //返回类型jsond
  241. data: "oper=add&selId=",
  242. url: "${contextPath }/admin/basicdata/feedupdate.html",
  243. error: function(){alert("系统错误");},
  244. success: function(json){
  245. $("#list").clearGridData(); //清空原grid数据
  246. loadList(); //重新载入服务器数据
  247. }
  248. });
  249. }
  250. //自定义删除方法
  251. function deleteRow(){
  252. loadCount = 1;
  253. var count = 0;
  254. var flag = confirm("您确定要删除吗?");
  255. if(flag){
  256. var row = $("#list").jqGrid("getGridParam","selrow");
  257. var selRow = $("#list").jqGrid("getRowData",row);
  258. var id = selRow.ID;
  259. if(id==1000){
  260. alert("该饲料不能删除");
  261. }else{
  262. $.ajax({
  263. async: false,
  264. type: "POST",
  265. dataType:"json", //返回类型jsond
  266. data: "selId="+selRow.ID,
  267. url: "${contextPath }/admin/basicdata/queryfeedglxx.html",
  268. error: function(){alert("系统错误");},
  269. success: function(json){
  270. count = json.status;
  271. }
  272. });
  273. if(count == 0){
  274. $.ajax({
  275. async: false,
  276. type: "POST",
  277. dataType:"json", //返回类型jsond
  278. data: "oper=del&selId="+selRow.ID,
  279. url: "${contextPath }/admin/basicdata/feedupdate.html",
  280. error: function(){alert("系统错误");},
  281. success: function(json){
  282. $("#list").clearGridData(); //清空原grid数据
  283. loadList(); //重新载入服务器数据
  284. }
  285. });
  286. }else{
  287. alert("该记录被引用、不能删除!!!");
  288. }
  289. }
  290. }
  291. }
  292. //自定义验证名称是否存在方法
  293. function checkName(value, colname){
  294. var flag = 0;
  295. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  296. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  297. $.ajax({
  298. async: false,
  299. type: 'POST',
  300. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  301. dataType: 'json',
  302. url: "${contextPath}/admin/basicdata/feedcheck.html",
  303. error: function(){alert("系统错误");},
  304. success: function(json){
  305. flag = json.status;
  306. }
  307. });
  308. if(flag == 0){
  309. return [true,""];
  310. }else{
  311. return [false,"饲料名称已经存在!"];
  312. }
  313. }
  314. //配方顺序
  315. function viewRow(){
  316. $.ajax({
  317. async: false,
  318. type: 'POST',
  319. dataType: 'json',
  320. url: "${contextPath}/admin/basicdata/checkFtdetailSort.html",
  321. error: function(){alert("系统错误");},
  322. success: function(json){
  323. if(json.status == "success"){
  324. alert("配方模版饲料顺序已经全部更新");
  325. }
  326. }
  327. });
  328. }
  329. </script>
  330. </head>
  331. <body style="background-color: #E0E0E0">
  332. <div>
  333. <div class="navfrm">
  334. <span>当前位置:</span>
  335. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  336. <span>&nbsp;>>&nbsp;</span>
  337. <span>饲料管理</span>
  338. </div>
  339. <table id="list"></table>
  340. <div id="page"></div>
  341. </div>
  342. </body>
  343. </html>