template.jsp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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" src="${contextPath }/js/mColorPicker.js"></script>
  10. <script type="text/javascript" src="${contextPath }/js/zxx.color_exchange.js"></script>
  11. <script type="text/javascript">
  12. var mydata,operType,panelCHeight=0,loadCount = 0,selRowId = 0,loadType=1;
  13. $(document).ready( function() {
  14. loadList(); //加载jqgrid
  15. panelC = $("body").layout("panel","center").panel();
  16. panelCHeight = panelC.height();
  17. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  18. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 30);
  19. $("body").layout("panel","south").panel({
  20. onClose: function(){
  21. panelC = $("body").layout("panel","center").panel();
  22. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  23. },
  24. onExpand: function(){
  25. panelS = $("body").layout("panel","south").panel();
  26. panelCHeight = document.body.clientHeight - panelS.height();
  27. $("#list").jqGrid("setGridHeight",panelCHeight-135);
  28. },
  29. onResize: function(){
  30. panelS = $("body").layout("panel","south").panel();
  31. panelCHeight = document.body.clientHeight - panelS.height();
  32. $("#list").jqGrid("setGridHeight",panelCHeight-135);
  33. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 30);
  34. $("#listFtdetail").jqGrid("setGridHeight",panelS.height()-75);
  35. $("#listFtdetail").jqGrid("setGridWidth",document.body.clientWidth - 30);
  36. }
  37. });
  38. //初始化绑定选颜色控件
  39. $('#mColorPickerImg').bind('click', function() {
  40. if(selRowId == 0){
  41. alert("请选择配方模版");
  42. }else{
  43. var color = $("#tColor").val();
  44. var str = color.substring(0,3);
  45. if(str == "rgb"){
  46. color = color.colorHex();
  47. }
  48. $.ajax({
  49. async: true,
  50. type: "POST",
  51. dataType:"json", //返回类型jsond
  52. data: "tcolor="+color+"&selId="+selRowId,
  53. url: "${contextPath }/admin/recipeplan/tcolorfeedtemplet.html",
  54. error: function(){alert("系统错误");},
  55. success: function(json){
  56. $("#list").clearGridData(); //清空原grid数据
  57. loadList(); //重新载入服务器数据
  58. }
  59. });
  60. }
  61. });
  62. });
  63. $(window).resize(function(){
  64. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 10);
  65. $("#listFtdetail").jqGrid("setGridWidth",document.body.clientWidth - 10);
  66. });
  67. //jqgrid初始化
  68. function loadList(){
  69. jQuery("#list").jqGrid({
  70. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  71. height: 170, //高度
  72. colNames:['主键','模版名称','模板颜色','牲畜类型', '制定人', '说明', '是否补料模版', '顺序', '是否启用'], //列名
  73. colModel:[
  74. {
  75. name: "ID",
  76. index: "ID",
  77. align: "center",
  78. sorttype: "string",
  79. editable: true,
  80. hidden: true
  81. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  82. },
  83. {
  84. name: "TNAME",
  85. index: "TNAME",
  86. align: "center",
  87. sorttype: "string",
  88. editable: true,
  89. editrules:{
  90. required: true,
  91. custom: true,
  92. custom_func: checkName
  93. }
  94. },
  95. {
  96. name: "tColor",
  97. index: "tColor",
  98. width: 70,
  99. align: "center",
  100. sorttype: "string",
  101. editable: false
  102. },
  103. {
  104. name: "CLASSNAME",
  105. index: "CLASSNAME",
  106. align: "center",
  107. sorttype: "int",
  108. editable: true,
  109. edittype: "select",
  110. editoptions:{
  111. dataUrl: "${contextPath }/admin/recipeplan/feedtempletselect.html"
  112. }
  113. },
  114. {
  115. name: "OWNER",
  116. index: "OWNER",
  117. align: "center",
  118. sorttype: "int",
  119. editable: true
  120. },
  121. {
  122. name: "REMARK",
  123. index: "REMARK",
  124. align: "center",
  125. sorttype: "int",
  126. editable: true
  127. },
  128. {
  129. name: "isSupplyFeed",
  130. index: "isSupplyFeed",
  131. align: "center",
  132. sorttype: "string",
  133. editable: true,
  134. edittype: "select",
  135. editoptions: {value:{"Yes":"是","No":"否"}}
  136. },
  137. {
  138. name: "SORT",
  139. index: "SORT",
  140. align: "center",
  141. sorttype: "int",
  142. editable: true,
  143. editrules:{
  144. required: true,
  145. integer: true
  146. }
  147. },
  148. {
  149. name: "ENABLE",
  150. index: "ENABLE",
  151. align: "center",
  152. sorttype: "string",
  153. editable: true,
  154. edittype: "select",
  155. editoptions: {value:{"Yes":"是","No":"否"}}
  156. }
  157. ],
  158. cellEdit: true,
  159. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  160. onSelectCell: function(rowid){
  161. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  162. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  163. selRowId = rowData.ID;
  164. },
  165. afterEditCell: function(rowid,name,val,iRow,iCol){
  166. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  167. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  168. $("#ftdetailResult").load("${contextPath }/admin/recipeplan/ftdetail.html?currentTfId="+rowData.ID);
  169. selRowId = rowData.ID;
  170. },
  171. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  172. var rowData = $("#list").jqGrid("getRowData",rowid);
  173. $.ajax({
  174. async: false,
  175. type: 'POST',
  176. dataType:'json', //返回类型jsond
  177. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  178. url: "${contextPath }/admin/recipeplan/feedtempletupdatedyg.html",
  179. error: function(){alert("系统错误");},
  180. success: function(json){
  181. }
  182. });
  183. },
  184. pager: "#page", //#page分页控件绑定的位置对象
  185. pginput: false, //不显示分页文本框
  186. pgbuttons: false, //不显示翻页按钮
  187. rowNum: 1000, //每页显示条数
  188. viewrecords: true, //是否显示总条数
  189. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  190. autowidth: true, //自动调节宽度
  191. sortname: 'SORT' //按SORT进行排序 默认asc
  192. });
  193. //获取数据集
  194. mydata = getLists();
  195. if(mydata!=null){
  196. for(var i=0;i<=mydata.length;i++){
  197. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  198. }
  199. //jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  200. }
  201. //绑定、设置工具栏
  202. jQuery("#list").jqGrid("navGrid","#page",{
  203. add: true, addtext: "添加",
  204. edit: false, edittext: "编辑",
  205. del: true, deltext: "删除",refresh: false,
  206. addfunc: addRow, //自定义添加方法
  207. delfunc: deleteRow, //自定义删除方法
  208. searchtext: "搜索",
  209. refreshtext: "刷新",
  210. alerttext:"请选择一条记录!"
  211. });
  212. if(loadCount == 0){
  213. $("#list").navButtonAdd("#page",{
  214. caption:"复制",
  215. buttonicon:"ui-icon-document",
  216. position: "last",
  217. title:"复制",
  218. cursor: "pointer", //光标类型
  219. onClickButton: copyRow
  220. });
  221. $("#list").navButtonAdd("#page",{
  222. caption:"显示启用",
  223. buttonicon:"ui-icon-document",
  224. position: "last",
  225. title:"显示启用",
  226. cursor: "pointer", //光标类型
  227. onClickButton: showUse
  228. });
  229. $("#list").navButtonAdd("#page",{
  230. caption:"显示禁用",
  231. buttonicon:"ui-icon-document",
  232. position: "last",
  233. title:"显示禁用",
  234. cursor: "pointer", //光标类型
  235. onClickButton: showBan
  236. });
  237. $("#list").navButtonAdd("#page",{
  238. caption:"显示全部",
  239. buttonicon:"ui-icon-document",
  240. position: "last",
  241. title:"显示全部",
  242. cursor: "pointer", //光标类型
  243. onClickButton: showAll
  244. });
  245. $("#list").navButtonAdd("#page",{
  246. caption:"导出Excel",
  247. buttonicon:"ui-icon-document",
  248. position: "last",
  249. title:"导出Excel",
  250. cursor: "pointer", //光标类型
  251. onClickButton: exportExcel
  252. });
  253. //$("#page_left").append("&nbsp;&nbsp;<input id='tColor' name='tColor' style='width:50px; ' value='' type='color' class='color' readonly='readonly' />");
  254. $("#page_left").append("&nbsp;&nbsp;<input id='tColor' name='tColor' style='width:50px; color: white; background-color: rgb(0, 0, 0);' value='' type='hidden' class='color mColorPicker' readonly='readonly' />");
  255. $("#page_left").append("<span onClick='selTColor1()' id='mcp_tColor' class='mColorPickerTrigger' style='display: inline-block; cursor: pointer;'><img src='images/color.png' style='border: 0px; margin: 0px 0px 0px 3px; vertical-align: text-bottom;'></span>");
  256. //$("#page_left").append("<input class='sysub' type='button' value='选择模版颜色' onClick='selTColor()' style='width:85px;height: 30px;'/>");
  257. loadCount++;
  258. }
  259. }
  260. //获取服务器数据
  261. function getLists(){
  262. var loadurl;
  263. if(loadType==1){
  264. loadurl="${contextPath }/admin/recipeplan/feedtempletlistuse.html";
  265. }
  266. else if(loadType==2){
  267. loadurl="${contextPath }/admin/recipeplan/feedtempletlistban.html";
  268. }
  269. else if(loadType==3){
  270. loadurl="${contextPath }/admin/recipeplan/feedtempletlist.html";
  271. }
  272. $.ajax({
  273. async: false,
  274. type: 'POST',
  275. dataType:'json', //返回类型json
  276. url: loadurl,
  277. error: function(){alert("系统错误");},
  278. success: function(json){
  279. mydata = json;
  280. }
  281. });
  282. return mydata;
  283. }
  284. //自定义添加方法
  285. function addRow(){
  286. var ids = $("#list").jqGrid("getDataIDs");
  287. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  288. $.ajax({
  289. async: false,
  290. type: "POST",
  291. dataType:"json", //返回类型jsond
  292. data: "oper=add&selId=",
  293. url: "${contextPath }/admin/recipeplan/feedtempletupdate.html",
  294. error: function(){alert("系统错误");},
  295. success: function(json){
  296. $("#list").clearGridData(); //清空原grid数据
  297. loadList(); //重新载入服务器数据
  298. }
  299. });
  300. }
  301. //自定义删除方法
  302. function deleteRow(){
  303. var count = 0;
  304. var row = $("#list").jqGrid("getGridParam","selrow");
  305. var selRow = $("#list").jqGrid("getRowData",row);
  306. $.ajax({
  307. async: false,
  308. type: "POST",
  309. dataType:"json", //返回类型jsond
  310. data: "selId="+selRow.ID,
  311. url: "${contextPath }/admin/recipeplan/queryfeedtempletglxx.html",
  312. error: function(){alert("系统错误");},
  313. success: function(json){
  314. count = json.status;
  315. }
  316. });
  317. var deletetype,warn;
  318. if(count==0){
  319. deletetype="realdel";
  320. warn="您确定要删除吗"
  321. }
  322. else{
  323. deletetype="unrealdel";
  324. warn="该配方模板已被使用,是否要删除\n(栏舍配方中相关信息将被清除)"
  325. }
  326. var flag = confirm(warn);
  327. if(flag){
  328. $.ajax({
  329. async: false,
  330. type: "POST",
  331. dataType:"json", //返回类型jsond
  332. data: "oper="+deletetype+"&selId="+selRow.ID,
  333. url: "${contextPath }/admin/recipeplan/feedtempletupdate.html",
  334. error: function(){alert("系统错误");},
  335. success: function(json){
  336. $("#list").clearGridData(); //清空原grid数据
  337. window.location.reload();
  338. }
  339. });
  340. }
  341. }
  342. //自定义验证名称是否存在方法
  343. function checkName(value, colname){
  344. var flag = 0;
  345. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  346. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  347. $.ajax({
  348. async: false,
  349. type: 'POST',
  350. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  351. dataType: 'json',
  352. url: "${contextPath}/admin/recipeplan/feedtempletcheck.html",
  353. error: function(){alert("系统错误");},
  354. success: function(json){
  355. flag = json.status;
  356. }
  357. });
  358. if(flag == 0){
  359. return [true,""];
  360. }else{
  361. return [false,"模版名称已经存在!"];
  362. }
  363. }
  364. //复制记录
  365. function copyRow(){
  366. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  367. if(selId!=null){
  368. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  369. $.ajax({
  370. async: false,
  371. type: 'POST',
  372. data: "entityId="+rowData.ID,
  373. dataType: 'json',
  374. url: "${contextPath}/admin/recipeplan/copyRow.html",
  375. error: function(){alert("系统错误");},
  376. success: function(json){
  377. $("#list").clearGridData(); //清空原grid数据
  378. window.location.reload();
  379. }
  380. });
  381. }else{
  382. alert("请选择记录");
  383. }
  384. }
  385. //导出Excel
  386. function exportExcel(){
  387. document.location.href="${contextPath }/admin/recipeplan/feedtempletexcel.html";
  388. }
  389. function selTColor(){
  390. $("body").layout("collapse","south");
  391. panelC = $("body").layout("panel","center").panel();
  392. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  393. if(selRowId == 0){
  394. alert("请选择配方模版");
  395. }else{
  396. var color = $("#tColor").val();
  397. var str = color.substring(0,3);
  398. if(str == "rgb"){
  399. color = color.colorHex();
  400. }
  401. $.ajax({
  402. async: true,
  403. type: "POST",
  404. dataType:"json", //返回类型jsond
  405. data: "tcolor="+color+"&selId="+selRowId,
  406. url: "${contextPath }/admin/recipeplan/tcolorfeedtemplet.html",
  407. error: function(){alert("系统错误");},
  408. success: function(json){
  409. $("#list").clearGridData(); //清空原grid数据
  410. loadList(); //重新载入服务器数据
  411. }
  412. });
  413. }
  414. }
  415. function selTColor1(){
  416. $("body").layout("collapse","south");
  417. panelC = $("body").layout("panel","center").panel();
  418. $("#list").jqGrid("setGridHeight",panelC.height()-55);
  419. $("#mColorPickerSwatches").hide();
  420. $("#mColorPickerFooter").hide();
  421. //$("#mColorPicker").attr("style","height: 144px;");
  422. }
  423. function showAll(){
  424. loadType=3;
  425. $("#list").clearGridData();
  426. loadList();
  427. }
  428. function showBan(){
  429. loadType=2;
  430. $("#list").clearGridData();
  431. loadList();
  432. }
  433. function showUse(){
  434. loadType=1;
  435. $("#list").clearGridData();
  436. loadList();
  437. }
  438. </script>
  439. </head>
  440. <body class="easyui-layout">
  441. <div region="center" title="配方模版" style="padding:5px;background:#eee;">
  442. <table id="list"></table>
  443. <div id="page"></div>
  444. <input type="hidden" />
  445. </div>
  446. <div region="south" split="true" title="饲料" style="padding:5px;height:230px;">
  447. <div id="ftdetailResult"></div>
  448. </div>
  449. </body>
  450. </html>