import {
|
LightningElement,
|
wire,
|
api
|
} from 'lwc';
|
import {
|
CurrentPageReference
|
} from "lightning/navigation";
|
import {
|
CloseActionScreenEvent
|
} from 'lightning/actions';
|
import init from '@salesforce/apex/buttonAssetCtl.init';
|
import initUserName from '@salesforce/apex/buttonAssetCtl.initUserName';
|
import selecctAccountByAccountId from '@salesforce/apex/buttonAssetCtl.selecctAccountByAccountId';
|
import selecctProduct2ById from '@salesforce/apex/buttonAssetCtl.selecctProduct2ById';
|
import selecctRepairByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctRepairByFomatToday';
|
import selecctQISReportByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctQISReportByFomatToday';
|
import {
|
NavigationMixin
|
} from 'lightning/navigation';
|
import {
|
encodeDefaultFieldValues
|
} from 'lightning/pageReferenceUtils';
|
import LightningConfirm from 'lightning/confirm';
|
import {
|
ShowToastEvent
|
} from 'lightning/platformShowToastEvent';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader'
|
export default class LexCreateRepairFromAsset extends NavigationMixin(LightningElement) {
|
@api recordId;
|
str;
|
IsLoading = true;
|
Id;
|
userID;
|
EmployeeNoC;
|
day;
|
day1;
|
day2;
|
Name;
|
NoPartRiskDateFC;
|
ProductIDC;
|
AccountId;
|
HPIdC;
|
HospitalC;
|
DepartmentClassC;
|
HospitalId;
|
DepartmentClassId;
|
RepairSalesPointProvinceChinaC;
|
partSupplyFinishDate;
|
notCreateRepairFromAssetButton;
|
notCreateRepairFromAssetButton02;
|
msg;
|
flag = false;
|
fomatToday;
|
QIS_Name = '';
|
QIS_Id = '';
|
Old_Repair_Name = '';
|
Work_Location = '';
|
FSE_GI_Main_Leader__id = '';
|
FSE_GI_Main_Leader__name = '';
|
FSE_SP_Main_Leader__id = '';
|
FSE_SP_Main_Leader__name = '';
|
Incharge_Staff = '';
|
Incharge_Staff_id = '';
|
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback() {
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
init({
|
recordId: this.recordId
|
}).then(result => {
|
console.log(result);
|
if (result != null) {
|
this.Id = result.Id;
|
this.userID = result.userID;
|
this.day = result.day;
|
this.day1 = result.day1;
|
this.day2 = result.day2;
|
this.Name = result.Name;
|
this.NoPartRiskDateFC = result.NoPartRiskDateFC == undefined ? "" : result.NoPartRiskDateFC;
|
this.ProductIDC = result.ProductIDC == undefined ? "" : result.ProductIDC;
|
this.AccountId = result.AccountId == undefined ? "" : result.AccountId;
|
this.HPIdC = result.HPIdC == undefined ? "" : result.HPIdC;
|
this.HospitalC = result.HospitalC == undefined ? "" : result.HospitalC;
|
this.DepartmentClassC = result.DepartmentClassC == undefined ? "" : result.DepartmentClassC;
|
this.HospitalId = result.HospitalId == undefined ? "" : result.HospitalId;
|
this.DepartmentClassId = result.DepartmentClassId == undefined ? "" : result.DepartmentClassId;
|
this.notCreateRepairFromAssetButton = result.notCreateRepairFromAssetButton;
|
this.notCreateRepairFromAssetButton02 = result.notCreateRepairFromAssetButton02;
|
console.log('result.partSupplyFinishDate-------->>>>'+result.partSupplyFinishDate);
|
this.partSupplyFinishDate = result.partSupplyFinishDate == undefined ? "" :result.partSupplyFinishDate;
|
|
initUserName({
|
userId: this.userID
|
}).then(result => {
|
console.log(result);
|
if (result != null) {
|
this.EmployeeNoC = result[0].Employee_No__c;
|
this.RepairSalesPointProvinceChinaC = result[0].RepairSalesPoint_Province_China__c;
|
}
|
this.CreateRepairFromAsset();
|
})
|
}
|
}).catch(error => {
|
console.log(error);
|
})
|
}
|
|
// 新建修理
|
CreateRepairFromAsset() {
|
var nCRepairFromAssetBSting = this.notCreateRepairFromAssetButton;
|
var nCRepairFromAssetB02Sting = this.notCreateRepairFromAssetButton02;
|
nCRepairFromAssetBSting = nCRepairFromAssetBSting + nCRepairFromAssetB02Sting;
|
var nCRepairFromAssetBList = nCRepairFromAssetBSting.split(',');
|
var EmployeeNo = this.EmployeeNoC;
|
console.log(nCRepairFromAssetBList.indexOf(EmployeeNo) != -1,'权限判断')
|
if (nCRepairFromAssetBList.indexOf(EmployeeNo) != -1) {
|
this.ShowToastEvent("对不起,您无权使用此按钮创建修理!", "error");
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
|
this.fomatToday = this.day1;
|
|
|
selecctQISReportByFomatToday({
|
AssetId: this.Id,
|
fomatToday: this.fomatToday
|
}).then(records => {
|
console.log(records,'records<<<<<<<<')
|
if (records.length >= 1) {
|
this.QIS_Name = records[0].Name;
|
this.QIS_Id = records[0].Id;
|
}
|
if (records.length >= 1) {
|
this.handleConfirmClick01('请确认此件是否属于10天内重复报告,如果是,请使用原QIS信息填写。');
|
} else {
|
this.Repair();
|
}
|
|
})
|
}
|
|
Repair() {
|
selecctRepairByFomatToday({
|
AssetId: this.Id,
|
fomatToday: this.fomatToday
|
}).then(records2 => {
|
console.log(records2);
|
|
//20231108 ymh 修改 satrt
|
if (records2.length >= 1) {
|
this.Old_Repair_Name = records2[0].Name;
|
}
|
if (records2.length >= 1) {
|
this.handleConfirmClick02('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? ');
|
} else {
|
this.ContactYesOrNo();
|
}
|
|
// var partSupplyFinishDate = this.NoPartRiskDateFC;
|
// if (this.day < this.NoPartRiskDateFC && this.NoPartRiskDateFC <= this.day2) {
|
// this.ShowToastEvent('预计' + partSupplyFinishDate + '零件即将停产,请送修前与工厂及RC联络', "error");
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
// return;
|
// }
|
// console.log(this.NoPartRiskDateFC ,'this.NoPartRiskDateFC ')
|
// if (this.NoPartRiskDateFC != "" && this.NoPartRiskDateFC != null && this.NoPartRiskDateFC != undefined && this.NoPartRiskDateFC <= this.day) {
|
// this.ShowToastEvent('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络', "error");
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
// return;
|
// }
|
// if (records2.length >= 1) {
|
// this.Old_Repair_Name = records2[0].Name;
|
// }
|
// if (records2.length >= 1) {
|
// this.handleConfirmClick02('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? ');
|
// } else {
|
// this.Product2();
|
// }
|
// 20231108 ymh 修改 end
|
})
|
}
|
//20231108 ymh add start
|
async ContactYesOrNo(){
|
var partSupplyFinish = this.partSupplyFinishDate;
|
console.log(this.partSupplyFinishDate ,'this.partSupplyFinishDate ')
|
if (this.day < this.partSupplyFinishDate && this.partSupplyFinishDate <= this.day2) {
|
if (!this.handleConfirmClickYesOrNo('预计' + partSupplyFinish + '零件即将停产,请送修前与工厂及RC联络')) {
|
return;
|
}
|
}else if (this.partSupplyFinishDate != "" && this.partSupplyFinishDate != null && this.partSupplyFinishDate != undefined && this.partSupplyFinishDate <= this.day) {
|
if (!this.handleConfirmClickYesOrNo('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络')) {
|
return;
|
}
|
}else{
|
this.Product2();
|
}
|
}
|
//20231108 ymh add end
|
|
|
async handleConfirmClickYesOrNo(msg) {
|
const result = await LightningConfirm.open({
|
message: msg,
|
variant: 'headerless',
|
label: 'this is the aria-label value'
|
});
|
if (result) {
|
this.Product2();
|
} else {
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|
|
Product2() {
|
|
selecctProduct2ById({
|
Id: this.ProductIDC
|
}).then(recordP => {
|
console.log(recordP);
|
|
if (recordP != null && recordP.length > 0) {
|
var canRepair = recordP[0].Can_Repair__c;
|
if (canRepair == '第三方') {
|
this.ShowToastEvent('非我司修理对象,无法新建修理,如有不明请咨询CIC', "error");
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
if (canRepair == '不' || canRepair == null) {
|
this.ShowToastEvent('本设备无法新建修理', "error");
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
if (canRepair == 'RC送修') {
|
this.flag = true;
|
}
|
}
|
selecctAccountByAccountId({
|
AccountId: this.AccountId
|
}).then(List => {
|
console.log(List);
|
if (List != null) {
|
var RecordTypeId = List[0]['Parent']['RecordType_DeveloperName__c'];
|
console.log(RecordTypeId);
|
if (RecordTypeId != 'Agency') {
|
if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
|
this.FSE_GI_Main_Leader__id = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'];
|
this.FSE_GI_Main_Leader__name = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Name'];
|
}
|
if (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
|
this.FSE_SP_Main_Leader__id = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'];
|
this.FSE_SP_Main_Leader__name = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Name'];
|
}
|
if (List[0]['Parent']['RecordType_DeveloperName__c'] != null || List[0]['Parent']['RecordType_DeveloperName__c'] != undefined) {
|
var recordId = List[0]['Parent']['RecordType_DeveloperName__c'];
|
if (recordId == 'Department_Class_GI' || recordId == 'Department_Class_BF' || recordId == 'Department_Class_ET') {
|
if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
|
this.Work_Location = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Work_Location__c'];
|
}
|
} else if (recordId == 'Department_Class_GS' || recordId == 'Department_Class_URO' || recordId == 'Department_Class_ENT' || recordId == 'Department_Class_GYN' || recordId == 'Department_Class_OTH') {
|
if (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
|
this.Work_Location = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c'];
|
}
|
|
}
|
console.log(this.Work_Location,List[0],'xxxx')
|
}
|
if (RecordTypeId == 'Department_Class_GI') {
|
this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_BF') {
|
this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_ET') {
|
this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_GS') {
|
this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_URO') {
|
this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_ENT') {
|
this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_GYN') {
|
this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
|
}
|
if (RecordTypeId == 'Department_Class_OTH') {
|
this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
|
this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
|
}
|
}
|
}
|
const url = encodeDefaultFieldValues({
|
Hospital__c: this.HospitalId,
|
Department_Class__c: this.DepartmentClassId,
|
Account__c: this.AccountId,
|
Delivered_Product__c: this.Id,
|
Incharge_Staff__c: this.Incharge_Staff_id,
|
Work_Location_select__c: this.RepairSalesPointProvinceChinaC,
|
SalesOfficeCode_selection__c: this.Work_Location,
|
Source_QIS__c: this.QIS_Id,
|
Old_Name__c: this.Old_Repair_Name,
|
Exc_Work_Location__c: this.flag,
|
Repair_Source__c:'只修理',
|
//2023 08 22 张赫阳 PIPL相关按钮改造 start
|
AssetName: this.Name
|
//2023 08 22 张赫阳 PIPL相关按钮改造 end
|
});
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'Repair__c',
|
actionName: 'new'
|
},
|
state: {
|
//2023 08 22 张赫阳 PIPL相关按钮改造 start
|
//nooverride: '1',
|
//2023 08 22 张赫阳 PIPL相关按钮改造 end
|
defaultFieldValues: url
|
}
|
});
|
this.dispatchEvent(new CloseActionScreenEvent());
|
})
|
})
|
}
|
|
async handleConfirmClick01(msg) {
|
const result = await LightningConfirm.open({
|
message: msg,
|
variant: 'headerless',
|
label: 'this is the aria-label value'
|
});
|
if (result) {
|
this.Repair();
|
} else {
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|
|
async handleConfirmClick02(msg) {
|
const result = await LightningConfirm.open({
|
message: msg,
|
variant: 'headerless',
|
label: 'this is the aria-label value'
|
});
|
if (result) {
|
this.ContactYesOrNo();
|
} else {
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|
|
ShowToastEvent(msg, type) {
|
if(type == 'success'){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.dispatchEvent(event);
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode:'Sticky'
|
});
|
this.dispatchEvent(event);
|
}
|
}
|
|
closeAction() {
|
location.reload();
|
}
|
}
|