/**
|
* 物料编码
|
*/
|
$(function(){
|
$('#test-table').bootstrapTable('destroy')
|
$('#test-table').bootstrapTable({
|
method : 'GET',
|
url: "basic/matCodeList.action",
|
cache : false,
|
striped : true,
|
pagination : true, //在表格底部显示分页工具栏
|
pageSize : 5, //默认每页条数
|
pageNumber : 1, //默认分页
|
pageList : [ 10, 20, 50, 100, 200, 500 ],//分页数
|
showColumns : true, //显示隐藏列
|
showRefresh : false, //显示刷新按钮
|
showExport : false,
|
toolbar:"#toolbar",
|
singleselect : true,
|
clickToSelect: true, // 单击行即可以选中
|
search : false,//显示搜素表单
|
silent : true, //刷新事件必须设置
|
sidePagination : "server", //表示服务端请求
|
columns : [ {
|
checkbox:true
|
}, {
|
field : "mat_no",
|
title : "物料编码",
|
class : 'col-md-3',
|
align : "left",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field : "mat_name",
|
title : "物料名称",
|
align : "left",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field : "str1",
|
title : "单位",
|
align : "left",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field : "str2",
|
title : "规格",
|
align : "left",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field : "modi_user",
|
title : "修改人员",
|
align : "center",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field : "modi_time",
|
title : "修改时间",
|
align : "center",
|
valign : "middle",
|
sortable : "true"
|
}, {
|
field: 'operate',
|
title: '操作',
|
class : 'col-md-2',
|
align: 'center',
|
valign: 'middle',
|
formatter: operateFormatter,
|
}],
|
queryParamsType: "undefined",
|
queryParams: function queryParams(params) { //设置查询参数
|
var param = {
|
pageNumber: params.pageNumber,
|
pageSize: params.pageSize,
|
mat_no:$("#mat_no2").val(),
|
mat_name:$("#mat_name2").val()
|
// searchText: params.searchText
|
};
|
return param;
|
},
|
formatLoadingMessage : function() {
|
return "请稍等,正在加载中...";
|
},
|
|
formatNoMatches : function() {
|
return '无符合条件的记录';
|
},
|
//注册加载子表的事件。注意下这里的三个参数!
|
onExpandRow: function (index, row, $detail) {
|
oInit.InitSubTable(index, row, $detail);
|
}
|
|
});
|
});
|
|
function operateFormatter(value, row, index) {
|
return [
|
'<button type="button" class=" btn btn-info" onclick="getvalue(\''+row.mat_no+'\')">修改</button>',
|
' <button class=" btn btn-danger" type="button" onclick="delMatCode(\''+row.mat_no+'\')">删除</button>'
|
].join('');
|
}
|
|
/**
|
* 条件查询
|
* @returns
|
*/
|
function getMatCodeByCon(){
|
// $("#test-table").bootstrapTable('refresh');
|
$("#test-table").bootstrapTable('refreshOptions',{pageNumber:1}); //分页后重新搜索时,初始化页码为1
|
}
|
|
function formValidator(){
|
$("#addForm").bootstrapValidator({
|
message: 'This value is not valid',
|
feedbackIcons: {
|
valid: 'glyphicon glyphicon-ok',
|
invalid: 'glyphicon glyphicon-remove',
|
validating: 'glyphicon glyphicon-refresh'
|
},
|
|
fields:{
|
mat_no:{
|
message: '物料编码验证失败',
|
validators:{
|
notEmpty:{message:'不能为空'},
|
stringLength:{max:50,message:'字符长度不能超过50'}
|
}
|
}
|
}
|
});
|
|
$("#myform").bootstrapValidator({
|
message: 'This value is not valid',
|
feedbackIcons: {
|
valid: 'glyphicon glyphicon-ok',
|
invalid: 'glyphicon glyphicon-remove',
|
validating: 'glyphicon glyphicon-refresh'
|
},
|
|
fields: {
|
mat_no:{
|
message: '物料编码验证失败',
|
validators:{
|
notEmpty:{message:'不能为空'},
|
stringLength:{max:50,message:'字符长度不能超过50'}
|
}
|
}
|
}
|
});
|
|
$("#importForm").bootstrapValidator({
|
fields:{
|
files:{
|
validators:{
|
notEmpty:{
|
message:"导入文件不能为空"
|
},
|
}
|
},
|
}
|
});
|
}
|
//表单验证
|
$(function(){
|
formValidator();
|
|
});
|
|
//添加部门,打开模态框
|
function addMatCode(){
|
$("#addDlg").modal('show');
|
}
|
|
//添加库位状态时验证是否唯一
|
function checkMatCode(){
|
var x=$("#mat_no1").val();
|
if(x!=""){
|
$.ajax({
|
url:'basic/checkMatCode.action',
|
dataType:'json',
|
type:'post',
|
data:{
|
did:$("#mat_no1").val()
|
},
|
success:function(data){
|
$("#info").text(data.msg);
|
},
|
error:function(){
|
alert("请求失败");
|
}
|
});
|
}else{
|
return false;
|
}
|
};
|
|
// 提交插入
|
function insertMatCode(){
|
var msg=$("#info").text();
|
if(msg=="代号可用"){
|
if($("#addForm").data('bootstrapValidator').validate().isValid()){
|
$.ajax({
|
url:'basic/addMatCode.action',
|
type:'post',
|
dataType:'json',
|
data:$("#addForm").serialize(),
|
success:function(info){
|
if(info>0){
|
alert("添加成功");
|
}else{
|
alert("添加失败");
|
}
|
$("#test-table").bootstrapTable('refresh');
|
$("#addDlg").modal('hide');
|
$("#mat_no1").val("");
|
$("#mat_name1").val("");
|
$("#str11").val("");
|
$("#str21").val("");
|
},
|
error:function(){
|
alert('请求失败');
|
}
|
});
|
}else{
|
return false;
|
}
|
}else{
|
alert("代号不可用");
|
}
|
}
|
|
|
//打开模态框,数据回写
|
function getvalue(id){
|
$.ajax({
|
url:'basic/queryMatCodeById.action',
|
type:'post',
|
dataType:'json',
|
data:{did:id},
|
success:function(data){
|
$("#mat_no").val(data.mat_no);
|
$("#mat_name").val(data.mat_name);
|
$("#str1").val(data.str1);
|
$("#str2").val(data.str2);
|
},
|
error:function(){
|
alert("请求失败");
|
}
|
});
|
$("#mydlg").modal("show");
|
}
|
|
//保存修改内容
|
function upMatCode(){
|
if($("#myform").data('bootstrapValidator').validate().isValid()){
|
$.ajax({
|
url:'basic/upMatCode.action',
|
type:'post',
|
dataType:'json',
|
data:$("#myform").serialize(),
|
success:function(data){
|
if(data>0){
|
alert("修改成功");
|
}else{
|
alert("修改失败");
|
}
|
$("#test-table").bootstrapTable('refresh');
|
$("#mydlg").modal("hide");
|
},
|
error:function(){
|
alert("请求失败");
|
}
|
});
|
}else{
|
return false;
|
}
|
}
|
|
//单个删除
|
function delMatCode(id){
|
if(confirm('您确定要删除这条数据吗')){
|
$.ajax({
|
url:'basic/delMatCode.action',
|
type:'post',
|
dataType:'json',
|
data:{did:id},
|
success:function(data){
|
if(data>0){
|
alert("删除成功");
|
}else{
|
alert("删除失败");
|
}
|
$("#test-table").bootstrapTable('refresh');
|
},
|
error:function(){
|
alert("请求失败");
|
}
|
});
|
}
|
}
|
|
//批量删除
|
function delMany(){
|
var idstr=[];
|
//获取选中的行
|
var a= $('#test-table').bootstrapTable('getSelections');
|
if(a.length>0){
|
if(confirm("您确定要删除选中的数据吗?")){
|
$.each(a,function(index){
|
idstr.push(a[index].mat_no);
|
alert();
|
});
|
if(idstr.indexOf(1)>=0){
|
alert('系统默认用户,不能删除');
|
return;
|
}
|
$.ajax({
|
url:'user/delMatCodes.action',
|
dataType:'json',
|
type:'post',
|
traditional:true,
|
data:{
|
ids:idstr
|
},
|
success:function(data){
|
if(data>0){
|
alert("删除成功!");
|
}else{
|
alert("删除失败!");
|
}
|
$('#test-table').bootstrapTable('refresh');
|
},
|
error:function(){
|
alert("请求失败!");
|
}
|
});
|
}else{
|
return false;
|
}
|
}else{
|
alert("请至少选中一行数据");
|
}
|
}
|
|
//打开 导入
|
function ImportExcel(){
|
$("#importDlg").modal('show');
|
}
|
//导入
|
function importExcel(){
|
if($("#importForm").data('bootstrapValidator').validate().isValid()){
|
$.ajax({
|
url:'basic/importMatCode.action',
|
dataType:'json',
|
type:'post',
|
data:new FormData($("#importForm")[0]),
|
contentType: false, //必须false才会避开jQuery对 formdata 的默认处理
|
processData: false, //必须false才会自动加上正确的Content-Type
|
success:function(data){
|
if(data.flag){
|
alert("导入成功!"+data.msg);
|
}else{
|
alert("导入失败!"+data.msg);
|
}
|
closedlg();
|
$("#test-table").bootstrapTable('refresh');
|
},
|
error:function(){
|
alert("请求失败!");
|
}
|
});
|
}else{
|
return false;
|
}
|
}
|
|
//导出
|
function ExportExcel(){
|
if(confirm("确认导出excel?")){
|
var url = "basic/exportMatCode.action?";
|
url += "mat_no=" + $("#mat_no2").val();
|
url += "&mat_name=" + $("#mat_name2").val();
|
location.href=url;
|
}else{
|
return false;
|
}
|
}
|
|
//关闭模态框
|
function closedlg(){
|
$("#mydlg").modal("hide");
|
$("#addDlg").modal("hide")
|
$("#importDlg").modal('hide');
|
$("#info").text("");
|
$("#infos").text("");
|
|
$("input[type=reset]").trigger("click");
|
$('#importForm').data('bootstrapValidator', null);
|
$('#myform').data('bootstrapValidator', null);
|
$("#addForm").data('bootstrapValidator',null);
|
formValidator();
|
//$('#mydlg').data('bootstrapValidator').resetForm(true);
|
$("input[type=reset]").trigger("click");
|
}
|