631 lines
17 KiB
JavaScript
631 lines
17 KiB
JavaScript
define(["app", "moment"],
|
|
function (app, moment) {
|
|
return ["$scope", "$filter", "$rootScope", "config", "$mdDialog", "DashboardService", "$http", "$stateParams",
|
|
"MMWService", "$location", "$timeout",
|
|
function ($scope, $filter, $rootScope, config, $mdDialog, $DashboardService, $http, $stateParams,
|
|
$MMWService, $location, $timeout) {
|
|
|
|
$scope.area = ""; //區預編號
|
|
$scope.op = ""; //作業站編號
|
|
$scope.mono = ""; //工單編號
|
|
$scope.plot = ""; //生產批編號
|
|
$scope.machine_plot = ""; //生產批編號
|
|
$scope.nowtime = moment().format('YYYY-MM-DD'); //派工日期
|
|
$scope.machineList = []; //設備清單
|
|
$scope.plotList = []; //產批清單
|
|
$scope.selectAll = false; //是否全選
|
|
$scope.machineShow = false; //設備派工資訊flag
|
|
$scope.machineLotList = [];
|
|
$scope.machineLotOrgList = [];
|
|
|
|
var allMachineLotList = {};
|
|
var existsEQPLot = {};
|
|
var machineNoList = []; //設備編號清單
|
|
var eqpHideInfo = []; //machine隱藏資訊
|
|
var searchTime; //搜尋派工日期,因變更日期無法重置搜尋結果,派工已searchTime為主
|
|
|
|
const input_controls = {
|
|
input_area: {
|
|
title: $filter('translate')('common.msg.plz_select'),
|
|
list: [],
|
|
key: "AREANO"
|
|
},
|
|
input_op: {
|
|
title: $filter('translate')('common.msg.plz_select'),
|
|
list: [],
|
|
key: "OPNO"
|
|
},
|
|
input_mo: {
|
|
title: $filter('translate')('common.msg.plz_select'),
|
|
list: [],
|
|
key: "MONO"
|
|
}
|
|
};
|
|
|
|
$scope.init = function () {
|
|
|
|
LoadBasis(function (data, methods) {
|
|
var dsArea = JSON.parse(data[methods[1]]);
|
|
var dsOP = JSON.parse(data[methods[0]]);
|
|
var dsMO = JSON.parse(data[methods[2]]);
|
|
var dtArea = dsArea["SMDAreaBasis"];
|
|
var dtOP = dsOP["OPArea"];
|
|
var dtMO = dsMO["OEMOBasis"];
|
|
input_controls['input_area'].list = dtArea;
|
|
input_controls['input_op'].list = dtOP;
|
|
input_controls['input_mo'].list = dtMO;
|
|
});
|
|
|
|
}
|
|
|
|
//前一天
|
|
$scope.pervDay = function () {
|
|
if (!$scope.machineShow)
|
|
$scope.nowtime = moment($scope.nowtime).add(-1, 'days').format("YYYY/MM/DD");
|
|
}
|
|
|
|
//下一天
|
|
$scope.nextDay = function () {
|
|
if (!$scope.machineShow)
|
|
$scope.nowtime = moment($scope.nowtime).add(1, 'days').format("YYYY/MM/DD");
|
|
}
|
|
|
|
$scope.showSelect = function (event) {
|
|
var id = event.path[0].id;
|
|
|
|
if (id == "input_op" && !$scope.area)
|
|
return;
|
|
|
|
var list = input_controls[id].list;
|
|
if (id == "input_op") {
|
|
var selectList = [];
|
|
var i = 0;
|
|
for (i = 0; i < list.length; i++) {
|
|
if (list[i].AREANO == $scope.area)
|
|
selectList.push(list[i]);
|
|
}
|
|
list = selectList;
|
|
}
|
|
|
|
selectDialog(input_controls[id].title, list, input_controls[id].key);
|
|
}
|
|
|
|
$scope.clickSelect = function () {
|
|
if (!($scope.plotList.length > 0)) {
|
|
$scope.selectAll = false;
|
|
return;
|
|
}
|
|
else
|
|
$scope.selectAll = !$scope.selectAll;
|
|
|
|
var i = 0;
|
|
for (i = 0; i < $scope.plotList.length; i++) {
|
|
$scope.plotList[i].isSelect = $scope.selectAll;
|
|
console.log(i);
|
|
checkMachineHide($scope.plotList[i].isSelect, $scope.plotList[i].LOTNO);
|
|
}
|
|
}
|
|
|
|
$scope.itemClickSelect = function (item) {
|
|
$scope.selectAll = false;
|
|
item.isSelect = !item.isSelect;
|
|
checkMachineHide(item.isSelect, item.LOTNO);
|
|
}
|
|
|
|
//清除搜尋Input
|
|
$scope.clear = function () {
|
|
$scope.mono = "";
|
|
$scope.plot = "";
|
|
resetSearchResult();
|
|
}
|
|
|
|
$scope.search = function () {
|
|
if (!$scope.mono || !$scope.op || !$scope.nowtime)
|
|
return;
|
|
|
|
searchTime = $scope.nowtime;
|
|
|
|
LoadDispatchState_LotStateData(function (data) {
|
|
$scope.plotList = data['DispatchState_LotStateData'];
|
|
$scope.selectAll = false;
|
|
existsEQPLot = [];
|
|
$scope.plot = "";
|
|
|
|
resetHide();
|
|
|
|
LoadWIPEQPDispatch_And_Arrange($scope.nowtime);
|
|
});
|
|
}
|
|
|
|
$scope.machineClick = function (item) {
|
|
var selectList = [];
|
|
var i = 0;
|
|
for (i = 0; i < $scope.plotList.length; i++) {
|
|
if ($scope.plotList[i].isSelect)
|
|
selectList.push($scope.plotList[i].LOTNO);
|
|
}
|
|
|
|
if (selectList.length > 0) {
|
|
dispatch_process(item.EQUIPMENTNO, selectList, $scope.op, searchTime, function (data) {
|
|
$scope.search();
|
|
})
|
|
}
|
|
else
|
|
machineLotInfoShow(item);
|
|
}
|
|
|
|
$scope.back = function () {
|
|
$scope.machineShow = false;
|
|
}
|
|
|
|
$scope.machine_search = function () {
|
|
if (!$scope.machine_plot)
|
|
return;
|
|
|
|
var list = [];
|
|
var i = 0;
|
|
for (i = 0; i < $scope.machineLotOrgList.length; i++) {
|
|
if ($scope.machineLotOrgList[i].LOTNO == $scope.machine_plot) {
|
|
list.push($scope.machineLotOrgList[i]);
|
|
$scope.machineLotList = list;
|
|
}
|
|
}
|
|
|
|
$scope.machine_plot = "";
|
|
}
|
|
|
|
$scope.machine_clear = function () {
|
|
$scope.machine_plot = "";
|
|
$scope.machineLotList = $scope.machineLotOrgList;
|
|
}
|
|
|
|
$scope.machine_delete = function (item) {
|
|
dispatch_delete_process(item, function (data) {
|
|
LoadWIPEQPDispatch_And_Arrange(item.DISPATCHDATE, function () {
|
|
if (allMachineLotList[item.EQUIPMENTNO]) {
|
|
$scope.machineLotList = allMachineLotList[item.EQUIPMENTNO];
|
|
$scope.machineLotOrgList = allMachineLotList[item.EQUIPMENTNO];
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
$scope.machine_up = function (item) {
|
|
if ($scope.machineLotList.length <= 1)
|
|
return;
|
|
|
|
if (item.DISPATCHORDER <= 1)
|
|
return;
|
|
|
|
var order = item.DISPATCHORDER - 1;
|
|
var plot;
|
|
var i = 0;
|
|
for (i = 0; i < $scope.machineLotList.length; i++) {
|
|
if ($scope.machineLotList[i].DISPATCHORDER == order) {
|
|
plot = $scope.machineLotList[i].LOTNO;
|
|
break;
|
|
}
|
|
}
|
|
var orderInfo = [
|
|
{
|
|
plot_no: item.LOTNO,
|
|
dispatch_order: order
|
|
},
|
|
{
|
|
plot_no: plot,
|
|
dispatch_order: item.DISPATCHORDER
|
|
}
|
|
];
|
|
|
|
dispatch_order_update_process(item, orderInfo, function (data) {
|
|
LoadWIPEQPDispatch_And_Arrange(item.DISPATCHDATE, function () {
|
|
if (allMachineLotList[item.EQUIPMENTNO]) {
|
|
$scope.machineLotList = allMachineLotList[item.EQUIPMENTNO];
|
|
$scope.machineLotOrgList = allMachineLotList[item.EQUIPMENTNO];
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
$scope.machine_down = function (item) {
|
|
if ($scope.machineLotList.length <= 1)
|
|
return;
|
|
|
|
var maxOrder = 0;
|
|
var order = item.DISPATCHORDER + 1;
|
|
var plot;
|
|
for (i = 0; i < $scope.machineLotList.length; i++) {
|
|
if ($scope.machineLotList[i].DISPATCHORDER > maxOrder) {
|
|
maxOrder = $scope.machineLotList[i].DISPATCHORDER;
|
|
}
|
|
if ($scope.machineLotList[i].DISPATCHORDER == order) {
|
|
plot = $scope.machineLotList[i].LOTNO;
|
|
}
|
|
}
|
|
if (item.DISPATCHORDER == maxOrder)
|
|
return;
|
|
|
|
|
|
var orderInfo = [
|
|
{
|
|
plot_no: item.LOTNO,
|
|
dispatch_order: order
|
|
},
|
|
{
|
|
plot_no: plot,
|
|
dispatch_order: item.DISPATCHORDER
|
|
}
|
|
];
|
|
|
|
dispatch_order_update_process(item, orderInfo, function (data) {
|
|
LoadWIPEQPDispatch_And_Arrange(item.DISPATCHDATE, function () {
|
|
if (allMachineLotList[item.EQUIPMENTNO]) {
|
|
$scope.machineLotList = allMachineLotList[item.EQUIPMENTNO];
|
|
$scope.machineLotOrgList = allMachineLotList[item.EQUIPMENTNO];
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function resetSearchResult() {
|
|
$scope.plotList = [];
|
|
$scope.selectAll = false;
|
|
existsEQPLot = {};
|
|
eqpHideInfo = [];
|
|
}
|
|
|
|
function resetHide() {
|
|
eqpHideInfo = [];
|
|
var i = 0;
|
|
for (i = 0; i < $scope.machineList.length; i++)
|
|
$scope.machineList[i].isHide = false;
|
|
}
|
|
|
|
function checkMachineHide(isSelect, lot) {
|
|
if (isSelect) {
|
|
if (existsEQPLot[lot]) {
|
|
var i = 0;
|
|
for (i = 0; i < existsEQPLot[lot].length; i++) {
|
|
var eqp = existsEQPLot[lot][i];
|
|
var index = machineNoList.indexOf(eqp);
|
|
if (index >= 0) {
|
|
$scope.machineList[index].isHide = true;
|
|
var flag = true;
|
|
var k = 0;
|
|
for (k = 0; k < eqpHideInfo.length; k++) {
|
|
if (eqpHideInfo[k].machine == eqp) {
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (flag) {
|
|
var hideInfo = {
|
|
machine: eqp,
|
|
lotList: []
|
|
};
|
|
eqpHideInfo.push(hideInfo);
|
|
}
|
|
k = 0;
|
|
for (k = 0; k < eqpHideInfo.length; k++) {
|
|
if (eqpHideInfo[k].machine == eqp) {
|
|
if (!eqpHideInfo[k].lotList.includes(lot))
|
|
eqpHideInfo[k].lotList.push(lot);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
var i = 0;
|
|
for (i = 0; i < eqpHideInfo.length; i++) {
|
|
var index = eqpHideInfo[i].lotList.indexOf(lot);
|
|
if (index >= 0) {
|
|
eqpHideInfo[i].lotList.splice(index, 1);
|
|
if (eqpHideInfo[i].lotList.length <= 0) {
|
|
var machineIndex = machineNoList.indexOf(eqpHideInfo[i].machine);
|
|
$scope.machineList[machineIndex].isHide = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function selectDialog(title, list, key) {
|
|
$rootScope.showSelect({
|
|
title: title,
|
|
label: key,
|
|
code: key,
|
|
order: key,
|
|
selectCode: '',
|
|
list: list,
|
|
|
|
confirm: function (s_item, s_dialog) {
|
|
s_dialog.hide();
|
|
|
|
if (s_item.OPNO)
|
|
$scope.op = s_item.OPNO;
|
|
else if (s_item.MONO)
|
|
$scope.mono = s_item.MONO;
|
|
else {
|
|
$scope.area = s_item.AREANO;
|
|
$scope.op = "";
|
|
$scope.machineList = [];
|
|
}
|
|
|
|
resetSearchResult();
|
|
|
|
if ($scope.op && $scope.area) {
|
|
LoadAreaEquipment_All(function (data) {
|
|
$scope.machineList = data['AreaEquipment_All'];
|
|
$scope.machineList.forEach(item=> {
|
|
if (item.EQPLOADPORT = "-1") item.EQPLOADPORT = "NA";
|
|
if (item.CAPACITY = "-1") item.CAPACITY = "NA";
|
|
item.LotCount = 0;
|
|
item.SumQty = 0;
|
|
});
|
|
|
|
var list = [];
|
|
var i = 0;
|
|
for (i = 0; i < $scope.machineList.length; i++)
|
|
list.push($scope.machineList[i].EQUIPMENTNO);
|
|
machineNoList = list;
|
|
|
|
LoadWIPEQPDispatch_And_Arrange($scope.nowtime);
|
|
});
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
function machineLotInfoShow(eqp) {
|
|
$scope.machineLotList = [];
|
|
$scope.machineLotOrgList = [];
|
|
|
|
$scope.machineShow = true;
|
|
if (allMachineLotList[eqp.EQUIPMENTNO]) {
|
|
$scope.machineLotList = allMachineLotList[eqp.EQUIPMENTNO];
|
|
$scope.machineLotOrgList = allMachineLotList[eqp.EQUIPMENTNO];
|
|
}
|
|
}
|
|
|
|
function LoadWIPEQPDispatch_And_Arrange(disDate, callback) {
|
|
LoadWIPEQPDispatchState(disDate, function (data, methods, machines) {
|
|
var allEQPLot = {};
|
|
|
|
var i = 0;
|
|
for (i = 0; i < methods.length; i++) {
|
|
var index = i + 1;
|
|
var key = methods[i];
|
|
if (index > 1)
|
|
key = key + '(' + index + ')';
|
|
var ds = JSON.parse(data[key]);
|
|
var dt = ds['ShowWIPEQPDispatchStateJoinLotState'];
|
|
var j = 0;
|
|
for (j = 0; j < dt.length; j++)
|
|
dt[j].DISPATCHDATE = moment(dt[j].DISPATCHDATE).format("YYYY/MM/DD");
|
|
|
|
var j = 0;
|
|
for (j = 0; j < dt.length; j++) {
|
|
if (!allEQPLot[dt[j].LOTNO])
|
|
allEQPLot[dt[j].LOTNO] = [];
|
|
allEQPLot[dt[j].LOTNO].push(dt[j].EQUIPMENTNO);
|
|
}
|
|
existsEQPLot = allEQPLot;
|
|
|
|
var eqp = machines[i];
|
|
if (eqp)
|
|
allMachineLotList[eqp] = dt;
|
|
|
|
for (var i = 0; i < $scope.machineList.length; i++) {
|
|
var item = $scope.machineList[i];
|
|
if (item.EQUIPMENTNO == eqp)
|
|
{
|
|
item.LotCount = dt.length;
|
|
item.SumQty = 0;
|
|
dt.forEach(item2=> {
|
|
item.SumQty += item2.CURQTY;
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
|
|
//2020/10/12 Grace 手動派工調整: Grid在作業站後,再新增一欄, 已派工之EquipmentNo,若有多台,以逗號分隔顯示.
|
|
if (existsEQPLot != undefined && i == methods.length-1 ) {
|
|
var strEQPList = "";
|
|
|
|
if ($scope.plotList.length > 0){
|
|
for (var index in $scope.plotList){
|
|
var item = $scope.plotList[index];
|
|
strEQPList = "";
|
|
|
|
if (existsEQPLot[item.LOTNO]){
|
|
if (existsEQPLot[item.LOTNO].length > 0){
|
|
|
|
for (var index2 in existsEQPLot[item.LOTNO]){
|
|
strEQPList += existsEQPLot[item.LOTNO][index2].toString() + ",";
|
|
}
|
|
if (strEQPList.length > 1) {
|
|
strEQPList = strEQPList.substring(0, strEQPList.length-1);
|
|
}
|
|
}
|
|
}
|
|
|
|
$scope.plotList[index].DispatchEQPNo =strEQPList;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (callback)
|
|
callback();
|
|
}
|
|
});
|
|
}
|
|
|
|
function LoadBasis(callback) {
|
|
var methods = ['kcOP.clsOpBasis.LoadOPArea', 'kcSMD.clsSMDBasis.LoadAreaBasis', 'kcWIP.clsLot.LoadMOBasis'];
|
|
var contents = [];
|
|
var opContent = {};
|
|
var areaContent = {};
|
|
var moContent = { MOState: "3|6" };
|
|
contents.push(opContent);
|
|
contents.push(areaContent);
|
|
contents.push(moContent);
|
|
|
|
$MMWService.sendToMESSrv_Multi(
|
|
{
|
|
uri: methods,
|
|
content: contents,
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data, methods);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function LoadAreaEquipment_All(callback) {
|
|
$MMWService.sendToMESSrv(
|
|
{
|
|
uri: 'kcWIP.clsWIP.LoadAreaEquipment_All',
|
|
content:
|
|
{
|
|
areano: $scope.area
|
|
},
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function LoadWIPEQPDispatchState(disDate, callback) {
|
|
var method = 'kcWIP.clsMDS.ShowWIPEQPDispatchStateJoinLotState';
|
|
var methods = [];
|
|
var machines = [];
|
|
var contents = [];
|
|
var i = 0;
|
|
for (i = 0; i < $scope.machineList.length; i++) {
|
|
var content = {
|
|
equipmentno: $scope.machineList[i].EQUIPMENTNO,
|
|
opno: $scope.op,
|
|
dispatchdate: disDate
|
|
};
|
|
methods.push(method);
|
|
contents.push(content);
|
|
machines.push($scope.machineList[i].EQUIPMENTNO);
|
|
}
|
|
|
|
$MMWService.sendToMESSrv_Multi(
|
|
{
|
|
uri: methods,
|
|
content: contents,
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data, methods, machines);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function LoadDispatchState_LotStateData(callback) {
|
|
var content = {
|
|
areano: $scope.area,
|
|
opno: $scope.op,
|
|
mono: $scope.mono,
|
|
};
|
|
if ($scope.plot)
|
|
content.LotNo = $scope.plot;
|
|
$MMWService.sendToMESSrv(
|
|
{
|
|
uri: 'kcWIP.clsWIP.LoadDispatchState_LotStateData',
|
|
content: content,
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function dispatch_process(eqp, plotList, op, time, callback) {
|
|
$MMWService.sendToEAISrv(
|
|
{
|
|
uri: 'KMI.dispatch.process.json',
|
|
content:
|
|
{
|
|
equipment_no: eqp,
|
|
plot_no: plotList,
|
|
op_no: op,
|
|
dispatch_date: time,
|
|
login_employee_no: config.cache.account
|
|
},
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function dispatch_delete_process(item, callback) {
|
|
$MMWService.sendToEAISrv(
|
|
{
|
|
uri: 'KMI.dispatch.delete.process.json',
|
|
content:
|
|
{
|
|
equipment_no: item.EQUIPMENTNO,
|
|
plot_no: item.LOTNO,
|
|
op_no: $scope.op,
|
|
dispatch_date: item.DISPATCHDATE
|
|
},
|
|
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function dispatch_order_update_process(item, orderInfo, callback) {
|
|
$MMWService.sendToEAISrv(
|
|
{
|
|
uri: 'KMI.dispatch.order.update.process.json',
|
|
content:
|
|
{
|
|
dispatch_order: orderInfo,
|
|
equipment_no: item.EQUIPMENTNO,
|
|
op_no: $scope.op,
|
|
dispatch_date: item.DISPATCHDATE
|
|
},
|
|
|
|
success: function (data) {
|
|
if (data && data.Code == "0") {
|
|
var data = JSON.parse(data.ResultJson);
|
|
if (callback)
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}];
|
|
});
|