layui.use(['table', 'admin', 'ax', 'func'], function () {
var $ = layui.$;
var table = layui.table;
var $ax = layui.ax;
var admin = layui.admin;
var func = layui.func;
/**
* 生产工单管理
*/
var WorkOrder = {
tableId: "workOrderTable"
};
/**
* 初始化表格的列
*/
WorkOrder.initColumn = function () {
return [[
{type: 'checkbox'},
{field: 'id', hide: true, title: '主键id'},
{align: 'center', toolbar: '#tableBar', title: '操作',minWidth:330},
{field: 'workOrderCode', sort: true, title: '工单编号',width: 160},
{field: 'salesOrderCode', sort: true, title: '订单编号',width: 160},
{field: 'productCode', sort: true, title: '产品编号',width: 160},
{field: 'productName', sort: true, title: '产品名称',width: 160},
{field: 'planQty', sort: true, title: '计划数量',width: 120},
{field: 'produceQty', sort: true, title: '完成数量',width: 120},
{field: 'onlineQty', sort: true, title: '上线数量',width: 120},
{field: 'planStartTime', sort: true, title: '计划开始时间',width: 160},
{field: 'planEndTime', sort: true, title: '计划结束时间',width: 160},
{field: 'produceStartTime', sort: true, title: '生产开始时间',width: 160},
{field: 'produceEndTime', sort: true, title: '生产结束时间',width: 160},
{field: 'workshopCode', sort: true, title: '车间编码',width: 120},
{field: 'lineCode', sort: true, title: '产线编码',width: 120},
{field: 'state', sort: true, title: '状态',width: 120,templet: '#orderStatusTpl'},
{field: 'badQty', sort: true, title: '不良数量',width: 120},
{field: 'repairQty', sort: true, title: '返修数量',width: 120},
{field: 'scrapQty', sort: true, title: '报废数量',width: 120},
{field: 'routeCode', sort: true, title: '工艺流程',width: 120},
{field: 'bomCode', sort: true, title: '产品BOM',width: 160},
{field: 'recipeCode', sort: true, title: '工艺配方',width: 120},
{field: 'createUser', sort: true, title: '创建用户',width: 120},
{field: 'createTime', sort: true, title: '创建时间',width: 160},
{field: 'updateUser', sort: true, title: '更改用户',width: 120},
{field: 'updateTime', sort: true, title: '更改时间',width: 160},
{field: 'remark', sort: true, title: '备注',width: 160},
// {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
]];
};
/**
* 点击查询按钮
*/
WorkOrder.search = function () {
var queryData = {};
queryData['workOrderCode'] = $('#workOrderCode').val();
queryData['salesOrderCode'] = $('#salesOrderCode').val();
queryData['productCode'] = $('#productCode').val();
queryData['productName'] = $('#productName').val();
queryData['workshopCode'] = $('#workshopCode').val();
queryData['lineCode'] = $('#lineCode').val();
queryData['state'] = $('#state').val();
table.reload(WorkOrder.tableId, {
where: queryData, page: {curr: 1}
});
};
/**
* 跳转到添加页面
*/
WorkOrder.jumpAddPage = function () {
window.location.href = Feng.ctxPath + '/workOrder/add'
};
/**
* 跳转到编辑页面
*
* @param data 点击按钮时候的行数据
*/
WorkOrder.jumpEditPage = function (data) {
window.location.href = Feng.ctxPath + '/workOrder/edit?id=' + data.id
};
/**
* 导出excel按钮
*/
WorkOrder.exportExcel = function () {
var checkRows = table.checkStatus(WorkOrder.tableId);
if (checkRows.data.length === 0) {
Feng.error("请选择要导出的数据");
} else {
table.exportFile(tableResult.config.id, checkRows.data, 'xls');
}
};
/**
* 点击删除
*
* @param data 点击按钮时候的行数据
*/
WorkOrder.onDeleteItem = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/delete", function (data) {
Feng.success("删除成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!");
});
ajax.set("id", data.id);
ajax.start();
};
Feng.confirm("是否删除?", operation);
};
// 渲染表格
var tableResult = table.render({
elem: '#' + WorkOrder.tableId,
url: Feng.ctxPath + '/workOrder/list',
page: true,
height: "full-158",
cellMinWidth: 100,
cols: WorkOrder.initColumn()
});
// 搜索按钮点击事件
$('#btnSearch').click(function () {
WorkOrder.search();
});
// 添加按钮点击事件
$('#btnAdd').click(function () {
WorkOrder.jumpAddPage();
});
// 导出excel
$('#btnExp').click(function () {
WorkOrder.exportExcel();
});
//操作栏编辑
/**
* 点击开始工单
*/
WorkOrder.startOrder = function (data) {
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3");
var result = ajax.start();
if(result.data.length === 0) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) {
Feng.success("开始工单成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("开始工单失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
ajax.start();
};
Feng.confirm("是否开始生产?", operation);
}else {
layer.open({
title: "操作提示",
icon: 0,
closeBtn: 2,
area: ['450px', '200px'],
time: 5000,
content: '开始失败,只能有一条生产中的工单进行生产!'
});
}
};
/**
* 冻结工单
*/
WorkOrder.freezeOrder = function (data) {
console.log(data)
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) {
Feng.success("冻结工单成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("冻结工单失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
console.log(data)
ajax.start();
};
Feng.confirm("是否冻结工单?", operation);
};
/**
* 点击解冻工单
*/
WorkOrder.thawOrder = function (data) {
var ajax = new $ax(Feng.ctxPath + "/workOrder/list?state=3");
var result = ajax.start();
if(result.data.length === 0) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) {
Feng.success("解冻工单成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("解冻工单失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
ajax.start();
};
Feng.confirm("是否解冻工单?", operation);
}else {
layer.open({
title: "操作提示",
icon: 0,
closeBtn: 2,
area: ['450px', '200px'],
time: 5000,
content: '解冻失败,只能有一条生产中的工单进行生产!'
});
}
};
/**
* 关闭工单
*/
WorkOrder.closeOrder = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editOrderState", function (data) {
Feng.success("关闭工单成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("关闭工单失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
console.log(data)
ajax.start();
};
Feng.confirm("是否关闭工单?", operation);
};
/**
* 点击启用工单
*/
WorkOrder.enableOrder = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) {
Feng.success("启用工单成功!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("启用工单失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
ajax.start();
};
Feng.confirm("是否启用工单?", operation);
};
/**
* 点击完成
*
* @param data 点击按钮时候的行数据
*/
WorkOrder.finish = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/workOrder/editItem", function (data) {
Feng.success("已完成!");
table.reload(WorkOrder.tableId);
}, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!");
});
ajax.set(data);
ajax.start();
};
Feng.confirm("是否完成?", operation);
};
// 工具条点击事件
table.on('tool(' + WorkOrder.tableId + ')', function (obj) {
var data = obj.data;
var layEvent = obj.event;
console.log(data)
// if (layEvent === 'edit') {
// WorkOrder.jumpEditPage(data);
// } else if (layEvent === 'delete') {
// WorkOrder.onDeleteItem(data);
// }
if (layEvent === 'edit') {//编辑
WorkOrder.jumpEditPage(data);
}
else if (layEvent === 'start') {//开始
data.state = '3';
data.produceStartTime = getDateTime();
WorkOrder.startOrder(data);
}else if (layEvent === 'freeze') {//冻结
data.state = '4';
WorkOrder.freezeOrder(data);
}else if (layEvent === 'thaw') {//解冻
data.state = '3';
WorkOrder.thawOrder(data);
}else if (layEvent === 'close') {//关闭
data.state = '6';
WorkOrder.closeOrder(data);
}else if (layEvent === 'enable') {//启用
data.state = '1';
WorkOrder.enableOrder(data);
}else if (layEvent === 'delete') {
WorkOrder.onDeleteItem(data);
}else if (layEvent === 'finish') {//完成
data.state = '5';
data.produceEndTime = getDateTime();
WorkOrder.finish(data);
}
});
//获取当前日期
function getDateTime(){
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
let time = date.toLocaleTimeString();
// 对月份进行处理,1-9月在前面添加一个“0”
if (month >= 1 && month <= 9) {
month = "0" + month;
}
//对日期进行处理,1-9日在前面添加一个“0”
if (day >= 0 && day <= 9) {
day = "0" + day;
}
let separator = "-"; //添加分隔符“-”
this.dateTime = year + separator + month + separator + day + " " + time;
return this.dateTime;
}
});