123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <%@ page contentType="text/html; charset=utf-8" session="false" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
- <head>
- <title>我的工作台</title>
- <%@ include file="../common/header.jsp" %>
- <script type="text/javascript">
- var mydata,operType,loadCount = 0;
- $(document).ready( function() {
- loadList(); //加载jqgrid
- $("#list").jqGrid("setGridHeight",$(window).height() - 100);
- $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
- });
- $(window).resize(function(){
- $("#list").jqGrid("setGridHeight",$(window).height() - 100);
- $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
- });
-
- //jqgrid初始化
- function loadList(){
- jQuery("#list").jqGrid({
- datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
- height: "70%", //高度
- colNames:['主键','饲料名称','饲料分类', '打印组', '允许误差数(kg)', '包装单位重量', '单价(元)', '干物质(kg/kg)', '跳转重量域(公斤)', '跳转延时(秒)', '确认开始', '继电器位置', '顺序', '是否启用'], //列名
- colModel:[
- {
- name: "ID",
- index: "ID",
- align: "center",
- sorttype: "string",
- editable: true,
- hidden: true
- //editoptions:{readonly:true} 如果要显示该列可以设置只读
- },
- {
- name: "FNAME",
- index: "FNAME",
- align: "center",
- sorttype: "string",
- editable: true,
- editrules:{
- required: true,
- custom: true,
- custom_func: checkName
- }
- },
- {
- name: "FCNAME",
- index: "FCNAME",
- align: "center",
- sorttype: "int",
- editable: true,
- edittype: "select",
- editoptions:{
- dataUrl: "${contextPath }/admin/basicdata/feedselect.html"
- }
- },
- {
- name: "PrintGroup",
- index: "PrintGroup",
- align: "center",
- sorttype: "string",
- editable: true,
- edittype:"select",
- editoptions:{value:{"无":"无","铲车":"铲车","精料":"精料"}}
- },
- {
- name: "AllowRatio",
- index: "AllowRatio",
- align: "center",
- sorttype: "number",
- editable: true,
- editrules: {required:true,number: true}
- },
- {
- name: "UnitWeight",
- index: "UnitWeight",
- align: "center",
- sorttype: "number",
- editable: true,
- editrules: {number: true}
- },
- {
- name: "Uprice",
- index: "Uprice",
- align: "center",
- sorttype: "number",
- editable: true,
- editrules: {number: true}
- },
- {
- name: "dry",
- index: "dry",
- align: "center",
- sorttype: "number",
- editable: true,
- editrules: {number: true}
- },
- {
- name: "autozone",
- index: "autozone",
- align: "center",
- sorttype: "number",
- editable: true,
- editrules: {number: true}
- },
- {
- name: "autosecond",
- index: "autosecond",
- align: "center",
- sorttype: "string",
- editable: true,
- edittype:"select",
- editoptions:{value:{"0":"禁用","1":"3秒","2":"6秒","3":"9秒"}}
- },
- {
- name: "NeedBegin",
- index: "NeedBegin",
- align: "center",
- sorttype: "string",
- editable: true,
- edittype:"select",
- editoptions:{value:{"0":"禁用","1":"启用"}}
- },
- {
- name: "TrgAddress",
- index: "TrgAddress",
- align: "center",
- sorttype: "int",
- editable: true,
- editrules:{
- required: true,
- integer: true
- }
- },
- {
- name: "SORT",
- index: "SORT",
- align: "center",
- sorttype: "int",
- editable: true,
- editrules:{
- required: true,
- integer: true
- }
- },
- {
- name: "ENABLE",
- index: "ENABLE",
- align: "center",
- sorttype: "string",
- editable: true,
- edittype: "select",
- editoptions: {value:{"Yes":"是","No":"否"}}
- }
- ],
- caption: "饲料管理", //标题
-
- cellEdit: true,
- cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
-
-
- afterSaveCell: function(rowid,name,val,iRow,iCol) {
- var rowData = $("#list").jqGrid("getRowData",rowid);
- var id = rowData.ID;
- if(id==1000 && iCol==2){
- alert("该饲料名称不能修改");
- }else{
- $.ajax({
- async: false,
- type: 'POST',
- dataType:'json', //返回类型jsond
- data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
- url: "${contextPath }/admin/basicdata/feedupdatedyg.html",
- error: function(){alert("系统错误");},
- success: function(json){
- }
- });
- }
- },
-
- pager: "#page", //#page分页控件绑定的位置对象
- rowNum: 1000, //每页显示条数
- rowList: [100,200,300,400], //分页下拉选项内容
- rownumbers: true, //是否显示行数
- viewrecords: true, //是否显示总条数
- emptyrecords: "无数据", //服务器返回空列表时显示的内容
- autowidth: true, //自动调节宽度
- sortname: 'SORT', //按SORT进行排序 默认asc
- altRows: true, //设置表格是否允许行交替变色值
- altclass:"tdbgmouseover" //自定义隔行变色的样式
- });
-
- //获取数据集
- mydata = getLists();
-
- if(mydata!=null){
- for(var i=0;i<=mydata.length;i++){
- jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
- }
- jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
- }
- //绑定、设置工具栏
- jQuery("#list").jqGrid("navGrid","#page",{
- add: true, addtext: "添加",
- edit: false, edittext: "编辑",
- del: true, deltext: "删除",refresh: false,
- addfunc: addRow, //自定义添加方法
- delfunc: deleteRow, //自定义删除方法
- searchtext: "搜索",
- refreshtext: "刷新",
- alerttext:"请选择一条记录!"
- });
-
- if(loadCount == 0){
- $("#list").navButtonAdd("#page",{
- caption:"批量修改配方模版饲料顺序",
- buttonicon:"ui-icon-document",
- position: "last",
- title:"批量修改配方模版饲料顺序",
- cursor: "pointer", //光标类型
- onClickButton: viewRow
- });
- }
-
- }
-
- //获取服务器数据
- function getLists(){
- $.ajax({
- async: false,
- type: 'POST',
- dataType:'json', //返回类型json
- url: "${contextPath }/admin/basicdata/feedlist.html",
- error: function(){alert("系统错误");},
- success: function(json){
- mydata = json;
- }
- });
- return mydata;
- }
-
- //自定义添加方法
- function addRow(){
- loadCount = 1;
- var ids = $("#list").jqGrid("getDataIDs");
- $("#list").jqGrid("addRowData",ids.length+1,{},"first");
- $.ajax({
- async: false,
- type: "POST",
- dataType:"json", //返回类型jsond
- data: "oper=add&selId=",
- url: "${contextPath }/admin/basicdata/feedupdate.html",
- error: function(){alert("系统错误");},
- success: function(json){
- $("#list").clearGridData(); //清空原grid数据
- loadList(); //重新载入服务器数据
- }
- });
- }
-
- //自定义删除方法
- function deleteRow(){
- loadCount = 1;
- var count = 0;
- var flag = confirm("您确定要删除吗?");
- if(flag){
- var row = $("#list").jqGrid("getGridParam","selrow");
- var selRow = $("#list").jqGrid("getRowData",row);
- var id = selRow.ID;
- if(id==1000){
- alert("该饲料不能删除");
- }else{
- $.ajax({
- async: false,
- type: "POST",
- dataType:"json", //返回类型jsond
- data: "selId="+selRow.ID,
- url: "${contextPath }/admin/basicdata/queryfeedglxx.html",
- error: function(){alert("系统错误");},
- success: function(json){
- count = json.status;
- }
- });
- if(count == 0){
- $.ajax({
- async: false,
- type: "POST",
- dataType:"json", //返回类型jsond
- data: "oper=del&selId="+selRow.ID,
- url: "${contextPath }/admin/basicdata/feedupdate.html",
- error: function(){alert("系统错误");},
- success: function(json){
- $("#list").clearGridData(); //清空原grid数据
- loadList(); //重新载入服务器数据
- }
- });
- }else{
- alert("该记录被引用、不能删除!!!");
- }
- }
- }
- }
-
- //自定义验证名称是否存在方法
- function checkName(value, colname){
- var flag = 0;
- var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
- var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
- $.ajax({
- async: false,
- type: 'POST',
- data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
- dataType: 'json',
- url: "${contextPath}/admin/basicdata/feedcheck.html",
- error: function(){alert("系统错误");},
- success: function(json){
- flag = json.status;
- }
- });
- if(flag == 0){
- return [true,""];
- }else{
- return [false,"饲料名称已经存在!"];
- }
- }
-
- //配方顺序
- function viewRow(){
- $.ajax({
- async: false,
- type: 'POST',
- dataType: 'json',
- url: "${contextPath}/admin/basicdata/checkFtdetailSort.html",
- error: function(){alert("系统错误");},
- success: function(json){
- if(json.status == "success"){
- alert("配方模版饲料顺序已经全部更新");
- }
- }
- });
- }
- </script>
- </head>
- <body style="background-color: #E0E0E0">
- <div>
- <div class="navfrm">
- <span>当前位置:</span>
- <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
- <span> >> </span>
- <span>饲料管理</span>
- </div>
- <table id="list"></table>
- <div id="page"></div>
- </div>
- </body>
- </html>
|