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'; export default class LexCreateRepairFromAsset extends LightningElement { @api recordId; str; IsLoading = true; Id; userID; EmployeeNoC; day; day1; day2; Name; NoPartRiskDateFC; ProductIDC; AccountId; HPIdC; HospitalC; DepartmentClassC; HospitalId; DepartmentClassId; RepairSalesPointProvinceChinaC; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback() { init({ recordId: this.recordId }).then(result => { console.log(result); if (result != null) { this.IsLoading = false; 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; this.ProductIDC = result.ProductIDC; this.AccountId = result.AccountId; this.HPIdC = result.HPIdC; this.HospitalC = result.HospitalC; this.DepartmentClassC = result.DepartmentClassC; this.HospitalId = result.HospitalId; this.DepartmentClassId = result.DepartmentClassId; initUserName({ userId: this.userID }).then(result => { console.log(result); if (result != null) { this.EmployeeNoC = result.Employee_No__c; this.RepairSalesPointProvinceChinaC = result.RepairSalesPoint_Province_China__c; } }) this.CreateRepairFromAsset(); this.dispatchEvent(new CloseActionScreenEvent()); } }).catch(error => { console.log(error); }) } // 新建修理 CreateRepairFromAsset() { var nCRepairFromAssetBSting = "{!$Label.notCreateRepairFromAssetButton}"; var nCRepairFromAssetB02Sting = "{!$Label.notCreateRepairFromAssetButton02}"; nCRepairFromAssetBSting = nCRepairFromAssetBSting + nCRepairFromAssetB02Sting; var nCRepairFromAssetBList = nCRepairFromAssetBSting.split(','); var EmployeeNo = this.EmployeeNoC; if (nCRepairFromAssetBList.indexOf(EmployeeNo) != -1) { alert("对不起,您无权使用此按钮创建修理!"); return; } var today = this.day1; todays = today.split("/"); fomatToday = todays[0] + '-' + todays[1] + '-' + todays[2]; var QIS_Name = ''; var QIS_Id = ''; var url1 = ""; var FSE_GI_Main_Leader__id = ''; var FSE_GI_Main_Leader__name = ''; var FSE_SP_Main_Leader__id = ''; var FSE_SP_Main_Leader__name = ''; var Incharge_Staff = ''; var Incharge_Staff_id = ''; selecctQISReportByFomatToday({ AssetId: this.Id, fomatToday: fomatToday }).then(records => { console.log(records); if (records.length >= 1) { var boolday = confirm('请确认此件是否属于10天内重复报告,如果是,请使用原QIS信息填写。'); if (!boolday) { return; } } if (records.length >= 1) { QIS_Name = records[0].Name; QIS_Id = records[0].Id; } }) selecctRepairByFomatToday({ AssetId: this.Id, fomatToday: fomatToday }).then(records2 => { console.log(records2); if (records2.length >= 1) { var boolday = confirm('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? '); if (!boolday) { return; } } var Old_Repair_Name = ''; if (records2.length >= 1) { Old_Repair_Name = records2[0].Name; } }) selecctProduct2ById({ Id: this.ProductIDC }).then(recordP => { console.log(recordP); if (recordP != null && recordP.length > 0) { var canRepair = recordP[0].Can_Repair__c; if (canRepair == '第三方') { alert('非我司修理对象,无法新建修理,如有不明请咨询CIC'); return; } if (canRepair == '不' || canRepair == null) { alert('本设备无法新建修理'); return; } if (canRepair == 'RC送修') { url1 = "&00N10000009HAJl=TRUE" } } }) selecctAccountByAccountId({ AccountId: this.AccountId }).then(List => { console.log(List); if (List != null) { var RecordTypeId = List['records']['Parent']['RecordTypeId'].substring(0, 15); if (RecordTypeId != '01210000000Qem1') { if (List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) { FSE_GI_Main_Leader__id = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'].substring(0, 15); FSE_GI_Main_Leader__name = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__r']['Name']; } if (List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) { FSE_SP_Main_Leader__id = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'].substring(0, 15); FSE_SP_Main_Leader__name = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__r']['Name']; } var Work_Location = ''; if (List['records']['Parent']['RecordTypeId'] != null || List['records']['Parent']['RecordTypeId'] != '') { var recordId = List['records']['Parent']['RecordTypeId'].substring(0, 15); if (recordId == '01210000000QemL' || recordId == '01210000000QezZ' || recordId == '01210000000QemQ') { if (List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) { Work_Location = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__r']['Work_Location__c']; } } else if (recordId == '01210000000Qeze' || recordId == '01210000000Qezj' || recordId == '01210000000Qezt' || recordId == '01210000000Qezo' || recordId == '01210000000Qezy') { if (List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) { Work_Location = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c']; } } } if (RecordTypeId == '01210000000QemL') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeId == '01210000000QezZ') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeId == '01210000000QemQ') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeId == '01210000000Qeze') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeId == '01210000000Qezj') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeId == '01210000000Qezt') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeId == '01210000000Qezo') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeId == '01210000000Qezy') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } } } }) var partSupplyFinishDate = this.NoPartRiskDateFC; if (this.day < this.NoPartRiskDateFC && this.NoPartRiskDateFC <= this.day2) { alert('预计' + partSupplyFinishDate + '零件即将停产,请送修前与工厂及RC联络'); } if (this.NoPartRiskDateFC != null && this.NoPartRiskDateFC != undefined && this.NoPartRiskDateFC <= this.day) { alert('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络'); } var url = "/a0J/e?CF00N10000002Dx66_lkid=" + this.HospitalId + "&CF00N10000002Dx66=" + this.HospitalC + "&CF00N10000002Dx5t_lkid=" + this.DepartmentClassId + "&CF00N10000002Dx5t=" + this.DepartmentClassC + "&CF00N10000002Dx5n_lkid=" + this.Id + "&CF00N10000002Dx5n=" + this.Name + "&CF00N10000002Dx1X_lkid=" + this.Id + "&CF00N10000002Dx1X=" + this.Name + "&CF00N10000002EMHw_lkid=" + Incharge_Staff_id + "&CF00N10000002EMHw=" + Incharge_Staff + "&00N10000002FH86=%e5%8f%aa%e4%bf%ae%e7%90%86&00N10000006P6Rn=" + this.RepairSalesPointProvinceChinaC + "&00N10000006P6SM=" + encodeURI(Work_Location) + "&CF00N10000009H7yM=" + QIS_Name + "&CF00N10000009H7yM_lkid=" + QIS_Id + "&00N10000009H2fa=" + Old_Repair_Name + "&retURL=%2F" + this.Id; if (url1 != "") { url = url + url1; } window.open(url); } }