//common function
define(["app", "moment",
// 2021/04/20 異常單開立跳出視窗
"module/moduleWIP/program/common/wp05_lot_erf_create/wp05_lot_erf_create.js"
], function (app, moment) {
app.run(["$state", "$rootScope", "$filter", "$mdDialog", "$mdlToast", "$timeout", "$location", "$anchorScroll", "$templateRequest", "$compile", "config", 'MMWService', '$injector', 'wp05_lot_erf_create',
function ($state, $rootScope, $filter, $mdDialog, $mdlToast, $timeout, $location, $anchorScroll, $templateRequest, $compile, config, $MMWService, $injector, $wp05_lot_erf_create) {
$rootScope.loadFinish = false;
$rootScope.lang = config.setting.lang
$rootScope.strExceedTime_Rule = "EXCEEDTIME"; //20210630 13871,增加共用變數 生產批限制 固定字串
config.APKVersion = "";
//20170802 modify by Dustdusk for 判斷目前版本
if (window.nodeRequire) {
$rootScope.platform = 'desktop';
} else if (typeof cordova !== 'undefined') {
$rootScope.platform = 'cordova';
//20220418 13871,取得cordova apk version
try {
cordova.getAppVersion.getVersionNumber(function (version) {
config.APKVersion = version;
});
} catch (e) { }
} else {
$rootScope.platform = 'web';
}
$rootScope.isElectron = false;
try {
$rootScope.isElectron = nodeRequire ? true : false;
} catch (e) { }
// 紀錄目前Loading的狀態
//disabled : true - 隱藏/false - 顯示
$rootScope.Loading = {
disabled: true,
count: 0,
msg: ''
}
//顯示Loading, 會記錄目前顯示幾次Loading
$rootScope.showLoading = function (msg) {
angular.element(document.getElementsByClassName('LoadingContener')[0]).removeClass('ng-hide');
$rootScope.Loading.msg = msg || 'Loading...';
$rootScope.Loading.disabled = false;
$rootScope.Loading.count++;
}
window.showLoading = function (msg) {
$timeout(function () {
$rootScope.showLoading(msg);
});
}
//隱藏Loading, 當Loading 全部被關閉的時候才會完全關閉
$rootScope.hideLoading = function (isForce) {
if (isForce) {
$rootScope.Loading.count = 0;
}
$rootScope.Loading.count--;
if ($rootScope.Loading.count <= 0) {
angular.element(document.getElementsByClassName('LoadingContener')[0]).addClass('ng-hide');
$rootScope.Loading.disabled = true;
$rootScope.Loading.count == 0;
}
}
window.hideLoading = function (isForce) {
$timeout(function () {
$rootScope.hideLoading(isForce);
});
}
//顯示 Alert
$rootScope.showAlert = function (alertMsg, confirm) {
if (alertMsg.length != undefined) {
$mdDialog.alert(alertMsg, confirm);
} else if (Object.keys(alertMsg).length > 1) {
//20210115 雋辰,message trace 轉譯換行符號
if (alertMsg.stack !== undefined && alertMsg.stack != null)
alertMsg.stack = alertMsg.stack.replace(/\r\n/g, "
").replace(/\n/g, "
");
if (alertMsg.message !== undefined && alertMsg.message != null)
alertMsg.message = alertMsg.message.replace(/\r\n/g, "
").replace(/\n/g, "
");
var codeInfo = $filter('translate')('imes_name.' + alertMsg.code);
if (codeInfo != 'imes_name.' + alertMsg.code) alertMsg.title = codeInfo;
//2020/09/22 , 進站出站完成顯示WAIT HOLD
if (Object.keys(alertMsg).length == 3 || (Object.keys(alertMsg).length == 4 && alertMsg.LinkName)) {
$mdDialog.alert_top_right(alertMsg, confirm);
} else {
$mdDialog.alert_full(alertMsg, confirm);
}
}
}
window.showAlert = function (alertMsg, confirm) {
$timeout(function () {
$rootScope.showAlert(alertMsg, confirm);
});
}
//20211125 13871,顯示 Message,msg允許傳入[%%]翻譯格式
$rootScope.showMessage = function (msg, code, confirm) {
var message = "";
if (code != undefined)
message = code + ":" + $filter('translate')('imes_name.' + code);
if (message.length > 0)
message += "";
var index = msg.indexOf('[%');
while (index >= 0) {
var index2 = msg.indexOf('%]', index + 2);
if (index2 < 0) break;
var key = msg.substring(index + 2, index2);
var key_tran = $filter('translate')('imes_resources.' + key);
msg = msg.substring(0, index) + (key == key_tran ? key : key_tran) + msg.substring(index2 + 2, msg.length);
index = msg.indexOf('[%');
}
message += msg;
$mdDialog.alert(message, confirm);
}
/*
判斷當前是否有Alert視窗
*/
$rootScope.alertStatus = function (callback) {
var obj = document.getElementById('alertpage');
if (obj) { //有物件
callback(1);
} else {
callback(0);
}
};
//#region 互動式Dialog
//Yes Or No Dialog
$rootScope.ShowYesOrNo = function (options, callback, cancel) {
//沒有msg直接回傳
if (options.msg == null || options.msg == undefined) {
if (callback)
callback();
return;
}
$mdDialog.dialog('JSplugins/angular-material-lite/template/rule.tmp.html', function (dialog) {
//2020/09/22 雋辰,增加取消確認按鈕
dialog.isOKCancel = options.isOKCancel;
return {
title: options.title,
msg: options.msg,
confirm: function () {
dialog.hide();
if (callback)
callback();
},
back: function () {
dialog.hide();
if (cancel)
cancel();
}
};
});
}
//顯示 confirm
$rootScope.showConfirm = function (alertMsg, confirm, cancel) {
$mdDialog.confirm(alertMsg, confirm, cancel);
}
//顯示Select
/*
* options : {
* title : 標題
* label : list 中外顯值得變數名稱
* sub_label : list 中外顯值得其他資訊
* code : list 中內存值的變數名稱
* selectCode : 預設值,對應code設定的變數
* list : 要呈現的list
* confirm : 按下list以後的處理,會傳入dialog,可以用dialog.hide()
* 關閉開窗
* ExecFunction: 額外按鈕 傳入需要執行的Function 並帶入 選擇的項目
* ExecFunction_BtnImgUrl: 額外按鈕的background-image:的值
* 傳入的list 必須包含EXECUTE_FUNCTION_FLAG 才可點擊按鈕
* }
*/
$rootScope.showSelect = function (options) {
if (options.list.length != 0) {
$mdDialog.dialog('JSplugins/angular-material-lite/template/radioList.tmp.html', function (dialog) {
//20210320 雋辰 , 增加額外功能按鈕
dialog.EXECUTE_FUNCTION = options.EXECUTE_FUNCTION;
dialog.EXECUTE_FUNCTION_BTN_IMG_URL = options.EXECUTE_FUNCTION_BTN_IMG_URL;
return {
//20220419 13871同步startup.js,showSelect
title: options.title || $filter('translate')('common.msg.plz_select'),
label: options.label || 'label',
sub_label: options.sub_label, //2021/02/26 傳入subLabel
order: options.order || options.label, //2021/02/26 傳入order
selectCode: options.selectCode, //2021/02/26 傳入selectCode
labelOutput: function (item) {
if (typeof (options.label) === 'function') {
return options.label(item);
} else {
return item[dialog.label];
}
},
code: options.code || 'code',
valueOutput: function (item) {
if (typeof (options.code) === 'function') {
return options.code(item);
} else {
return item[dialog.code];
}
},
back: function () {
dialog.hide();
},
itemList: options.list,
search: function (itemList, filter_string, strkey) {
var key = strkey;
var obj = {
[key]: filter_string
};
return filter_string != "" ? $filter('filter')(itemList, obj) : itemList;
},
itemClick: function (item) {
if (options.confirm)
options.confirm(item, this);
},
itemCancel: function () {
dialog.hide();
if (options.cancel)
options.cancel(this);
},
isCancel: options.cancel != undefined,
background: {
click: function () {
dialog.hide();
}
},
//20210320 雋辰 , 增加額外功能按鈕,需要動態變更原資料寬度
checkItemWidth: function () {
if (dialog.EXECUTE_FUNCTION)
return { float: 'left', position: 'relative', width: 'calc(100% - 68px)' };
else
return { float: 'left', position: 'relative', width: '100%' };
}
};
});
} else {
$rootScope.showAlert($filter('translate')('common.msg.no_data'));
}
};
$rootScope.showToast = function (msg) {
$mdlToast.show(msg);
};
//顯示模糊查詢開窗 QueryList
/*
* options : {
* title : 標題
* label : list 中外顯值得變數名稱
* header : kmi list欄位
* code : list 中內存值的變數名稱
* selectCode : 預設值,對應code設定的變數
* confirm : 按下list以後的處理,會傳入dialog,可以用dialog.hide()
* 關閉開窗
* mode : m:多選/s:單選
* }
*/
$rootScope.showQueryList = function (options) {
//20180331 增加初始化Conditions,modeList沒設定的話則使用預設值
//預設查詢條件
var modeList = [
{ name: $filter('translate')('common.report.condition.equal'), code: '0' },
{ name: $filter('translate')('common.report.condition.nequal'), code: '1' },
{ name: $filter('translate')('common.report.condition.contain'), code: '2' },
{ name: $filter('translate')('common.report.condition.ncontain'), code: '3' },
{ name: $filter('translate')('common.report.condition.exceed-equal'), code: '4' },
{ name: $filter('translate')('common.report.condition.less-equal'), code: '5' },
{ name: $filter('translate')('common.report.condition.exceed'), code: '6' },
{ name: $filter('translate')('common.report.condition.less'), code: '7' }
];
function initConditions(conditions) {
if (conditions && conditions.length) {
conditions.forEach(function (condition) {
var temp_modeList = modeList; //用來判斷目前該使用哪些條件
if (condition.modeList == undefined) {
condition.modeList = modeList; //將預設條件放進查詢裡面
} else if (condition.modeList.length > 0) {
temp_modeList = condition.modeList; //因為查詢有設定條件,所以將條件放進temp_modeList
}
if (temp_modeList.length > 0) {
var isMatch = false;
//當有設定query_mode時則需要從modeList找出對應的查詢條件名稱
//如果沒有對應的則抓第一筆
if (condition.query_mode && condition.query_mode != '') {
for (var i = 0; i < temp_modeList.length; i++) {
if (condition.query_mode == temp_modeList[i].code) {
condition.query_name = temp_modeList[i].name;
isMatch = true;
break;
}
}
if (!isMatch) {
//表示設定的query_mode並不在modeList內
//使用第一筆作為預設值
condition.query_name = modeList[0].name;
condition.query_mode = modeList[0].code;
}
}
}
});
return conditions;
}
}
function getConditions(conditions) {
var query_condition_info = [];
if (conditions && conditions.length > 0) {
conditions.forEach(function (condition) {
if (condition.column_name != '' && condition.query_mode != '' && condition.value && condition.value != '') {
var query_conditoin = angular.extend({}, condition);
query_conditoin.modeList = undefined;
if (!query_conditoin.merge_condition_model)
query_conditoin.merge_condition_model = 'AND';
if (condition.data_type == 'D') {
query_conditoin.value = moment(condition.value).format('YYYY-MM-DD');
} else if (condition.query_mode == '2') {
query_conditoin.value = '%' + condition.value + '%';
} else {
query_conditoin.value = condition.value;
}
query_condition_info.push(query_conditoin);
}
});
}
return query_condition_info;
}
function calcPage(queryResults, pageInfo) {
pageInfo.totalPage = Math.floor(queryResults.length / pageInfo.perPageRow);
if (queryResults.length % pageInfo.perPageRow > 0) {
pageInfo.totalPage++;
}
return queryResults.slice((pageInfo.nowPage - 1) * pageInfo.perPageRow, (pageInfo.nowPage) * pageInfo.perPageRow);
}
function getQueryOrder(key, header) {
if (key) {
for (var i = 0; i < header.length; i++) {
if (header[i].code == key) {
return i;
}
}
return -1;
} else {
return 0;
}
}
function QueryListCompile(template, options) {
var header = template.find('#query_list_header');
var list = template.find('#query_list');
if (options.header && options.header.length > 0) {
for (var i = 0; i < options.header.length; i++) {
// 20201228 FOR 83491 自定义排版
var headerColumn = '';
if (options.setting) {
headerColumn = '
';
} else {
headerColumn = '
';
}
headerColumn += '
';
headerColumn += '';
headerColumn += 'clear';
headerColumn += '
';
headerColumn += '
';
headerColumn += '
search';
headerColumn += '
';
headerColumn += '
{{!dialog.header[' + i + '].order?\'\':\'\'}}';
headerColumn += '
';
headerColumn += '
';
headerColumn += '
';
header.append(headerColumn);
var listColumn = '';
if (options.setting) {
listColumn = '
';
listColumn += '
';
list.append(listColumn);
}
list.append('
');
}
return template;
}
function openDialog(options, pageInfo, queryResults) {
var selectItem;
options.condition = initConditions(options.condition);
if (options.mode == 'M') {
if (options.selectItem && options.selectItem.length > 0) {
selectItem = {};
options.selectItem.forEach(function (item) {
selectItem[item[options.key || options.header[0].code]] = item;
});
}
}
$mdDialog.dialog('JSplugins/angular-material-lite/template/queryList.tmp.html', function (dialog) {
return {
background: {
click: function () {
dialog.hide();
if (typeof (feedback) == 'function')
feedback();
}
},
mode: options.mode || 'S', //m (多選) / s (單選)
key: options.key || options.header[0].code,
queryTitle: options.title || $filter('translate')('common.msg.plz_select'),
qeryOrder: getQueryOrder(options.order || options.key, options.header),
orderColumn: function () {
if (dialog.qeryOrder == -1) {
return options.order;
} else {
return dialog.header[dialog.qeryOrder].code;
}
},
orderColumnSeq: function () {
if (dialog.qeryOrder == -1) {
return options.orderSeq;
} else {
return dialog.header[dialog.qeryOrder].order;
}
},
IsSelect: function (item) {
if (dialog.mode == 'S') {
return item[dialog.key] == dialog.selectCode;
} else if (dialog.mode == 'M') {
//20210804 13871,修改為回傳$is_select
//if (options.selectKey != undefined) {
//item.$is_select = item[options.selectKey.key] == options.selectKey.true;
return item.$is_select
//}
//return false;
}
return false;
},
selectCode: options.selectCode,
seletItem: selectItem,
condition: options.condition,
scrollbar: options.setting ? options.header.length * 200 + 32 + 'px' : '',
filterColumns: options.filterColumns || {}, //20180202 新增模糊查詢
beforeShown: options.beforeShown,
beforeCompile: function (template) {
return QueryListCompile(template, options);
},
loadCodeList: function (item) {
if (!item.require) {
$rootScope.showSelect({
title: $filter('translate')('common.report.condition_fields'),
label: 'name',
code: 'column_name',
selectCode: item.column_name,
list: options.condition,
confirm: function (selectItem, CodeDialog) {
item.modeList = [];
item.query_name = undefined;
item.query_mode = undefined;
item.data_type = undefined;
item.value = undefined;
item = angular.extend(item, selectItem);
CodeDialog.hide();
}
});
}
},
loadTypeList: function (item) {
if (!item.require) {
if (item.modeList && item.modeList.length > 0) {
$rootScope.showSelect({
title: $filter('translate')('common.condition_title'),
label: 'name',
code: 'code',
order: 'code',
selectCode: item.code,
list: item.modeList,
confirm: function (selectItem, TypeDialog) {
item.query_name = selectItem.name;
item.query_mode = selectItem.code;
TypeDialog.hide();
}
});
}
}
},
header: options.header,
orderResult: function (index, head) {
if (dialog.qeryOrder != index) {
head.order = false;
} else {
head.order = !head.order;
}
dialog.qeryOrder = index;
},
pageInfo: pageInfo,
getPageRange: function () {
return new Array(dialog.pageInfo.totalPage);
},
gotoPage: function (pageNum) {
dialog.pageInfo.nowPage = pageNum;
},
getQueryResults: function () {
var _queryResults = queryResults.filter(function (item, index, array) {
var isOK = true,
keys = Object.keys(dialog.filterColumns);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (isOK && item[key] && dialog.filterColumns[key] && dialog.filterColumns[key] != '') {
if ((item[key] + '').indexOf(dialog.filterColumns[key]) == -1) {
isOK = false;
break;
}
}
}
return isOK;
});
if (dialog.pageInfo != undefined) {
return calcPage(_queryResults, dialog.pageInfo);
} else {
return _queryResults;
}
},
confirm: function () {
//var selectItem = [];
if (dialog.mode == 'S') {
if (!dialog.seletItem) {
//完全未選擇的情況
if (queryResults && queryResults.length > 0) {
if (dialog.selectCode && dialog.selectCode != '') {
var tObject = {};
tObject[dialog.key] = dialog.selectCode;
var temp = $filter('filter')(queryResults, tObject);
if (temp && temp.length > 0) {
dialog.seletItem = temp[0];
}
}
}
}
} else if (dialog.mode == 'M') {
//20210804 13871,不需要管有沒有傳入selectKey
//if (options.selectKey != undefined) {
// dialog.seletItem = queryResults;
if (dialog.seletItem != undefined) {
var selectItem = [];
for (var key in dialog.seletItem) {
if (dialog.seletItem[key] != undefined)
selectItem.push(dialog.seletItem[key]);
}
dialog.seletItem = selectItem;
}
}
if (dialog.seletItem) {
if (options.confirm)
options.confirm(dialog.seletItem, dialog);
} else {
$rootScope.showAlert($filter('translate')('common.msg.plz_select_one'));
}
},
back: function () {
if (options.back) {
options.back(dialog.hide);
} else {
dialog.hide();
}
},
itemClick: function (item) {
if (dialog.mode == 'S') {
dialog.selectCode = item[dialog.key];
dialog.seletItem = item;
} else {
//dialog.selectCode = item[dialog.key];
//20210804 13871,不需要管有沒有傳入selectKey
//if (options.selectKey != undefined) {
//item.$is_select = item[options.selectKey.key] == options.selectKey.true;
if (item.$is_select) {
if (options.selectKey)
item[options.selectKey.key] = options.selectKey.false;
item.$is_select = false;
} else {
if (options.selectKey)
item[options.selectKey.key] = options.selectKey.true;
item.$is_select = true;
}
if (dialog.seletItem == undefined)
dialog.seletItem = [];
if (item.$is_select)
dialog.seletItem.push(item);
else {
for (var i = 0; i < dialog.seletItem.length; i++) {
if (item == dialog.seletItem[i]) {
dialog.seletItem.splice(i, 1);
break;
}
}
}
//} else if (dialog.seletItem) {
// //dialog.seletItem = {};
// if (dialog.seletItem[item[dialog.key]]) {
// dialog.seletItem[item[dialog.key]] = undefined;
// } else {
// dialog.seletItem[item[dialog.key]] = item;
// }
//}
}
},
itemDbClick: function (item, event) {
if (dialog.mode == 'S') {
dialog.selectCode = item[dialog.key];
dialog.seletItem = item;
dialog.confirm();
} else {
dialog.itemClick(item, event);
}
},
UnSelectAll: function () {
queryResults.forEach(item => {
item.$is_select = false
if (dialog.seletItem == undefined)
dialog.seletItem = [];
if (item.$is_select)
dialog.seletItem.push(item);
else {
for (var i = 0; i < dialog.seletItem.length; i++) {
if (item == dialog.seletItem[i]) {
dialog.seletItem.splice(i, 1);
break;
}
}
}
});
dialog.seletItem = undefined;
},
SelectAll: function () {
queryResults.forEach(item => {
item.$is_select = true;
if (dialog.seletItem == undefined)
dialog.seletItem = [];
if (item.$is_select)
dialog.seletItem.push(item);
else {
for (var i = 0; i < dialog.seletItem.length; i++) {
if (item == dialog.seletItem[i]) {
dialog.seletItem.splice(i, 1);
break;
}
}
}
});
},
search: function () {
var query_condition_info = getConditions(options.condition);
options.query(query_condition_info, function (_queryResults) {
if (!_queryResults || _queryResults.length == 0) {
$rootScope.showToast($filter('translate')('common.msg.no_data'), 'error');
}
if (dialog.pageInfo != undefined) {
dialog.pageInfo.nowPage = 1;
}
queryResults = _queryResults;
});
},
cancel: options.cancel
};
});
}
(function (options) {
if (options.header && options.header.length > 0) {
if (options.query) {
var pageInfo;
if (options.pageRecord != undefined) {
pageInfo = {
nowPage: 1,
perPageRow: options.pageRecord,
totalPage: 0
};
}
if (options.notQuery && options.condition) {
//當有設定查詢條件以及 notQuery 的時候,開啟不會伴隨查詢
openDialog(options, pageInfo, []);
} else {
var query_condition_info = getConditions(options.condition);
options.query(query_condition_info, function (queryResults) {
if (queryResults && queryResults.length > 0) {
openDialog(options, pageInfo, queryResults);
} else if (options.noDataException) {
options.noDataException(options, function () {
openDialog(options, pageInfo, queryResults);
});
} else {
$rootScope.showAlert($filter('translate')('common.msg.no_data'));
//20181024 modify by Dustdusk for M#: 當有設定查詢條件時,查無資料還是會開啟視窗
if (options.condition && options.condition.length > 0)
openDialog(options, pageInfo, queryResults);
}
});
}
} else {
console.error('showQueryList : plz set options.query');
}
} else {
console.error('showQueryList : plz set options.header');
}
})(options);
};
//ControlRule Alert Dialog
function RuleDialog(options, response, callback) {
$mdDialog.dialog('JSplugins/angular-material-lite/template/rule.tmp.html', function (dialog) {
//2020/09/22 雋辰,增加取消確認按鈕
dialog.isOKCancel = options.isOKCancel;
return {
title: (options.title == 'PASS' ? "NOTE" : options.title) + $filter('translate')('dialog.chkRule.' + (options.title == 'PASS' ? "NOTE" : options.title)),
msg: options.msg,
confirm: function () {
this.hide();
//2020/09/22 雋辰,QUESTION
if (options.isOKCancel) {
response.LinkName = 'PASS';
response.ChkControlRule = 0;
}
if (callback)
callback(response);
},
back: function () {
this.hide();
if (callback)
callback(response);
}
};
});
}
//#endregion
//#region 共用功能
//Mantis:0080931
//作業站[多人加工模式]是否為設備,[扣料模式]是否為設備
$rootScope.EQPCheck_ModuleWIP = function (stationNo, callback) {
$MMWService.sendToMESSrv({
uri: 'kcOP.clsOpBasis.LoadOPBasis',
content: {
opno: stationNo,
IssueState: 2,
GetXml_CLOB: false,
columns: ['opno', 'opname', 'multioperatormode', 'materialoption']
},
success: function (data) {
data = JSON.parse(data.ResultJson);
if (data.OPBasis.length <= 0) {
$rootScope.showAlert($filter('translate')('mrs00.msg.cantGet') + $filter('translate')('mrs00.msg.opInfo') + stationNo);
config.setting.workStation = "";
config.cache.workStation = "";
config.setting.equipment = "";
config.cache.equipment = "";
$rootScope.changeProgram('moduleEQP');
callback(data, false);
return;
}
var intmultioperatormode = data.OPBasis[0].MULTIOPERATORMODE;
var intmaterialoption = data.OPBasis[0].MATERIALOPTION;
if (intmultioperatormode != 2) {
$rootScope.showAlert("(" + stationNo + ")" + $filter('translate')('mrs00.msg.opoptionmultoperatormod'));
config.setting.workStation = "";
config.cache.workStation = "";
config.setting.equipment = "";
config.cache.equipment = "";
$rootScope.changeProgram('moduleEQP');
callback(data, false);
return;
}
if (intmaterialoption != 1) {
$rootScope.showAlert("(" + stationNo + ")" + $filter('translate')('mrs00.msg.opoptionmaterialoption'));
config.setting.workStation = "";
config.cache.workStation = "";
config.setting.equipment = "";
config.cache.equipment = "";
$rootScope.changeProgram('moduleEQP');
callback(data, false);
return;
}
if (callback) {
callback(data.OPBasis[0], true);
}
}
});
}
//[Mantis:0078174] Zedd 2020/11/09
//生產批報工模式 多人加工模式 不是 設備、作業站 ,不允許綁定裝置
$rootScope.LotCheck_ModuleWIP = function (stationNo, callback) {
$MMWService.sendToMESSrv({
uri: 'kcOP.clsOpBasis.LoadOPBasis',
content: {
opno: stationNo,
IssueState: 2,
GetXml_CLOB: false,
columns: ['opno', 'opname', 'multioperatormode']
},
success: function (data) {
data = JSON.parse(data.ResultJson);
if (data.OPBasis.length <= 0) {
$rootScope.showAlert($filter('translate')('mrs00.msg.cantGet') + $filter('translate')('mrs00.msg.opInfo') + stationNo);
config.setting.workStation = "";
config.setting.equipment = "";
config.setting.op = "";
config.cache.workStation = "";
config.cache.equipment = "";
config.cache.op = "";
$rootScope.changeProgram('moduleLot');
if (callback) {
callback(data, false);
return;
}
}
var intmultioperatormode = data.OPBasis[0].MULTIOPERATORMODE;
if (intmultioperatormode != 0 && intmultioperatormode != 2) {
$rootScope.showAlert("(" + stationNo + ")" + $filter('translate')('mrs00_lot.msg.opoptionmultoperatormod'));
config.setting.workStation = "";
config.setting.equipment = "";
config.setting.op = "";
config.cache.workStation = "";
config.cache.equipment = "";
config.cache.op = "";
$rootScope.changeProgram('moduleLot');
if (callback) {
callback(data, false);
return;
}
}
if (callback) {
callback(data, true);
}
}
});
}
// Change Program
$rootScope.changeProgram = function (program, parameters, isLeave) {
//20210623 13871,檢查program如果是undefined就不執行
if (program == undefined || program == null || program == '')
return;
//20201106 雋辰,增加program檢查
var flag = false;
for (i in config.program) {
var item = config.program[i];
if (item.name == program) {
flag = true;
break;
}
}
if (!flag) {
$rootScope.showAlert(program + $filter('translate')('error.pageNotFound'));
return;
}
$rootScope.reciprocalRestart();
if (typeof (parameters) == 'boolean') {
isLeave = parameters;
} else {
isLeave = isLeave || false;
}
if (!isLeave) {
//從任何地點 > 載入一般程式
$rootScope.programState = 'load-program';
} else {
//從其他程式> 載入home
$rootScope.programState = 'leave-program';
}
if (parameters != undefined) {
$state.go(program, parameters);
} else {
$state.go(program);
}
//2020-05-07 yenru , UCD Layout Clear Menu Right Top Button;
if ($rootScope.currentState != program) {
$rootScope.btnList = [];
}
}
///
/// 2020/10/27 Grace 增加顯示異常單開立完成訊息(右上訊息提示窗)
///
///
///
///
是否為checkin
///
切換的頁面名稱
$rootScope.CheckInOut_After = function (lot, linkName, isci, gotoProgram) {
var title = ""
if (isci && isci == true)
title = $filter('translate')('common.msg.checkin_lot');
else
title = $filter('translate')('common.msg.checkout_lot');
if (linkName == 'HOLD' || linkName == 'WAIT')
title += "(" + linkName + ")" + $filter('translate')('dialog.chkRule.' + linkName);
var holdMsg = "";
if (linkName == 'HOLD')
holdMsg = "
" + $filter('translate')('dialog.holdPleaseExecERF');
$rootScope.showAlert({
title: title,
item: $filter('translate')('common.lotno'),
message: lot + holdMsg,
LinkName: linkName
});
if (gotoProgram)
$rootScope.changeProgram(gotoProgram, true);
}
$rootScope.logout = function (callback) {
$rootScope.showConfirm(
$filter('translate')('common.msg.is_logout'),
function (dialog) {
dialog.hide();
$MMWService.sendToMESSrv_plain({
uri: 'wsUSR.ClearLoginInfo_plainjson',
content: {
userno: config.cache.account,
computername: config.setting.deviceName + "/" + config.client.ip, //20220425 13871,增加deviceName至computername,與uri的不一致會導致登出時無法刪除session
sessionid: config.mdssessionno
},
success: function (data) {
//20220425 13871,登出,清除使用的session
config.mdssessionno = '';
if (callback)
callback();
$rootScope.hideMenu();
$timeout(function () {
$rootScope.changeProgram("login", true);
}, 200);
}
});
},
function (dialog) {
dialog.hide();
});
}
//20201113 雋辰,深拷貝
$rootScope.deepCopy = function (obj, cache) {
if (cache == undefined)
cache = new WeakMap();
// 基本型別 & function
if (obj === null || typeof obj !== 'object') return obj
// Date 及 RegExp
if (obj instanceof Date || obj instanceof RegExp) return obj.constructor(obj)
// 檢查快取
if (cache.has(obj)) return cache.get(obj) // 使用原物件的 constructor
const copy = new obj.constructor() // 先放入 cache 中
cache.set(obj, copy)
// 取出所有一般屬性 & 所有 key 為 symbol 的屬性
;
[...Object.getOwnPropertyNames(obj), ...Object.getOwnPropertySymbols(obj)].forEach(key => {
copy[key] = $rootScope.deepCopy(obj[key], cache)
});
return copy;
}
//20210703 13871,判斷undefined null 空值
$rootScope.IsNullOrEmpty = function (str) {
if (str == undefined || str === "")
return true;
return false;
}
$rootScope.focusById = function (id) {
$timeout(function () {
var target = document.getElementById(id);
if (target) {
target.focus();
target.select();
}
});
}
///
/// 20210830 13871,檢查生產批設備是否符合綁定的設備
///
///
生產批資訊
///
設備清單,未使用設備應傳入Available EQP,已使用應傳入TempEquipment
///
頁面dialog物件
///
是否已經確認使用設備
///
是否執行ReverseTriggerOP,不傳入為true
///
執行ReverseTriggerOP成功後欲執行的function
///
執行ReverseTriggerOP失敗後欲執行的function
///
response
$rootScope.CheckLotBelongEQP = function (lotInfo, listEQP, dialog, isCO, execReverse, callback, error) {
var flag = true; //是否符合
if (execReverse == undefined)
execReverse = true;
if (isCO) {
if (listEQP.length != 1 || listEQP[0].EQUIPMENTNO != config.cache.equipment) {
flag = false;
}
}
else {
var listTemp = listEQP.filter(item => {
return item.EQUIPMENTNO == config.cache.equipment;
});
if (listTemp.length < 0) {
flag = false;
}
}
if(!flag) {
$rootScope.showAlert($filter('translate')('wp_excute_lot.doesNotBelongOP'));
if (execReverse) {
ReverseTriggerOP_NotUseUndo(lotInfo.LOTNO, lotInfo.LOTSERIAL, lotInfo.LOTSTAMP, callback, error);
}
if (dialog) {
dialog.hide();
}
}
}
//使用設備報工時的設備確認
$rootScope.CheckUseEQP = function (LotNo,Phase,dialog,callback) {
if(config.cache.dashboard == 'lot'){
callback();
return;
}
var uri = [];
var content = [];
switch (Phase){
case 'ci': //CheckIn
uri.push("kcWIP.clsLot.LoadAvailableEquipment_All")
content.push({
LotNo: LotNo,
});
break;
case 'co': //CheckOut
uri.push("kcWIP.clsLot.LoadTemp_Equipment")
content.push({
LotNo: LotNo
});
break;
}
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
if (data.Code == "0") {
var list = [];
var tmpJson = JSON.parse(data.ResultJson);
var tmp;
//funLoadLotState
tmp = JSON.parse(tmpJson[uri[0]]);
tmp = tmp[Object.keys(tmp)[0]];
list = tmp;
var result = list.filter(obj=> {
return config.cache.equipment == obj.EQUIPMENTNO;
});
switch (Phase){
case 'ci': //CheckIn
if(result.length < 1){
$rootScope.showAlert($filter('translate')('lc_ci_gen.msg.thiseqpcantuselot') + "," +
$filter('translate')('lc_ci_gen.msg.plaseuse') + $filter('translate')('moduleLot.title'));
if(dialog && dialog.back){
dialog.back();
}else if (dialog) {
dialog.hide();
}
return;
}
break;
case 'co': //CheckOut
if(result.length != 1 || list.length != 1){
$rootScope.showAlert($filter('translate')('lc_ci_gen.msg.thiseqpcantuselot') + "," +
$filter('translate')('lc_ci_gen.msg.plaseuse') + $filter('translate')('moduleLot.title'));
if(dialog && dialog.back){
dialog.back();
}else if (dialog) {
dialog.hide();
}
return;
}
break;
}
callback();
}
},
error: function (data) {
if (error)
error();
}
});
}
/*
*20220510 13871,取得ValueList,並將翻譯後的值放入指定欄位
*tblName:ValueList資料表名稱
*colName:ValueList資料表欄位名稱
*list:資料集合
*sourceCol:資料集合的欄位名稱,會將此欄位的值用作語系翻譯
*replaceCol:資料集合的欄位名稱,會將翻譯後的值放入此欄位
*callback:執行完後端取得ValueList資訊,並翻譯值後呼叫
*/
$rootScope.GetValueList = function (tblName, colName, list, sourceCol , replaceCol, callback) {
var uri = [];
var content = [];
uri.push("kcSYS.clsValueList.LoadValueList");
content.push({
pTableName: tblName,
pColumnName: colName
});
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
var tmpJson = JSON.parse(data.ResultJson);
var tmp;
var index = 0;
tmp = JSON.parse(tmpJson[uri[index]]);
tmp = tmp[Object.keys(tmp)[0]];
if (list) {
list.forEach(item=> {
var drSel;
drSel = tmp.filter(valList => {
return valList.COLUMNVALUE == item[sourceCol];
});
if (drSel.length > 0)
item[replaceCol] = $filter('translate')('imes_resources.' + drSel[0].DISPLAYTEXT);
else
item[replaceCol] = item[sourceCol];
});
}
if (callback) {
callback();
}
}
});
}
//20220629 13871,argb int convert to rgb #Hex
$rootScope.ArgbInt2HexStr = function (color) {
return '#' + ('000000' + (color & 0xFFFFFF).toString(16)).slice(-6);
}
//#endregion
//#region 共用iMES
///
/// ChkControlRule For HTML
///
///
///
/// 特性資料Array