bar.jsp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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,selId = 0,loadCount = 0,loadType=1;
  9. $(document).ready( function() {
  10. loadList(); //加载jqgrid
  11. $("#list").jqGrid("setGridHeight",$(window).height() - 87);
  12. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  13. });
  14. $(window).resize(function(){
  15. $("#list").jqGrid("setGridHeight",$(window).height() - 87);
  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)','跳转重量域(公斤)','跳转延时(秒)', '顺序', '是否启用'], //列名
  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: "BNAME",
  36. index: "BNAME",
  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: "BCode",
  48. index: "BCode",
  49. align: "center",
  50. sorttype: "string",
  51. editable: true,
  52. editrules:{
  53. required: true
  54. }
  55. },
  56. {
  57. name: "AllowRatio",
  58. index: "AllowRatio",
  59. align: "center",
  60. sorttype: "number",
  61. editable: true,
  62. editrules: {number: true}
  63. },
  64. {
  65. name: "autozone",
  66. index: "autozone",
  67. align: "center",
  68. sorttype: "number",
  69. editable: true,
  70. editrules: {number: true}
  71. },
  72. {
  73. name: "autosecond",
  74. index: "autosecond",
  75. align: "center",
  76. sorttype: "string",
  77. editable: true,
  78. edittype:"select",
  79. editoptions:{value:{"0":"禁用","1":"3秒","2":"6秒","3":"9秒"}}
  80. },
  81. {
  82. name: "SORT",
  83. index: "SORT",
  84. align: "center",
  85. sorttype: "int",
  86. editable: true,
  87. editrules:{
  88. required: true,
  89. integer: true
  90. }
  91. },
  92. {
  93. name: "ENABLE",
  94. index: "ENABLE",
  95. align: "center",
  96. sorttype: "string",
  97. editable: true,
  98. edittype: "select",
  99. editoptions: {value:{"Yes":"是","No":"否"}}
  100. }
  101. ],
  102. caption: "舍组栏管理", //标题
  103. cellEdit: true,
  104. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  105. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  106. var rowData = $("#list").jqGrid("getRowData",rowid);
  107. $.ajax({
  108. async: false,
  109. type: 'POST',
  110. dataType:'json', //返回类型jsond
  111. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  112. url: "${contextPath }/admin/basicdata/barupdatedyg.html",
  113. error: function(){alert("系统错误");},
  114. success: function(json){
  115. $("#list").clearGridData(); //清空原grid数据
  116. loadList(); //重新载入服务器数据
  117. }
  118. });
  119. },
  120. pager: "#page", //#page分页控件绑定的位置对象
  121. rowNum: 1000, //每页显示条数
  122. rowList: [100,200,300,400], //分页下拉选项内容
  123. rownumbers: true, //是否显示行数
  124. viewrecords: true, //是否显示总条数
  125. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  126. autowidth: true //自动调节宽度
  127. });
  128. //获取数据集
  129. mydata = getLists();
  130. if(mydata!=null){
  131. for(var i=0;i<=mydata.length;i++){
  132. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  133. }
  134. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  135. }
  136. //绑定、设置工具栏
  137. jQuery("#list").jqGrid("navGrid","#page",{
  138. add: true, addtext: "添加",
  139. edit: false, edittext: "编辑",
  140. del: true, deltext: "删除",refresh: false,
  141. addfunc: addRow, //自定义添加方法
  142. delfunc: deleteRow, //自定义删除方法
  143. searchtext: "搜索",
  144. refreshtext: "刷新",
  145. alerttext:"请选择一条记录!"
  146. });
  147. if(selId > 0){
  148. $("#list").jqGrid("setSelection",selId);
  149. }
  150. if(loadCount == 0){
  151. $("#list").navButtonAdd("#page",{
  152. caption:"显示启用",
  153. buttonicon:"ui-icon-document",
  154. position: "last",
  155. title:"显示启用",
  156. cursor: "pointer", //光标类型
  157. onClickButton: showUse
  158. });
  159. $("#list").navButtonAdd("#page",{
  160. caption:"显示禁用",
  161. buttonicon:"ui-icon-document",
  162. position: "last",
  163. title:"显示禁用",
  164. cursor: "pointer", //光标类型
  165. onClickButton: showBan
  166. });
  167. $("#list").navButtonAdd("#page",{
  168. caption:"显示全部",
  169. buttonicon:"ui-icon-document",
  170. position: "last",
  171. title:"显示全部",
  172. cursor: "pointer", //光标类型
  173. onClickButton: showAll
  174. });
  175. loadCount++;
  176. }
  177. }
  178. //获取服务器数据
  179. function getLists(){
  180. var loadurl;
  181. if(loadType==1){
  182. loadurl="${contextPath }/admin/basicdata/barlistUse.html";
  183. }
  184. else if(loadType==2){
  185. loadurl="${contextPath }/admin/basicdata/barlistBan.html";
  186. }
  187. else if(loadType==3){
  188. loadurl="${contextPath }/admin/basicdata/barlist.html";
  189. }
  190. $.ajax({
  191. async: false,
  192. type: 'POST',
  193. dataType:'json', //返回类型json
  194. url: loadurl,
  195. error: function(json){alert("系统错误");},
  196. success: function(json){
  197. mydata = json;
  198. }
  199. });
  200. return mydata;
  201. }
  202. //自定义添加方法
  203. function addRow(){
  204. var ids = $("#list").jqGrid("getDataIDs");
  205. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  206. $.ajax({
  207. async: false,
  208. type: "POST",
  209. dataType:"json", //返回类型jsond
  210. data: "oper=add&selId=",
  211. url: "${contextPath }/admin/basicdata/barupdate.html",
  212. error: function(json){alert("系统错误");},
  213. success: function(json){
  214. flag = json.status;
  215. if(flag=="fail"){
  216. alert("请先修改舍组栏名称为【空白名称】的记录,再添加新记录");
  217. }
  218. selId=1;
  219. $("#list").clearGridData(); //清空原grid数据
  220. loadList(); //重新载入服务器数据
  221. selId=0;
  222. }
  223. });
  224. }
  225. //自定义删除方法
  226. function deleteRow(){
  227. var count = 0;
  228. var row = $("#list").jqGrid("getGridParam","selrow");
  229. var selRow = $("#list").jqGrid("getRowData",row);
  230. $.ajax({
  231. async: false,
  232. type: "POST",
  233. dataType:"json", //返回类型jsond
  234. data: "selId="+selRow.ID,
  235. url: "${contextPath }/admin/basicdata/querybarglxx.html",
  236. error: function(){alert("系统错误");},
  237. success: function(json){
  238. count = json.status;
  239. }
  240. });
  241. var deletetype,warn;
  242. if(count==0){
  243. deletetype="realdel";
  244. warn="您确定要删除吗"
  245. }
  246. else{
  247. deletetype="unrealdel";
  248. warn="该舍组栏已被使用,是否要删除\n(栏舍配方中相关信息将被清除)"
  249. }
  250. var flag = confirm(warn);
  251. if(flag){
  252. $.ajax({
  253. async: false,
  254. type: "POST",
  255. dataType:"json", //返回类型jsond
  256. data: "oper="+deletetype+"&selId="+selRow.ID,
  257. url: "${contextPath }/admin/basicdata/barupdate.html",
  258. error: function(json){alert("系统错误");},
  259. success: function(json){
  260. $("#list").clearGridData(); //清空原grid数据
  261. loadList(); //重新载入服务器数据
  262. }
  263. });
  264. }
  265. }
  266. //自定义验证名称是否存在方法
  267. function checkName(value, colname){
  268. var flag = 0;
  269. var warn = 0;
  270. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  271. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  272. $.ajax({
  273. async: false,
  274. type: 'POST',
  275. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  276. dataType: 'json',
  277. url: "${contextPath}/admin/basicdata/barcheck.html",
  278. error: function(){alert("系统错误");},
  279. success: function(json){
  280. flag = json.status;
  281. warn = json.warn;
  282. }
  283. });
  284. if(flag == 0){
  285. return [true,""];
  286. }else{
  287. var warnway
  288. if(warn==1){
  289. warnway="舍组栏名称已经存在于启用中!";
  290. }
  291. else if(warn==2)
  292. {
  293. warnway="舍组栏名称曾被使用,无法创建!";
  294. }
  295. else if(warn==3){
  296. warnway="舍组栏名称已经存在于禁用中!";
  297. }
  298. else{
  299. warnway="舍组栏名称已经存在!";
  300. }
  301. return [false,warnway];
  302. }
  303. }
  304. function showAll(){
  305. loadType=3;
  306. $("#list").clearGridData();
  307. loadList();
  308. }
  309. function showBan(){
  310. loadType=2;
  311. $("#list").clearGridData();
  312. loadList();
  313. }
  314. function showUse(){
  315. loadType=1;
  316. $("#list").clearGridData();
  317. loadList();
  318. }
  319. </script>
  320. </head>
  321. <body style="background-color: #E0E0E0">
  322. <div>
  323. <div class="navfrm">
  324. <span>当前位置:</span>
  325. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  326. <span>&nbsp;>>&nbsp;</span>
  327. <span>舍组栏管理</span>
  328. </div>
  329. <table id="list"></table>
  330. <div id="page"></div>
  331. </div>
  332. </body>
  333. </html>