$(function() {
|
// $.fn.dataTable.ext.errMode = "none";
|
var table = $("#example").DataTable({
|
"aLengthMenu":[9,10,15,20],
|
"searching":false,
|
"lengthChange":true,
|
"paging": true,
|
"bProcessing" : true,
|
"bServerSide" : true,
|
"bAutoWidth" : false,
|
"sort" : "position",
|
"autoWidth": true,
|
"deferRender":true,
|
"bStateSave" : false,
|
"iDisplayLength" : 9,
|
"iDisplayStart" : 0,
|
"dom": '<l<\'#topPlugin\'>f>rt<ip><"clear">',
|
"ordering": false,
|
"ajax": {
|
"type": "GET",
|
"url":contextPath + "/shelfmanager/rawpackagelist?ajax=true",
|
"data":function(d){
|
|
d.glassId=$("#glassId").val();
|
d.glassThickness=$("#glassThickness").val().trim();
|
d.state=$("#state").val();
|
d.status=$("#status").val();
|
}
|
},
|
"aoColumns" : [
|
{
|
"mData" : "id",
|
"orderable": false , // 禁用排序
|
"sDefaultContent" : "",
|
"sWidth" : "2%"
|
},
|
|
{
|
"mData" : "number",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "6%",
|
"render":function(data, type, full, meta){
|
return '<span style="font-size:20px; Height: 40px">'+data+'</span>';
|
}
|
|
},
|
{
|
"mData" : "glassId",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, full, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+data+'</span>';
|
}
|
},{
|
"mData" : "width",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, full, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+data+'</span>';
|
}
|
},{
|
"mData" : "length",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, full, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+data+'</span>';
|
}
|
},
|
{
|
"mData" : "thickness",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, full, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+data+'</span>';
|
}
|
},
|
{
|
"mData" : "pieces",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, row, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+(row.pieces-row.completePieces)+'</span>';
|
}
|
},
|
{
|
"mData" : "precent",
|
"orderable" : false,
|
"sDefaultContent" : "",
|
"sWidth" : "9%",
|
"render":function(data, type, full, meta){
|
if(data==null){
|
return '';
|
}
|
return '<span style="font-size:20px; Height: 40px">'+(data)+'</span>';
|
}
|
},
|
{
|
"mData" : "createTime",
|
"orderable" : false, // 禁用排序
|
"sDefaultContent" : "",
|
"sWidth" : "13%",
|
"render" : function(data, type, row,meta) {
|
if(row.state=='空闲'){
|
return '';
|
}
|
//时间格式化
|
return '<span style="font-size:20px; Height: 40px">'+ moment(data.time).format("YYYY-MM-DD HH:mm:ss")+'</span>';
|
}
|
},
|
{
|
"mData" : "flag",
|
"orderable" : false, // 禁用排序
|
"sDefaultContent" : "",
|
"sWidth" : "10%",
|
"render" : function(data, type, full,meta) {
|
if(data==1){
|
data ="<a href='#' style='font-size:18px; Height: 40px' class='upOrderStatus' data-id="+full.id+">启用</a>";
|
}else{
|
data ="<a href='#' style='font-size:18px; Height0: 4px' class='upOrderStatus' data-id="+full.id+"><font color='red'>禁用</font></a>";
|
}
|
return data;
|
}
|
}],
|
// {
|
// "mData" : "precent",
|
// "orderable" : false,
|
// "sDefaultContent" : "",
|
// "sWidth" : "10%",
|
// "render":function(data, type, row, meta){
|
// var leftPieces=row.pieces-row.completePieces;
|
// var pieces=row.pieces;
|
// return '<div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" style="font-size:20px; Height: 40px; width: '+leftPieces/pieces*100+'%">'+'<span>'+leftPieces+'/'+pieces+'</span>'+'</div></div>';
|
// }
|
// }
|
|
"columnDefs" :
|
[{
|
"orderable" : false,
|
"targets" : [0],
|
"data" : "id",
|
"render" : function(data, type, full, meta) {
|
return '<input type="checkbox" value="'+ data + '" name="id"/>';
|
}
|
}],
|
"oLanguage" : {
|
"sProcessing" : "正在获取数据,请稍后...",
|
"sLengthMenu" : "显示 _MENU_ 条",
|
"sZeroRecords" : "没有找到数据",
|
"sInfo" : "从 _START_ 到 _END_ 条记录 总记录数为 _TOTAL_ 条",
|
"sInfoEmpty" : "记录数为0",
|
"sInfoFiltered" : "(全部记录数 _MAX_ 条)",
|
"sInfoPostFix" : "",
|
"sSearch" : "搜索",
|
"sUrl" : "",
|
"oPaginate" : {
|
"sFirst" : "第一页",
|
"sPrevious" : "上一页",
|
"sNext" : "下一页",
|
"sLast" : "最后一页"
|
}
|
},
|
initComplete:initComplete,
|
});
|
|
/**
|
* 初始化按钮
|
* @param data
|
*/
|
function initComplete(data){
|
// var topPlugin='<div class="btn-group" role="group" ><button class="btn btn-success btn-lg" id="deleteAll">出库</button> <button class="btn btn-primary btn-lg addBtn" >入库</button> <button id="info" class="btn btn-danger btn-lg" >禁用/启用</button> <button class="btn btn-info btn-lg" id="expExcel">导出全部</button> <button class="btn btn-warning btn-lg" id="reset">添加原片</button> <button class="btn btn-primary btn-lg deleteBtn" id="deleteBtn">删除原片</button> <button class="btn btn-success btn-lg" id="search">查询</button></div>' ;
|
//
|
// $("#topPlugin").append(topPlugin);
|
}
|
|
/**
|
* 多选选中和取消选中,同时选中第一个单元格单选框,并联动全选单选框
|
*/
|
$('#example tbody').on('click', 'tr', function(event) {
|
var allChecked=$('input[name=allChecked]')[0];//关联全选单选框
|
$($(this).children()[0]).children().each(function(){
|
if(this.type=="checkbox" && (!$(event.target).is(":checkbox") && $(":checkbox",this).trigger("click"))){
|
if(!this.checked){
|
this.checked = true;
|
addValue(this);
|
var selected=table.rows('.selected').data().length;//被选中的行数
|
//全选单选框的状态处理
|
var recordsDisplay=table.page.info().recordsDisplay;//搜索条件过滤后的总行数
|
var iDisplayStart=table.page.info().start;// 起始行数
|
if(selected === table.page.len()||selected === recordsDisplay||selected === (recordsDisplay - iDisplayStart)){
|
allChecked.checked = true;
|
}
|
}else{
|
this.checked = false;
|
cancelValue(this);
|
allChecked.checked = false;
|
}
|
}
|
});
|
$(this).toggleClass('selected');//放在最后处理,以便给checkbox做检测
|
});
|
|
|
|
/**
|
* 全选按钮被点击事件
|
*/
|
$('input[name=allChecked]').click(function(){
|
if(this.checked){
|
$('#example tbody tr').each(function(){
|
if(!$(this).hasClass('selected')){
|
$(this).click();
|
}
|
});
|
}else{
|
$('#example tbody tr').click();
|
}
|
});
|
|
/**
|
* 单选框被选中时将它的value放入隐藏域
|
*/
|
function addValue(para) {
|
var userIds = $("input[name=userIds]");
|
if(userIds.val() === ""){
|
userIds.val($(para).val());
|
}else{
|
userIds.val(userIds.val()+","+$(para).val());
|
}
|
}
|
|
/**
|
* 单选框取消选中时将它的value移除隐藏域
|
*/
|
function cancelValue(para){
|
//取消选中checkbox要做的操作
|
var userIds = $("input[name=allChecked]");
|
var array = userIds.val().split(",");
|
userIds.val("");
|
for (var i = 0; i < array.length; i++) {
|
if (array[i] === $(para).val()) {
|
continue;
|
}
|
if (userIds.val() === "") {
|
userIds.val(array[i]);
|
} else {
|
userIds.val(userIds.val() + "," + array[i]);
|
}
|
}
|
}
|
|
/**
|
* 批量出库
|
*/
|
$(document).delegate('#deleteAll','click',function() {
|
var theArray=[];
|
$("input[name=id]:checked").each(function() {
|
theArray.push($(this).val());
|
});
|
if(theArray.length<1){
|
$.MsgBox.Alert("警告", "请至少选中一行");
|
}else{
|
$("#deleteAllModal").modal('toggle');
|
var ids="";
|
for(var i=0; i<theArray.length; i++){
|
ids+=(theArray[i]+";");
|
}
|
ids=ids.substring(0, ids.length-1);
|
$("#delAllSubmit").val(ids);
|
}
|
|
});
|
|
/**
|
* 点击确认出库按钮
|
*/
|
$(document).delegate('#delAllSubmit','click',function(){
|
var Ids=$(this).val();
|
$('#deleteAllModal').modal('hide');
|
$.ajax({
|
url:contextPath + "/shelfmanager/deleteAll?Ids="+Ids,
|
async:true,
|
type:"GET",
|
dataType:"json",
|
cache:false,
|
success: function(data){
|
var obj = eval(data);
|
if(obj.code==1)
|
{
|
window.location.reload();
|
}
|
else
|
{
|
alert("出库失败");
|
}
|
|
},
|
error:function(data){
|
alert("请求异常");
|
}
|
});
|
});
|
|
/**
|
* 删除原片
|
*/
|
$(document).delegate('#deleteBtn','click',function() {
|
var deleteArray=[];
|
$("input[name=id]:checked").each(function() {
|
deleteArray.push($(this).val());
|
});
|
if(deleteArray.length<1){
|
$.MsgBox.Alert("警告", "请至少选中一行");
|
}else{
|
var ids="";
|
for(var i=0; i<deleteArray.length; i++){
|
ids+=(deleteArray[i]+";");
|
}
|
ids=ids.substring(0, ids.length-1);
|
$.ajax({
|
url:contextPath + "/shelfmanager/deleteBtn?Ids="+ids,
|
async:true,
|
type:"POST",
|
dataType:"json",
|
cache:false,
|
success: function(data){
|
var obj = eval(data);
|
if(obj.code==1)
|
{
|
window.location.reload();
|
}
|
else
|
{
|
alert("删除失败");
|
}
|
|
},
|
error:function(data){
|
alert("请求异常");
|
}
|
});
|
}
|
|
});
|
|
|
/**
|
* 禁用/启用
|
*/
|
$(document).delegate('#info','click',function(){
|
var infoArray=[];
|
$("input[name=id]:checked").each(function() {
|
infoArray.push($(this).val());
|
});
|
if(infoArray.length<1){
|
$.MsgBox.Alert("警告", "请至少选中一行");
|
}else{
|
$("#infoMyModal").modal('toggle');
|
var ids="";
|
for(var i=0; i<infoArray.length; i++){
|
ids+=(infoArray[i]+";");
|
}
|
ids=ids.substring(0, ids.length-1);
|
$("#infoAllSubmit").val(ids);
|
}
|
});
|
|
/**
|
* 点击确认禁用启用按钮
|
*/
|
$(document).delegate('#infoAllSubmit','click',function(){
|
var Ids=$(this).val();
|
$('#infoMyModal').modal('hide');
|
$.ajax({
|
url:contextPath + "/shelfmanager/stopOrStart?Ids="+Ids,
|
async:true,
|
type:"GET",
|
dataType:"json",
|
cache:false,
|
success: function(data){
|
var obj = eval(data);
|
if(obj.code==1)
|
{
|
window.location.reload();
|
}
|
else
|
{
|
alert("失败");
|
}
|
|
},
|
error:function(data){
|
alert("请求异常");
|
}
|
});
|
});
|
|
|
/**
|
* 添加原片
|
*/
|
$(document).delegate('#reset','click',function(){
|
var addArray=[];
|
$("input[name=id]:checked").each(function() {
|
addArray.push($(this).val());
|
});
|
if(addArray.length<1){
|
$.MsgBox.Alert("警告", "请选中一行");
|
}
|
if(addArray.length>1){
|
$.MsgBox.Alert("警告", "只能选中一行");
|
}
|
if(addArray.length==1){
|
$("#add-info").modal('show');
|
var ids="";
|
for(var i=0; i<addArray.length; i++){
|
ids+=(addArray[i]+";");
|
}
|
ids=ids.substring(0, ids.length-1);
|
$("#addRawPackage").val(ids);
|
}
|
|
});
|
|
/**
|
* 入库
|
*/
|
$(document).delegate('.addBtn','click',function() {
|
$('#myModal-add-info').modal('show');
|
|
});
|
|
|
/**
|
* 导出Excel
|
*/
|
$(document).delegate('#expExcel','click',function() {
|
window.location.href=contextPath + "/shelfmanager/export";
|
});
|
|
/**
|
*查询
|
*/
|
$(document).delegate('#search','click',function() {
|
$('#myModal-search').modal('show');
|
});
|
|
/**
|
* 显示料架信息
|
*/
|
$(".vertical").mouseover(function(){
|
var $value=$(this).attr("value");
|
//发送ajax请求
|
$.ajax({
|
url:contextPath+"/shelfmanager/vertical?ajax=true&value="+$value,
|
type:"GET",
|
success: function(data){
|
var obj = eval('(' + data + ')');
|
$("#num").html(obj.number);
|
if(obj.state=="使用中"){
|
$("#gla").html(obj.glassId);
|
$("#hei").html(obj.length);
|
$("#wid").html(obj.width);
|
$("#thi").html(obj.thickness);
|
$("#pie").html(obj.pieces-obj.completePieces);
|
}
|
if(obj.state=="禁用"){
|
$("#sta").html("禁用");
|
}else{
|
$("#sta").html("启用");
|
}
|
},
|
});
|
|
$("#blockdiv").css({
|
"display":"block",
|
"left":$(this).position().left,
|
"top":$(this).position().top+50+"px",
|
});
|
});
|
|
/**
|
* 离开
|
*/
|
$(".vertical").bind("mouseout",function(){
|
$("#num").html("");
|
$("#gla").html("");
|
$("#hei").html("");
|
$("#wid").html("");
|
$("#thi").html("");
|
$("#pie").html("");
|
$("#sta").html("");
|
$("#blockdiv").css("display","none");
|
})
|
});
|