This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
SXS20240115/SRC/iMES_PAD/module/moduleWIP/program/dialog/keyinattrib/keyinattrib.js
2024-01-24 16:47:50 +08:00

266 lines
8.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

define(["angularAMD"], function (angularAMD) {
angularAMD.service('keyinattrib', ['$rootScope', '$filter', 'config', 'MMWService', '$mdDialog', '$calculater',
function ($rootScope, $filter, config, $MMWService, $mdDialog, $calculater) {
/***
* options : {
* br : {} //報工狀態
* keyinattribList: //特性資料
* callback : function //結束後呼叫的方法
* close : function //關閉後呼叫的方法
* }
*/
var type_list = [
{ code: 'True', name: 'True' },
{ code: 'False', name: 'False' }
];
var excludeList = [
"GoodQty", "ScrapQty", "DefectQty"
];
$rootScope.btn_switch = '0';
$rootScope.btn_status_filter = function (data) {
console.log(data);
$rootScope.btn_switch = $rootScope.btn_switch == '2' ? '0' : '2';
}
this.init = function (options) {
function initAttrib() {
var removeList = [];
for (var index in options.keyinattribList) {
var item = options.keyinattribList[index];
if (item.data_show != "1" || item.attrib_source != "0" || item.attrib_no.includes("SOP"))
removeList.push(index);
}
for (i = removeList.length - 1; i >= 0; i--) {
options.keyinattribList.splice(removeList[i], 1);
}
//先儲存所有Attrib作為User取消Attrib輸入的還原點。
var aryorgattrib = [];
var i;
for (i = 0; i <= options.keyinattribList.length - 1; i++) {
var arytemp = { orgattribvalue: '' };
arytemp.orgattribvalue = options.keyinattribList[i].attrib_value;
aryorgattrib.push(arytemp);
}
return {
br: options.br,
aryorgattrib: aryorgattrib
}
}
(function openDialog() {
$mdDialog.dialog('module/moduleWIP/program/dialog/keyinattrib/keyinattrib.tmp.html',
function (dialog) {
return {
css_url:'module/moduleWIP/program/dialog/keyinattrib/keyinattrib.css',
platform: config.cache.platform,
AttribItem: initAttrib(),
attriblist: options.keyinattribList.slice(), //copy array
attrib_value:'',
back: function () {
//返回還原所有Attrib
var i;
for (i = 0; i <= dialog.attriblist.length - 1; i++) {
dialog.attriblist[i].attrib_value = dialog.AttribItem.aryorgattrib[i].orgattribvalue;
}
dialog.hide();
if (options.close)
options.close();
},
background: {
click: function () {
dialog.hide();
if (typeof (feedback) == 'function')
feedback();
}
},
input_boolean: function (item) {
$rootScope.showSelect({
title: $filter('translate')('common.msg.plz_select'),
label: 'name',
code: 'code',
order: 'code',
selectCode: item.code,
list: type_list,
confirm: function (s_item, s_dialog) {
s_dialog.hide();
item.attrib_value = s_item.code;
}
});
},
confirm: function () {
//20200526 雋辰,檢查必須輸入之欄位
for (var index in dialog.attriblist) {
var item = dialog.attriblist[index];
if (excludeList.indexOf(item.attrib_no) >= 0) continue;
if (item.attrib_allownull == "0") {
//20200610 雋辰,boolean類型固定有基礎值無須檢查
if (item.data_type == 4)
continue;
if ((item.data_type != "3" && !item.attrib_value) ||
(item.data_type == "3" && !item.attrib_value_date)) {
$rootScope.showAlert(item.attrib_name + ' ' + $filter('translate')('dialog.keyinattrib.notInput'));
return false;
}
}
}
//20200526 雋辰,日期類型給予值,未知原因提早給予值又alert會導致date format字串異常
for (var index in dialog.attriblist) {
var item = dialog.attriblist[index];
if (item.data_type == "3" && item.attrib_value_date)
item.attrib_value = moment(item.attrib_value_date);
}
if (options.callback)
options.callback(options.plotItem, dialog.attriblist);
dialog.hide();
},
scanQrcode: function (index) {
$rootScope.OpenScanner({
after: function (result) {
dialog.attriblist[i].attrib_value = result.text;
},
exception: function () {
//目前裝置無法使用相機
$rootScope.showAlert($filter('translate')('common.msg.camera_not_support'));
},
orientation: "landscape"
});
},
LoadElementValue: function (attrib_no,index) {
LoadElementValue(attrib_no, function (data) {
if (data.SYSElementValue.length > 0) {
$rootScope.showSelect({
title: $filter('translate')('dialog.keyinattrib.VALIDLIST'),
label: 'VALIDLIST',
code: 'VALIDLIST',
order: 'VALIDLIST',
selectCode: '',
list: data.SYSElementValue,
confirm: function (s_item, s_dialog) {
s_dialog.hide();
dialog.attriblist[index].attrib_value = s_item.VALIDLIST;
}
});
} else {
$rootScope.showAlert($filter('translate')('dialog.keyinattrib.NONVALIDLIST'));
}
});
}
}
});
})();
}
$rootScope.barcodeScan = function () {
if (event.keyCode == 13) {
var target;
if (event) {
target = event.currentTarget
target.blur();
}
this.search(target);
}
}
$rootScope.trackOutInputDateofHour = function (event, item) {
var target = event.currentTarget;
angular.element(target).addClass('is-focus');
$calculater.open(function (num, calcDialog) {
if ((+num).length > 2 || (+num) >= 24) {
$rootScope.showAlert($filter('translate')('dialog.keyinattrib.wronghour'));
} else {
angular.element(target).removeClass('is-focus');
item.attrib_value_h = num;
calcDialog.hide();
}
},
function (calcDialog) {
angular.element(target).removeClass('is-focus');
calcDialog.hide();
},
{
title: $filter('translate')('dialog.keyinattrib.inputhour'),
decimal: true
});
}
$rootScope.trackOutInputDateofMinute = function (event, item) {
var target = event.currentTarget;
angular.element(target).addClass('is-focus');
$calculater.open(function (num, calcDialog) {
if ((+num).length > 2 || (+num) >= 60) {
$rootScope.showAlert($filter('translate')('dialog.keyinattrib.wrongminute'));
} else {
angular.element(target).removeClass('is-focus');
item.attrib_value_m = num;
calcDialog.hide();
}
},
function (calcDialog) {
angular.element(target).removeClass('is-focus');
calcDialog.hide();
},
{
title: $filter('translate')('dialog.keyinattrib.inputminute'),
decimal: true
});
}
$rootScope.trackOutInputDateofSecond = function (event, item) {
var target = event.currentTarget;
angular.element(target).addClass('is-focus');
$calculater.open(function (num, calcDialog) {
if ((+num).length > 2 || (+num) >= 60) {
$rootScope.showAlert($filter('translate')('dialog.keyinattrib.wrongsec'));
} else {
angular.element(target).removeClass('is-focus');
item.attrib_value_s = num;
calcDialog.hide();
}
},
function (calcDialog) {
angular.element(target).removeClass('is-focus');
calcDialog.hide();
},
{
title: $filter('translate')('dialog.keyinattrib.inputsec'),
decimal: true
});
}
function LoadElementValue(attrib_no,callback) {
$MMWService.sendToMESSrv({
uri: 'kcSYS.clsSYSEng.LoadElementValue',
content: {
ElementNo: attrib_no
},
success: function (data) {
var data = JSON.parse(data.ResultJson);
if (callback) {
callback(data);
}
}
});
}
}
]);
});