This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
SXS20240115/SRC/iMES_PAD/config/common.js

2253 lines
116 KiB
JavaScript
Raw Normal View History

2024-01-24 16:47:50 +08:00
//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, "<br>").replace(/\n/g, "<br>");
if (alertMsg.message !== undefined && alertMsg.message != null)
alertMsg.message = alertMsg.message.replace(/\r\n/g, "<br>").replace(/\n/g, "<br>");
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 += "</br>";
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 增加初始化ConditionsmodeList沒設定的話則使用預設值
//預設查詢條件
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 = '<div class="kmi-list__column head-controls" style="flex: 0 0 200px;" ng-style="{\'max-width\' : \'' + options.header[i].width + '\'}">';
} else {
headerColumn = '<div class="kmi-list__column head-controls" style="flex:1;" ng-style="{\'max-width\' : \'' + options.header[i].width + '\'}">';
}
headerColumn += '<div class="filter" ng-show="dialog.header[' + i + '].isFilter">';
headerColumn += '<input ng-model="dialog.filterColumns[\'' + options.header[i].code + '\']"/>';
headerColumn += '<i class="material-icons clear" style="position: absolute;top: 2px;right: 4px;" ng-click="dialog.header[' + i + '].isFilter = false;dialog.filterColumns[\'' + options.header[i].code + '\'] = \'\';">clear</i>';
headerColumn += '</div>';
headerColumn += '<div class="order" ng-hide="dialog.header[' + i + '].isFilter">';
headerColumn += '<i class="material-icons search" style="z-index:1;" ng-click="dialog.header[' + i + '].isFilter = true">search</i>';
headerColumn += '<label ng-bind="\'' + options.header[i].label + '\' | translate"></label>';
headerColumn += '<i class="material-icons" ng-show="dialog.qeryOrder == ' + i + '">{{!dialog.header[' + i + '].order?\'&#xE5D8;\':\'&#xE5DB;\'}}</i>';
headerColumn += '<div class="kmi-can-click" ng-click="dialog.orderResult(' + i + ', dialog.header[' + i + ']);"></div>';
headerColumn += '</div>';
headerColumn += '</div>';
header.append(headerColumn);
var listColumn = '';
if (options.setting) {
listColumn = '<div class="kmi-list__column" style="flex:0 0 200px;z-index:0;"';
} else {
listColumn = '<div class="kmi-list__column" style="flex:1;z-index:0;"';
}
listColumn += 'ng-class="{\' column-border\':!$last}" ng-style="{\'max-width\' : \'' + options.header[i].width + '\'}" ng-bind="item[\'' + options.header[i].code + '\']" >';
listColumn += '</div>';
list.append(listColumn);
}
list.append('<div class="kmi-can-click" ng-click="dialog.itemDbClick(item, $event);"></div>');
}
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 = [];
}
}
/// <summary>
/// 2020/10/27 Grace 增加顯示異常單開立完成訊息(右上訊息提示窗)
/// </summary>
/// <param name="lot"></param>
/// <param name="linkName"></param>
/// <param name="isci">是否為checkin</param>
/// <param name="gotoProgram">切換的頁面名稱</param>
$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 = "<br />" + $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();
}
});
}
/// <summary>
/// 20210830 13871,檢查生產批設備是否符合綁定的設備
/// </summary>
/// <param name="lotInfo">生產批資訊</param>
/// <param name="listEQP">設備清單,未使用設備應傳入Available EQP,已使用應傳入TempEquipment</param>
/// <param name="dialog">頁面dialog物件</param>
/// <param name="isCO">是否已經確認使用設備</param>
/// <param name="execReverse">是否執行ReverseTriggerOP,不傳入為true</param>
/// <param name="callback">執行ReverseTriggerOP成功後欲執行的function</param>
/// <param name="error">執行ReverseTriggerOP失敗後欲執行的function</param>
/// <return>response</resturn>
$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
/// <summary>
/// ChkControlRule For HTML
/// </summary>
/// <param name="LotNo"></param>
/// <param name="LotStamp"></param>
/// <param name="strAttrib">特性資料Array<Object></param>
/// <param name="strError"></param>
/// <param name="strAllBinNo"></param>
/// <param name="strBin"></param>
/// <param name="callback"></param>
$rootScope.ChkControlRule = function (LotNo, LotStamp, strAttrib, strError, strAllBinNo, strBin, callback) {
//需對應 wsWIP.ChkControlRule 的tag name, 有區分大小寫
var tmpAttrib = [];
strAttrib.forEach(item => {
//2020/10/14 Grace 若Attrib Value 為NULL 不可直接轉字串
var attribvalue_temp = '';
if (item.ATTRIBVALUE != null) { attribvalue_temp = item.ATTRIBVALUE.toString(); }
tmpAttrib.push({
attribtype: item.ATTRIBTYPE.toString(),
attribno: item.ATTRIBNO,
attribvalue: attribvalue_temp,
attribsource: item.ATTRIBSOURCE.toString(),
attribphase: item.ATTRIBPHASE.toString(),
attribsequence: item.ATTRIBSEQUENCE.toString(),
savetolotpropertyno: item.SAVETOLOTPROPERTYNO,
//for SPC, 仿照wsWIP, 欄位開著, 值沒有傳
TestValue: '',
QCItemNo: '',
Result: '',
Result_INT: '',
FactorSerial: '',
SerialNo: '',
MEMO: '',
ComponentNo: ''
});
});
var Invoke_content = { lotno: LotNo, lotstamp: LotStamp, attrib: tmpAttrib };
if (strError) {
Invoke_content.error = strError;
}
if (strAllBinNo) {
Invoke_content.allbinno = strAllBinNo;
}
if (strBin) {
Invoke_content.bin = strBin;
}
//Call ChkControlRule ws
$MMWService.sendToMESSrv({
uri: 'wsWIP.ChkControlRule',
content: Invoke_content,
success: function (data) {
var result = JSON.parse(data.ResultJson);
//預設不可繼續執行
if (data.Code === '0') {
var response = {};
var linkname = result.LinkName;
var msg = "";
response.ChkControlRule = -1;
response.Attrib = result.Attrib;
response.LinkName = result.LinkName;
response.RuleAction = result.RuleAction;
response.RuleNoList = result.RuleNoList;
response.RuleNo = result.RuleNo;
response.ERFType = result.ERFType;
response.MailGroupNo = result.MailGroupNo;
switch (linkname) {
case 'QUESTION':
if (result.RuleAction) {
msg += "Rule Check Result : " + result.RuleAction + " !! Do you want to continue?<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg, isOKCancel: true }, response, callback);
} else
if (callback) callback(response);
break;
case 'WARNING':
if (result.RuleAction) {
msg += "Rule Check Result : " + result.RuleAction + " !!<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
} else
if (callback) callback(response);
break;
case 'ABORTRULE':
//所有違反的法則
msg += "Rule Check Result : Abort Rule !!<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
break;
case 'WAIT':
response.ChkControlRule = 0;
if (callback) callback(response);
break;
case 'HOLD':
response.ChkControlRule = 0;
if (callback) callback(response);
break;
case 'ALERT':
response.LinkName = 'PASS';
response.ChkControlRule = 0;
if (result.RuleAction) {
if (result.MailGroupNo && result.MailGroupNo.length > 0) {
msg += "Rule Check Result : " + result.RuleAction + " !!<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
} else {
msg += "Rule Check Result : " + result.RuleAction + " !!, Mail To GroupNo : " + (result.MailGroupNo ? result.MailGroupNo : "") + "<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
}
RuleDialog({ title: linkname, msg: msg }, response, callback);
} else
if (callback) callback(response);
break;
case 'NOTE':
response.LinkName = 'PASS';
response.ChkControlRule = 0;
if (result.RuleAction) {
msg += "Rule Check Result : " + result.RuleAction + " !!<br />";
msg += "All Violation Rule: " + (result.RuleNoList ? result.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
} else
if (callback) callback(response);
break;
default:
response.ChkControlRule = 0;
if (result.RuleAction) {
msg += "Rule Check Result : " + result.RuleAction + " !!<br />";
RuleDialog({ title: linkname, msg: msg }, response, callback);
} else
if (callback) callback(response);
break;
}
}
}
});
}
/// <summary>
/// ChkControlRule_Component For HTML 20210803 13871
/// </summary>
/// <param name="LotNo">生產批號</param>
/// <param name="LastOne">是否為最後一次</param>
/// <param name="Component">元件資料Array<Object></param>
/// <param name="Attrib">特性資料Array<Object><</param>
/// <param name="ComponentAttrib">元件特性資料Array<Object><</param>
/// <param name="Error">不良原因資料Array<Object></param>
/// <param name="callback"></param>
/// <return>response</resturn>
/* response:{
ChkControlRule = 0:成功 other:卡控;
Attrib = 特性資料Array<Object>;
ComponentAttrib = 元件特性資料Array<Object>;
LotRuleData = ;
LinkName = ;
RuleAction = ;
RuleNoList = ;
RuleNo = ;
ERFType = ;
MailGroupNo = ;
}
*/
$rootScope.ChkControlRule_Component = function (LotNo, LastOne, Component, Attrib, ComponentAttrib, Error, callback) {
Attrib.forEach(item => {
if (item.ATTRIBVALUE != null && item.ATTRIBVALUE != undefined) { item.ATTRIBVALUE = item.ATTRIBVALUE.toString(); }
});
ComponentAttrib.forEach(item => {
if (item.ATTRIBVALUE != null && item.ATTRIBVALUE != undefined) { item.ATTRIBVALUE = item.ATTRIBVALUE.toString(); }
});
var Invoke_content = { lotno: LotNo, lastone: LastOne, attrib: Attrib, component: Component };
if (ComponentAttrib) {
Invoke_content.componentattrib = ComponentAttrib;
}
if (Error) {
Invoke_content.error = Error;
}
//Call ChkControlRule_Component ws
$MMWService.sendToMESSrv({
uri: 'wsWIP.ChkControlRule_Component',
content: Invoke_content,
success: function (data) {
var result = JSON.parse(data.ResultJson);
var response = {};
var linkname = result.LinkName;
var msg = "";
response.ChkControlRule = -1;
response.Attrib = result.Attrib;
response.ComponentAttrib = result.ComponentAttrib;
response.LotRuleData = result.LotRuleData;
response.LinkName = result.LinkName;
response.RuleAction = result.RuleAction;
//response.RuleNoList = result.RuleNoList; //20210807 13871,PC端並沒有取回result.RuleNoList 只從LotRuleData組成RuleNoList
response.RuleNo = result.RuleNo;
response.ERFType = result.ERFType;
response.MailGroupNo = result.MailGroupNo;
var obj = {
QUESTION: 3,
WARNING: 4,
ABORTRULE: 5,
WAIT: 2,
HOLD: 1,
}
//過濾LotRuleData資料以逗號串接RuleNo
if (linkname in obj) {
if (linkname != "HOLD" || (linkname == "HOLD" && LastOne))
response.LotRuleData.forEach(item=> {
if (item.RULEKEYWORD == obj[linkname]) {
if ($rootScope.IsNullOrEmpty(response.RuleNoList))
response.RuleNoList = "";
response.RuleNoList += item.RULENO + ",";
}
});
}
switch (linkname) {
case 'QUESTION':
if (result.RuleAction) {
msg += "Component Rule Check Result : " + result.RuleAction + " !! Do you want to continue?<br />";
msg += "All Violation Rule: " + (response.RuleNoList ? response.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg, isOKCancel: true }, response, callback);
} else
if (callback) callback(response);
break;
case 'WARNING':
if (result.RuleAction) {
var strErrName = $filter('translate')('imes_name.ENXXX');
var strErrName_Rep = $filter('translate')('imes_resources.' + response.RuleAction);
msg += "ENXXX";
if (strErrName != 'imes_name.ENXXX') msg += ":" + strErrName;
msg += "<br />";
msg += strErrName_Rep == ('imes_resources.' + response.RuleAction) ? response.RuleAction : strErrName_Rep
msg += "<br />";
msg += "Component Rule Check Result : " + result.RuleAction + " !!<br />";
msg += "All Violation Rule: " + (response.RuleNoList ? response.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
} else
if (callback) callback(response);
break;
case 'ABORTRULE':
msg += "Component Rule Check Result : Abort Rule !!<br />";
msg += "All Violation Rule: " + (response.RuleNoList ? response.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
break;
case 'WAIT':
response.ChkControlRule = 0;
if (callback) callback(response);
break;
case 'HOLD':
response.ChkControlRule = 0;
if (callback) callback(response);
break;
default:
response.ChkControlRule = 0;
if (result.RuleAction) {
//過濾LotRuleData資料以逗號串接RuleNo
response.LotRuleData.forEach(item=> {
if (item.RULEKEYWORD == 8) {
if ($rootScope.IsNullOrEmpty(response.RuleNoList))
response.RuleNoList = "";
response.RuleNoList += item.RULENO + ",";
}
});
if (!$rootScope.IsNullOrEmpty(response.RuleNoList)) {
var strErrName = $filter('translate')('imes_name.0000-003000');
msg += "0000-003000";
if (strErrName != 'imes_name.0000-003000') msg += ":" + strErrName;
msg += "<br />";
msg += response.RuleNo;
msg += "<br />";
msg += "All Violation Rule: " + (response.RuleNoList ? response.RuleNoList : "");
RuleDialog({ title: linkname, msg: msg }, response, callback);
}
else {
if (callback) callback(response);
}
} else
if (callback) callback(response);
break;
}
}
});
}
/// <summary>
/// 2020/10/23 Grace BRTransferLot 參考WP_KIT處理, 並將生產批報工、設備報工的CI、CO的BRTransferLot處理改呼叫共用
/// </summary>
/// <param name="LotNo"></param>
/// <param name="UserNo"></param>
/// <param name="LinkName"></param>
/// <param name="ERFType"></param>
/// <param name="RuleNo"></param>
/// <param name="ScrapQty"></param>
/// <param name="RuleMsg"></param>
/// <param name="isci">是否為checkin</param>
/// <param name="gotoProgram">執行後切換的頁面名稱</param>
// 2021/05/21 blnRepairERF 是否補開ERF
$rootScope.BRTransferLot = function (LotNo, UserNo, LinkName, ERFType, RuleNo, ScrapQty, RuleMsg, isci, gotoProgram, blnRepairERF) {
//--必要傳入 LotNo, UserNo, LinkName
//--非必要傳入 ERFType, RuleNo, ScrapQty, RuleMsg
var bolERFCreate = false;
if (blnRepairERF != null && blnRepairERF != "" && blnRepairERF == true) {
blnRepairERF = true;
} else {
blnRepairERF = false;
}
if (LinkName == "HOLD") {
$MMWService.sendToMESSrv({
uri: 'kcWIP.clsLot.LoadLotBasisJoinState',
content: {
LotNo: LotNo,
m_Types: ['System.String',
'System.String',
'System.String',
'System.String',
'System.Int32',
'System.String',
'System.String',
'System.String',
'System.String',
'System.Int32',
'System.DateTime',
'System.DateTime',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.Int32',
'System.Int32',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.String',
'System.Int32',
'System.Boolean',
'System.Boolean',
'System.Int32',
'System.Boolean',
'System.Boolean',
'System.Boolean']
},
success: function (data) {
var data = JSON.parse(data.ResultJson);
if (data.BasisJoinState.length > 0) {
// callback(data, data.BasisJoinState[0].LOTSTAMP);
//2022/05/16 異常單優化
var strHoldDescription = "";
if (RuleNo != undefined){
strHoldDescription = RuleNo;
}
if (RuleMsg != undefined){
strHoldDescription = strHoldDescription + RuleMsg;
}
$MMWService.sendToMESSrv({
uri: 'kcWIP.clsLot.AddERFCreateData',
content: {
LotNo: LotNo,
ERFType: ERFType,
OPNo: data.BasisJoinState[0].OPNO,
ERFQty:data.BasisJoinState[0].CURQTY,
HoldUser:UserNo,
CustomerNo:data.BasisJoinState[0].CUSTOMERNO,
ProductNo:data.BasisJoinState[0].PRODUCTNO,
HoldDescription:strHoldDescription,
ERFSource:0,
LotIsValid:1
},
success: function (data) {
}
});
}
}
});
//開立異常單
bolERFCreate = true;
//存入所需參數
//pChkWIP: WIP 開單
//pERFSource: '0:WIP,1:SPC,2:Receive
var ERFData = [];
ERFData.push({
pLotNo: LotNo,
pUserId: UserNo,
pERFType: ERFType,
pRuleNo: RuleNo,
pScrapQty: ScrapQty,
pRuleMsg: RuleMsg,
pGotoProgram: gotoProgram,
pChkWIP: true,
pERFSource: 0,
pRepairERF: blnRepairERF
});
// 2021/04/20 異常單開立跳出視窗
//$rootScope.changeProgram("wp05_lot_erf_create", { data: { ERFData } });
$wp05_lot_erf_create.init({ data: { ERFData}});
} else if (LinkName == "WAIT") {
bolERFCreate = false;
$rootScope.CheckInOut_After(LotNo, LinkName, isci);
} else {
//Transfer Lot
$MMWService.sendToMESSrv({
uri: 'wsWIP.TransferLot',
content: {
LotNo: LotNo,
LinkName: LinkName,
},
success: function(data) {
//20210608 13871,0094151: [平板]6.0.5 異常開立問題修正,修改TransferLot後的異常判斷
var result = JSON.parse(data.ResultJson);
var holdtime = -1;
if(result.holdtime !== undefined)
holdtime = result.holdtime;
//判斷 TransferLot 執行結果, 檢查是不是FutureHold/Wait
if(result.hasOwnProperty('Hold_ExceedTime') || RuleNo == $rootScope.strExceedTime_Rule) {
//PC動作BRERFCreateExecute(pUserId:=strExeUserNo, pLotNo:=LotNo, pERFType:=1, pHoldTime:=0, pRuleNo:=strExceedTime_Rule)
var ERFData =[];
ERFData.push({
pLotNo: LotNo,
pUserId: UserNo,
pERFType: 1,
pHoldTime: 0,
pRuleNo: "EXCEEDTIME",
pGotoProgram: "wp_excute_lot"
});
// wp05_lot_erf_create 預設 $scope.HoldTime = 0
$wp05_lot_erf_create.init({ data: { ERFData } });
bolERFCreate = true;
}
else if(result.hasOwnProperty('FutureHold')) {
var ERFData =[];
ERFData.push({
pLotNo: LotNo,
pUserId: UserNo,
pERFType: 3,
pHoldTime: holdtime,
pGotoProgram: "wp_excute_lot"
});
$wp05_lot_erf_create.init({ data: { ERFData } });
bolERFCreate = true;
}
else if(result.hasOwnProperty('FutureWait')) {
var strWaitDescription = "";
if (result.WaitDescription != null && result.WaitDescription != undefined) {
strWaitDescription = result.WaitDescription;
}
//批號:XXXXX 是預先等待!
$rootScope.showAlert($filter('translate') ('common.lotno') +LotNo +$filter('translate') ('common.msg.isfuturewait') + "!" +strWaitDescription);
}
else if (result.hasOwnProperty('FutureOS')) {
// 批號:XXXXX 是預先外包設定,請使用臨時外包
$rootScope.showAlert($filter('translate')('common.lotno') + LotNo + $filter('translate')('common.msg.isfutureospleaseusethetemporaryoutsourcing'));
}
if (bolERFCreate) {
$timeout(function () {
$rootScope.CheckInOut_After(LotNo, LinkName, isci);
}, 500);
}
else {
$rootScope.CheckInOut_After(LotNo, LinkName, isci);
}
}
});
}
}
$rootScope.ReverseTriggerOP_NotUseUndo = function (pLotNo, pLotSerial, pLotStamp, callback, error) {
$MMWService.sendToMESSrv({
uri: 'wsWIP.ReverseTriggerOP_NotUseUndo',
content: {
Lotno: pLotNo,
LotSerial: pLotSerial,
LotStamp: pLotStamp
},
success: function (data) {
if (callback)
callback(data);
},
error: function (data) {
if (callback)
callback(error);
}
});
}
//#endregion
//#region 共用其他
/***
* 顯示 local Notification, 由App本身所觸發的通知
* 此部分有加入使用html5 實作 web browser 通知
* data {
* id : id表示此訊息的身分,當有兩個相同的id時,後者會覆蓋前者
* msg : 通知的訊息
* sound : 通知的聲音, 預設是file://sound/sound.mp3
* target : 點擊通知訊息後會開啟的頁面
* }
*/
$rootScope.ShowNotification = function (data, prepareData, clickHandler) {
try {
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
cordova.plugins.notification.local.schedule(prepareData(data));
cordova.plugins.notification.local.on("click", clickHandler(data), this);
} else {
//產生HTML5的通知
Notification.requestPermission(function (permission) {
var feedbackData = prepareData(data);
var notification = new Notification(feedbackData.title, {
body: feedbackData.text,
dir: 'auto'
});
notification.click = function () {
window.location = "/";
}
});
}
} catch (error) {
console.log(error);
}
}
// Open Background Service
$rootScope.OpenBackgroundService = function (data) {
try {
// Android customization
cordova.plugins.backgroundMode.setDefaults(data);
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
}
} catch (error) {
console.log(error);
}
}
// Screen always on
$rootScope.DisplayOn = function (ScreenOn) {
if (window.plugins) {
if (ScreenOn)
window.plugins.insomnia.keepAwake();
else
window.plugins.insomnia.allowSleepAgain();
}
}
// open Server Send Event Connection
$rootScope.openSSECenection = function (config, prepareData, clickHandler) {
if (typeof (EventSource) !== "undefined") {
var server = config.server;
var source = new EventSource('http://' + server.ip + ':' + server.port + '/' + server.name + '/' + 'startSSE');
source.addEventListener('open', function (e) {
//console.log("Open Connection");
}, false);
//Set CallbackFunction
source.addEventListener('message', function (msg) {
//console.log("SSE get message ");
//console.log(msg.data);
var data = JSON.parse(msg.data);
if (data.command == 'refresh') {
if ($rootScope.refresh != undefined) {
$rootScope.refresh(data);
}
if (data.equipment && config.setting.machineNot) {
$rootScope.ShowNotification(data, prepareData, clickHandler);
}
}
});
source.addEventListener('error', function (e) {
console.log(e);
try {
if (cordova.plugins.backgroundMode.isEnabled()) {
cordova.plugins.backgroundMode.configure({
text: $filter('translate')('error.connectRefused')
});
}
} catch (error) {
console.log(error);
}
source.close();
console.log('prepare alert');
$MDLUtirlity.alert($filter('translate')('error.connectRefused'), function () {
$rootScope.openSSECenection();
$MDLUtirlity.alertClose();
});
}, false);
} else {
console.log('Your browser don\'t support SSE.');
}
}
/**
* open Camera for barcode/QRcode scan
* options {
* descript,
* after,
* exception,
* formats,
* orientation // Android only (portrait|landscape), default unset so it rotates with the device
* }
*/
$rootScope.OpenScanner = function (options) {
//options.formats = options.formats||"QR_CODE";
options.orientation = options.orientation || "unset";
options.descript = options.descript || "";
setTimeout(function () {
$rootScope.showLoading();
$rootScope.$apply();
setTimeout(function () {
try {
/***
* result.text
* Format: " + result.format
* result.cancelled
*/
cordova.plugins.barcodeScanner.scan(
function (result) {
$rootScope.hideLoading(true);
$rootScope.$apply();
if (options.after)
options.after(result);
},
function (error) {
$rootScope.hideLoading(true);
$rootScope.$apply();
}, {
"preferFrontCamera": false, // iOS and Android //使用前鏡頭
"showFlipCameraButton": false, // iOS and Android //切換前後鏡頭
"prompt": options.descript, // 掃描的文字
"formats": options.formats, // 要掃描的格式
"orientation": options.orientation // Android only (portrait|landscape), default unset so it rotates with the device
}
);
} catch (e) {
$rootScope.hideLoading(true);
$rootScope.$apply();
if (options.exception)
options.exception();
}
}, 400);
}, 200);
}
$rootScope.getService = function (options, callback) {
if (arguments.length == 2) {
if ($injector.has(options.name)) {
if (typeof (callback) == 'function') {
callback($injector.get(options.name));
}
} else {
try {
//動態建立 service
require([options.controllerUrl.replace('.js', '')], function () {
callback($injector.get(options.name));
}, function (e) {
$rootScope.showAlert("");
});
} catch (e) {
$rootScope.showAlert({
title: 'error.cant_load_service',
code: 999,
message: 'error.cant_load_service',
exception: e.message,
stack: e.stack,
});
}
}
} else {
console.error('ServiceDialog need call with arguments[ service_name, callback]');
}
}
//#endregion
//auto logout
var LogoutTimer = (function () {
var reciprocalTime = 0;
var timer;
function LogoutTimer(rt) {
if (rt)
reciprocalTime = rt;
}
LogoutTimer.prototype.start = function (rt) {
if (!timer) {
if (rt)
reciprocalTime = rt;
reciprocal();
}
}
LogoutTimer.prototype.stop = function () {
clearTimeout(timer);
timer = undefined;
}
LogoutTimer.prototype.refresh = function (rt) {
LogoutTimer.prototype.stop();
LogoutTimer.prototype.start(rt);
}
function reciprocal() {
if (reciprocalTime != 0) {
timer = setTimeout(function () {
//$rootScope.hideMenu();
//$rootScope.changeProgram('login',true);
$MMWService.sendToMESSrv_plain({
uri: 'wsUSR.ClearLoginInfo_plainjson',
content: {
userno: config.cache.account,
computername: config.client.ip,
sessionid: config.mdssessionno
},
success: function (data) {
$rootScope.hideMenu();
$timeout(function () {
$rootScope.changeProgram("login", true);
}, 200);
}
});
}, reciprocalTime * 60 * 1000);
} else {
console.warn('config.setting.timeout is 0, auto logout wound\'t start');
}
}
return LogoutTimer;
})();
var logoutTimerIns;
$rootScope.reciprocalStart = function () {
logoutTimerIns = new LogoutTimer(config.setting.timeout);
logoutTimerIns.start();
}
$rootScope.reciprocalRestart = function () {
if (logoutTimerIns)
logoutTimerIns.refresh();
}
/*
//fix keyboard cover input problem - only work with 'Material Design Lite' framework and cordova-keyboard-plugin
window.addEventListener('native.keyboardshow', function(info) {
var element = document.activeElement;
if(element!=undefined && element.tagName == 'INPUT'){
$timeout(function(){
if($location.hash() == element.id){
// set the $location.hash to `newHash` and
// $anchorScroll will automatically scroll to it
$anchorScroll();
} else{
// call $anchorScroll() explicitly,
// since $location.hash hasn't changed
$location.hash(element.id);
}
});
}
});
*/
/*
if($ && $.jqplot && $.jqplot.postDrawHooks){
$.jqplot.preDrawHooks.push(function(){
$rootScope.showLoading();
});
$.jqplot.postDrawHooks.push(function(){
$rootScope.hideLoading();
});
}
*/
//20170809 modify by Dustdusk for 開啟虛擬鍵盤
if ($rootScope.platform != 'web' && $rootScope.platform != 'cordova') {
$(document).on('click', 'input', function (event) {
if (config.setting.virtualKeyboard == 'Y') {
if (!$(event.currentTarget).is('[readonly]') && !$(event.currentTarget).is('[disabled]')) {
const exec = window.nodeRequire('child_process').exec;
exec('start /d "C:\\Program Files\\Common Files\\microsoft shared\\ink" TabTip.exe', function (error, stdout, stderr) {
if (error) {
console.error(error);
return;
}
});
}
}
});
}
}
]).controller('gallery', ["$scope", "$gallery", function ($scope, $gallery) {
$scope.gallery = $gallery;
}]).provider('$gallery', function () {
this.$get = ["$rootScope", "$controller", function ($rootScope, $controller) {
return {
url: '',
title: '',
isHide: true,
hide: function () {
this.isHide = true;
if (this.feedback) {
this.feedback();
}
},
show: function (title, url, feedback) {
this.title = title;
this.url = url;
this.feedback = feedback;
this.isHide = false;
try {
StatusBar.backgroundColorByHexString("#000000");
} catch (e) { }
},
feedback: null
};
}];
})
.directive('kmiReportPanel', ["$rootScope", "$filter", function ($rootScope, $filter) {
return {
restrict: "C",
replace: true,
templateUrl: "program/C00/C00.html",
link: function (scope, elem, attrs, ctrl) {
scope.queryMode = 'query';
scope.addCondition = function () {
scope.conditionList.push({ column_name: '', query_mode: '', value: '' });
};
scope.removeCondition = function (index, item) {
scope.conditionList.splice(index, 1);
}
//設定查詢畫面的"欄位"有哪些
scope.loadCodeList = function (item, $index) {
if (!item.require) {
$rootScope.showSelect({
title: $filter('translate')('common.report.condition_fields'),
label: 'name',
code: 'column_name',
selectCode: item.column_name,
list: scope.codeList,
confirm: function (selectItem, dialog) {
item.modeList = [];
item.query_name = undefined;
item.query_mode = undefined;
item.data_type = undefined;
item.value = undefined;
item = angular.extend(item, selectItem);
dialog.hide();
}
});
}
};
//根據欄位的modeList決定他條件有哪些
scope.loadTypeList = function (item, $index) {
if (!item.require) {
if (item.modeList) {
$rootScope.showSelect({
title: $filter('translate')('common.condition_title'),
label: 'name',
code: 'code',
selectCode: item.code,
list: item.modeList,
confirm: function (selectItem, dialog) {
item.query_name = selectItem.name;
item.query_mode = selectItem.code;
dialog.hide();
}
});
}
}
};
scope.changeDate = function (item, date) {
item.value_s = moment(new Date()).subtract(date, 'days').toDate();
item.value_e = new Date();
item.date_type = date;
}
$rootScope.genConditioninfo = function () {
var query_condition_info = [];
scope.conditionList.forEach(function (condition) {
if (condition.data_type == 'D-SE') {
query_condition_info.push({
column_name: condition.column_name_s,
query_mode: 4,
merge_condition_model: 'AND',
value: moment(condition.value_s).format('YYYY-MM-DD')
});
query_condition_info.push({
column_name: condition.column_name_e,
query_mode: 5,
merge_condition_model: 'AND',
value: moment(condition.value_e).format('YYYY-MM-DD')
});
} else if (condition.column_name != '' && condition.query_mode != '' && condition.value && condition.value != '') {
var query_conditoin = {};
query_conditoin.column_name = condition.column_name;
query_conditoin.query_mode = condition.query_mode;
query_conditoin.merge_condition_model = 'AND';
if (condition.data_type == 'D') {
query_conditoin.value = moment(condition.value).format('YYYY-MM-DD');
} else {
query_conditoin.value = condition.value;
}
query_condition_info.push(query_conditoin);
}
});
return query_condition_info;
};
}
}
}]);
});