var pageCurr;
|
function right(){
|
top.popupRight = top.layui.admin.popupRight({
|
id: 'LAY_adminPopupLayerTest'
|
, area: '750px'
|
, type: 2
|
, content:'custOrder/matQuery.html'
|
, success: function(){
|
// $('#'+ this.id).html('<div style="padding: 20px;">放入内容</div>');
|
//admin.view(this.id).render('system/xxx')
|
}
|
, end: function () {
|
$(".layui-laypage-btn")[0].click();
|
}
|
});
|
}
|
layui.config({
|
base: baseUrl + "/static/layui/lay/modules/" // 配置模块所在的目录
|
}).use(['table', 'laydate', 'form', 'tableX'], function(){
|
var table = layui.table;
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var layDate = layui.laydate;
|
var form = layui.form;
|
var tableX = layui.tableX;
|
|
// 数据渲染
|
tableIns = table.render({
|
elem: '#custOrder',
|
headers: {token: localStorage.getItem('token')},
|
url: baseUrl+'/custOrder/list/auth',
|
page: true,
|
limit: 16,
|
limits: [16, 30, 50, 100, 200, 500],
|
even: true,
|
toolbar: '#toolbar',
|
cellMinWidth: 50,
|
cols: [[
|
{type: 'checkbox'}
|
// ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
|
,{field: 'number', align: 'center',title: '销售单号'}
|
|
,{field: 'btypeId', align: 'center',title: '客户编号'}
|
,{field: 'etypeId', align: 'center',title: '经手人编号', hide: true}
|
,{field: 'userCode', align: 'center',title: '商品编号'}
|
,{field: 'qty', align: 'center',title: '商品数量'}
|
,{field: 'price', align: 'center',title: '商品单价', hide: true}
|
,{field: 'comment', align: 'center',title: '商品备注', hide: true}
|
,{field: 'status$', align: 'center',title: '状态', templet: '#statusTpl', width: 100}
|
,{field: 'billDate', align: 'center',title: '单据日期'}
|
// ,{field: 'createTime$', align: 'center',title: '添加时间'}
|
,{field: 'updateTime$', align: 'center',title: '修改时间', hide: true}
|
// ,{field: 'memo', align: 'center',title: '备注'}
|
|
,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 120}
|
]],
|
request: {
|
pageName: 'curr',
|
pageSize: 'limit'
|
},
|
parseData: function (res) {
|
return {
|
'code': res.code,
|
'msg': res.msg,
|
'count': res.data.total,
|
'data': res.data.records
|
}
|
},
|
response: {
|
statusCode: 200
|
},
|
done: function(res, curr, count) {
|
if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
}
|
pageCurr=curr;
|
tableX.merges('custOrder', [1, 11]);
|
limit();
|
form.on('checkbox(tableCheckbox)', function (data) {
|
var _index = $(data.elem).attr('table-index')||0;
|
if(data.elem.checked){
|
res.data[_index][data.value] = 'Y';
|
}else{
|
res.data[_index][data.value] = 'N';
|
}
|
});
|
}
|
});
|
|
// 监听排序事件
|
table.on('sort(locMast)', function (obj) {
|
var searchData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
searchData[this.name] = this.value;
|
});
|
searchData['orderByField'] = obj.field;
|
searchData['orderByType'] = obj.type;
|
tableIns.reload({
|
where: searchData,
|
page: {
|
curr: 1
|
},
|
done: function (res, curr, count) {
|
if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
}
|
pageCurr=curr;
|
limit();
|
}
|
});
|
});
|
|
// 监听头工具栏事件
|
table.on('toolbar(custOrder)', function (obj) {
|
var checkStatus = table.checkStatus(obj.config.id);
|
switch(obj.event) {
|
case 'deleteData':
|
var data = checkStatus.data;
|
if (data.length === 0){
|
layer.msg('请选择数据');
|
} else {
|
layer.confirm('确定删除'+(data.length===1?'此':data.length)+'条数据吗', function(){
|
$.ajax({
|
url: baseUrl+"/custOrder/delete/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {param: JSON.stringify(data)},
|
method: 'POST',
|
traditional:true,
|
success: function (res) {
|
if (res.code === 200){
|
layer.closeAll();
|
$(".layui-laypage-btn")[0].click();
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
});
|
}
|
break;
|
case 'exportData':
|
layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){
|
var titles=[];
|
var fields=[];
|
obj.config.cols[0].map(function (col) {
|
if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
|
titles.push(col.title);
|
fields.push(col.field);
|
}
|
});
|
var exportData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
exportData[this.name] = this.value;
|
});
|
var param = {
|
'custOrder': exportData,
|
'fields': fields
|
};
|
$.ajax({
|
url: baseUrl+"/custOrder/export/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: JSON.stringify(param),
|
dataType:'json',
|
contentType:'application/json;charset=UTF-8',
|
method: 'POST',
|
success: function (res) {
|
layer.closeAll();
|
if (res.code === 200) {
|
table.exportFile(titles,res.data,'xls');
|
} else if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
});
|
});
|
break;
|
}
|
});
|
|
// 监听行工具事件
|
table.on('tool(custOrder)', function(obj){
|
var data = obj.data;
|
switch (obj.event) {
|
// 拣货
|
case 'stockOut':
|
var loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl + "/work/stock/out/preview",
|
headers: {'token': localStorage.getItem('token')},
|
contentType: 'application/json;charset=UTF-8',
|
data: JSON.stringify({
|
number: data.number
|
}),
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
// 成功
|
if (res.code === 200){
|
layer.open({
|
type: 1
|
,title: false
|
,closeBtn: false
|
,offset: '100px'
|
// ,area: ['800px','450px']
|
,area: '1000px'
|
,shade: 0.5
|
,shadeClose: true
|
,id: 'LAY_layuipro'
|
,btn: ['立即生成', '稍后处理']
|
,btnAlign: 'c'
|
,moveType: 1 //拖拽模式,0或者1
|
,content: $('#stoukOutPreview')
|
,success: function(layero, index){
|
table.render({
|
elem: '#stoPreTab',
|
data: res.data,
|
page: true,
|
cellMinWidth: 100,
|
// ,width: admin.screen() > 1 ? 892 : ''
|
height: 432,
|
cols: [[
|
{field: 'title', title: '商品', align: 'center'},
|
{field: 'anfme', title: '总数量', align: 'center', style: 'font-weight: bold', width: 90},
|
{field: 'type', title: '仓库', align: 'center', templet: '#typeTpl', width: 90},
|
{field: 'locNo', title: '货位', align: 'center'},
|
{field: 'prior$', title: '推荐货位', align: 'center', width: 100},
|
{field: 'reduce', title: '数量', align: 'center', width: 90, style: 'font-weight: bold'},
|
// {field: 'remQty', title: '余量', align: 'center', width: 80},
|
{field: 'total', title: '总量', align: 'center', width: 90},
|
]],
|
done: function () {
|
tableX.merges('stoPreTab', [0,1,2]);
|
$('.layui-table-body.layui-table-main').css("overflow", "auto")
|
}
|
});
|
|
}
|
,yes: function(index, layero){
|
//按钮【马上拣货】的回调
|
stockOut(data.number);
|
}
|
,btn2: function(index, layero){
|
//按钮【稍后处理】的回调
|
//return false 开启该代码可禁止点击该按钮关闭
|
}
|
});
|
// 缺料
|
} else if (res.code === 20001) {
|
layer.confirm(res.msg, {
|
shadeClose: true
|
, area: ['400px']
|
, btn: ['库存调拨', '取消']
|
}, function() {
|
// 库存调拨
|
stockTransfer(data.number);
|
layer.closeAll();
|
}, function() {
|
// printPakouts(data.number);
|
layer.closeAll();
|
}
|
)
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg, {icon: 1})
|
}
|
}
|
})
|
break;
|
// 打印
|
case 'print':
|
layer.confirm('开始打印' +data.number + ' 拣货单?', {shadeClose: true}, function(){
|
layer.closeAll();
|
printPakouts(data.number);
|
})
|
break;
|
|
}
|
});
|
|
// 开始拣货
|
function stockOut(number) {
|
// layer.confirm(number + ' 订单开始拣货?', {shadeClose: true}, function(){
|
layer.closeAll();
|
$.ajax({
|
url: baseUrl+"/work/stock/out",
|
headers: {'token': localStorage.getItem('token')},
|
contentType:'application/json;charset=UTF-8',
|
data: JSON.stringify({
|
number: number
|
}),
|
method: 'POST',
|
success: function (res) {
|
// 成功
|
if (res.code === 200){
|
layer.confirm(res.msg, {
|
shadeClose: true
|
, btn: ['打印拣货单']
|
}, function() {
|
layer.closeAll();
|
printPakouts(number);
|
}
|
)
|
// 缺料
|
} else if (res.code === 20001) {
|
layer.confirm(res.msg, {
|
shadeClose: true
|
, btn: ['库存调拨', '取消']
|
}, function() {
|
// 库存调拨
|
layer.closeAll();
|
}, function() {
|
alert(number)
|
layer.closeAll();
|
}
|
)
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
$(".layui-laypage-btn")[0].click();
|
}
|
})
|
// });
|
}
|
|
// 库存调拨
|
function stockTransfer(number) {
|
|
$.ajax({
|
url: baseUrl + "/work/stock/transfer",
|
headers: {'token': localStorage.getItem('token')},
|
data: {
|
number: number
|
},
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200) {
|
layer.msg(res.msg, {icon: 1})
|
} else if (res.code === 403) {
|
top.location.href = baseUrl + "/";
|
} else {
|
layer.msg(res.msg, {icon: 2})
|
}
|
}
|
});
|
}
|
|
// 打印拣货单
|
function printPakouts(docNumber) {
|
$.ajax({
|
url: baseUrl+"/work/stock/out/print",
|
headers: {'token': localStorage.getItem('token')},
|
data: JSON.stringify({
|
number: docNumber
|
}),
|
contentType:'application/json;charset=UTF-8',
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200){
|
res.data["barcodeUrl"]=baseUrl+"/custOrder/code/auth?type=1¶m="+res.data.docNum;
|
var tpl = $('#pakoutPrintTpl').html();
|
var template = Handlebars.compile(tpl);
|
var html = template(res);
|
var box = $("#pakoutPrintBox");
|
box.html(html);box.show();
|
box.print({
|
mediaPrint:true,
|
deferred: $.Deferred().done(function () {
|
layer.confirm('[重要] 打印是否成功?', {btn: ['Yes', 'No']}, function(){
|
$.ajax({
|
url: baseUrl+"/pakout/print/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {
|
docNumber: docNumber
|
},
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200){
|
layer.closeAll();
|
$(".layui-laypage-btn")[0].click();
|
layer.msg(res.msg, {icon: 1})
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg, {icon: 2})
|
}
|
}
|
})
|
});
|
})
|
});
|
box.hide();
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg, {icon: 2})
|
}
|
}
|
})
|
}
|
|
// 数据保存动作
|
form.on('submit(save)', function () {
|
if (banMsg != null){
|
layer.msg(banMsg);
|
return;
|
}
|
method("add");
|
});
|
|
// 数据修改动作
|
form.on('submit(edit)', function () {
|
method("update")
|
});
|
|
function method(name){
|
var index = layer.load(1, {
|
shade: [0.5,'#000'] //0.1透明度的背景
|
});
|
var data = {
|
// id: $('#id').val(),
|
number: $('#number').val(),
|
billDate: $('#billDate').val(),
|
bTypeId: $('#bTypeId').val(),
|
eTypeId: $('#eTypeId').val(),
|
userCode: $('#userCode').val(),
|
qty: $('#qty').val(),
|
price: $('#price').val(),
|
comment: $('#comment').val(),
|
status: $('#status').val(),
|
createTime: top.strToDate($('#createTime\\$').val()),
|
updateTime: top.strToDate($('#updateTime\\$').val()),
|
memo: $('#memo').val(),
|
|
};
|
$.ajax({
|
url: baseUrl+"/custOrder/"+name+"/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: top.reObject(data),
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200){
|
parent.layer.closeAll();
|
parent.$(".layui-laypage-btn")[0].click();
|
$("#data-detail :input").each(function () {
|
$(this).val("");
|
});
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
}else {
|
layer.msg(res.msg)
|
}
|
layer.close(index);
|
}
|
})
|
}
|
|
// 复选框事件
|
form.on('checkbox(detailCheckbox)', function (data) {
|
var el = data.elem;
|
if (el.checked) {
|
$(el).val('Y');
|
} else {
|
$(el).val('N');
|
}
|
});
|
|
// 搜索栏搜索事件
|
form.on('submit(search)', function (data) {
|
pageCurr = 1;
|
tableReload(false);
|
});
|
|
// 搜索栏重置事件
|
form.on('submit(reset)', function (data) {
|
pageCurr = 1;
|
clearFormVal($('#search-box'));
|
tableReload(false);
|
});
|
|
// 时间选择器
|
layDate.render({
|
elem: '#createTime\\$',
|
type: 'datetime'
|
});
|
layDate.render({
|
elem: '#updateTime\\$',
|
type: 'datetime'
|
});
|
|
|
});
|
|
// 关闭动作
|
$(document).on('click','#data-detail-close', function () {
|
parent.layer.closeAll();
|
});
|
|
function tableReload(child) {
|
var searchData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
searchData[this.name] = this.value;
|
});
|
(child ? parent.tableIns : tableIns).reload({
|
where: searchData,
|
page: {
|
curr: pageCurr
|
},
|
// done: function (res, curr, count) {
|
// if (res.code === 403) {
|
// top.location.href = baseUrl+"/";
|
// }
|
// pageCurr=curr;
|
// if (res.data.length === 0 && count !== 0) {
|
// tableIns.reload({
|
// where: searchData,
|
// page: {
|
// curr: pageCurr-1
|
// }
|
// });
|
// pageCurr -= 1;
|
// }
|
// limit(child);
|
// }
|
});
|
}
|
|
function setFormVal(el, data, showImg) {
|
for (var val in data) {
|
var find = el.find(":input[id='" + val + "']");
|
if (find[0]!=null){
|
if (find[0].type === 'checkbox'){
|
if (data[val]==='Y'){
|
find.attr("checked","checked");
|
find.val('Y');
|
} else {
|
find.remove("checked");
|
find.val('N');
|
}
|
continue;
|
}
|
}
|
find.val(data[val]);
|
if (showImg){
|
var next = find.next();
|
if (next.get(0)){
|
if (next.get(0).localName === "img") {
|
find.hide();
|
next.attr("src", data[val]);
|
next.show();
|
}
|
}
|
}
|
}
|
}
|
|
function clearFormVal(el) {
|
$(':input', el)
|
.val('')
|
.removeAttr('checked')
|
.removeAttr('selected');
|
}
|
|
function detailScreen(index) {
|
var detail = layer.getChildFrame('#data-detail', index);
|
var height = detail.height()+60;
|
if (height > ($(window).height()*0.9)) {
|
height = ($(window).height()*0.8);
|
}
|
layer.style(index, {
|
// top: (($(window).height()-height)/3)+"px",
|
height: height+'px'
|
});
|
}
|
|
$('body').keydown(function () {
|
if (event.keyCode === 13) {
|
$("#search").click();
|
}
|
});
|