/* * @Date: 2023-05-16 13:32:13 * @Author: @zyh * @LastEditTime: 2024-02-23 18:18:35 * @Descripttion: */ import { LightningElement, wire, track, api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import { NavigationMixin } from 'lightning/navigation'; import init from '@salesforce/apex/lexRentalApply_FromRepCtl.init'; import userInfo from '@salesforce/apex/lexRentalApply_FromRepCtl.UserInfo_Owner'; import rentalApp from '@salesforce/apex/lexRentalApply_FromRepCtl.rentalApp'; import qureySoql from '@salesforce/apex/ControllerUtil.qureySoql'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import { loadStyle } from 'lightning/platformResourceLoader' import IFTradeComplianceAlertName from '@salesforce/label/c.IFTradeComplianceAlertName';// wyl 贸易合规2期 add export default class LexEquipmentRentalApply_FromRepair2 extends NavigationMixin(LightningElement) { @api recordId; //OpportunityId stauts1; repairId; repairName; hospital; repairDepartment; repairAccount; inspectionDate; shippedDate; assetModelNo; qisRepairId; qisId; qisRepairName; repairSource; maintenanceContract; purpose2; newProductGuaranteeObject; ifCheckFixture; IsLoading = true; isFormalStuff; userId; firstName; lastName; rtnJSON; records; dataFields; maintial; // 借用机会可视化-维保预判 estimateDate; // 借用机会可视化-报价日 agreeDate; // 借用机会可视化-同意报价日 dateCheck = false; // 借用机会可视化-判断是否新建 plannedRepairCompletedDate; // 修理预计完成日 mafinal; family; // 借用机会可视化-产品类型 IFTradeComplianceIntercept2;// WYL 贸易合规2期 add @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(111); console.log(currentPageReference); if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; console.log("str"); console.log(str); this.recordId = str; } } } connectedCallback() { console.log(this.recordId); this.IsLoading = false; Promise.all([ loadStyle(this, lwcCSS) ]); this.initRepairToApply(); } async initRepairToApply(){ await rentalApp({ recordId: this.recordId }).then(result => { console.log('rentalApp============', result); if (result.length > 0) { const evt = new ShowToastEvent({ // title : 'Error', message: '同一个型号的修理记录不能重复申请备品', variant: 'error', mode: 'sticky' }); this.dispatchEvent(evt); this.dispatchEvent(new CloseActionScreenEvent()); return; } else { init({ recordId: this.recordId }).then(initRes => { console.log('init============' + initRes); console.log(initRes); if (initRes != null) { userInfo({}).then(userRes => { this.userId = userRes.id; this.isFormalStuff = userRes.isFormalStuff; // this.firstName = result.firstName; this.lastName = userRes.lastName; }).catch(error => { console.log("error"); console.log(error); }).finally(() => { }); this.stauts1 = initRes.stauts1; this.repairId = initRes.repairId; this.repairName = initRes.repairName; this.hospital = initRes.hospital; this.inspectionDate = initRes.inspectionDate; this.shippedDate = initRes.shippedDate; this.qisId = initRes.qisId; this.newProductGuaranteeObject = initRes.newProductGuaranteeObject; this.maintenanceContract = initRes.maintenanceContract; this.repairSource = initRes.repairSource; this.ifCheckFixture = initRes.ifCheckFixture; this.repairDepartment = initRes.repairDepartment; this.repairAccount = initRes.repairAccount; this.maintial = initRes.maintial; // 借用机会可视化-维保预判 this.estimateDate = initRes.estimateDate; // 借用机会可视化-报价日 this.agreeDate = initRes.agreeDate; // 借用机会可视化-同意日 this.plannedRepairCompletedDate = initRes.plannedRepairCompletedDate; // 借用机会可视化-修理预计完成日 this.mafinal = initRes.mafinal; // 借用机会可视化-维保项目 // this.family = initRes.family; // 借用机会可视化-产品类型 this.IFTradeComplianceIntercept2 = initRes.IFTradeComplianceIntercept2;// WYL 贸易合规2期 add if (this.inspectionDate != null) { this.showToast('从修理做备品借出申请时,修理的[最终检测日]必须为空','error'); console.log('从修理做备品借出申请时,修理的[最终检测日]必须为空' + this.inspectionDate); return; } if (this.shippedDate != null) { this.showToast('从修理做备品借出申请时,修理的[RC修理品返送日]必须为空','error'); console.log('从修理做备品借出申请时,修理的[RC修理品返送日]必须为空' + this.shippedDate); return; } if (this.isFormalStuff == true) { this.showToast('试用期内,不能申请','error'); console.log('试用期内,不能申请' + this.isFormalStuff); return; } else if (this.stauts1 == '0.删除') { this.showToast('修理的状态为删除,不可借用备品','error'); console.log('修理的状态为删除,不可借用备品' + this.stauts1); return; } else if (this.stauts1 == '0.取消') { this.showToast('修理的状态为取消,不可借用备品','error'); console.log('修理的状态为取消,不可借用备品' + this.stauts1); return; } else if (this.stauts1 == '5.完毕') { this.showToast('修理的状态为完毕,不可借用备品','error'); console.log('修理的状态为完毕,不可借用备品' + this.stauts1); return; // 借用机会可视化 zyh start } else if (this.maintial == true && ((this.estimateDate == null && this.agreeDate == null) || (this.estimateDate == undefined && this.agreeDate == undefined) || this.mafinal != undefined) && this.maintenanceContract != undefined){ this.showToast('维保预判时,报价日/同意日为空,不可借用备品','error'); console.log('借用机会可视化============验证',this.maintial == true,this.estimateDate == null,this.agreeDate == null,this.mafinal != '',this.mafinal); return; // 借用机会可视化 zyh end } // WYl 贸易合规2期 start if (this.IFTradeComplianceIntercept2 == '1') { this.showToast('医院在黑名单中,存在贸易合规风险,无法新建备品借出申请,有问题请联系法务部贸易合规窗口'+IFTradeComplianceAlertName+'。','error'); return; }else if (this.IFTradeComplianceIntercept2 == '2') { this.showToast('医院在冻结清单中,可能存在贸易合规风险,目前正在评估中(一般需5-10个工作日),暂时无法新建备品借出申请,有问题请联系法务部贸易合规窗口'+IFTradeComplianceAlertName+'。','error'); return; } // WYl 贸易合规2期 end console.log('======='+this.maintial,this.estimateDate,this.maintenanceContract) if (this.qisId != '' && this.qisId != null) { console.log('qureySoql1===row'); var sql = "select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id ='" + this.recordId + "'"; this.selectSoql(sql); } else { console.log('qureySoql2===row'); console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"); var sql = "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"; this.selectSoql(sql); } setTimeout(() => { this.dispatchEvent(new CloseActionScreenEvent()); },10000); } }).catch(error => { console.log("error"); console.log(error); }).finally(() => { }); } }).catch(error => { console.log("error11"); console.log(error); }).finally(() => { }); } selectSoql(sql){ qureySoql({ soql: sql }).then(result => { console.log('qureySoql============' + result); this.rtnJSON = result; console.log('rtnJSON111111===row' + this.rtnJSON); this.records = JSON.parse(this.rtnJSON); this.repairToApply(); }).catch(error => { console.log("error"); console.log(error); }).finally(() => { }); } repairToApply() { console.log('repairToApply_Status============' + this.stauts1); if (this.stauts1 != '草案中') { var AssetModelNo = ''; if (this.records.length > 0) { console.log('records.lenth===row'); AssetModelNo = this.records[0].Delivered_Product__r.Product2.Asset_Model_No__c; console.log('records.lenth===qisId' + this.qisId); console.log('records.lenth===qisIdtest' + this.qisId != '' && this.qisId != null); if (this.qisId != '' && this.qisId != null) { this.qisRepairId = this.records[0].QIS_ID__r.Repair__c; this.qisRepairName = this.records[0].QIS_ID__r.Repair__r.Name; } } var isKeepRepair = false; if (this.newProductGuaranteeObject == '2: 服务多年保修' && (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A' || AssetModelNo == 'LTF-S190-10' || AssetModelNo == 'OER-AW' || AssetModelNo == 'URF-V' || AssetModelNo == 'URF-V2' || AssetModelNo == 'URF-P6')) { isKeepRepair = true; } var purpose2 = ''; if (this.repairSource != 'QIS转修理') { if (this.newProductGuaranteeObject == '8: 市场多年保修') { purpose2 = '市场多年保修'; } else if (this.maintenanceContract != null && this.maintenanceContract != '') { purpose2 = "保修用户"; } else if (this.ifCheckFixture) { purpose2 = "故障排查"; } else { if (isKeepRepair) { purpose2 = '保修用户'; } else { purpose2 = '一般用户'; } } } else { purpose2 = '索赔QIS'; } let defaultValues = { // RecordTypeId : '', Name: '*', //2023 7 11 update by 张赫阳 PIPL Start RepairName: this.repairName, //2023 7 11 update by 张赫阳 PIPL End Hospital__c: this.hospital, Strategic_dept__c: this.repairDepartment, Account__c: this.repairAccount, Demo_purpose1__c: '维修代用', demo_purpose2__c: purpose2, Person_In_Charge__c: this.userId, //备品出街担当 applyUser__c: this.userId, //操作者 Repair__c: this.repairId, Product_category__c: this.family, Loaner_received_staff__c: this.lastName // 收件者姓名 (销售或FSE) } this.dataFields = defaultValues; if (purpose2 == '索赔QIS' && this.qisId != null && this.qisId != '') { let defaultValues = { // RecordTypeId : '', Repair__c: this.repairId, //2023 7 11 update by 张赫阳 PIPL Start RepairName: this.repairName, //2023 7 11 update by 张赫阳 PIPL End Name: '*', Hospital__c: this.hospital, Strategic_dept__c: this.repairDepartment, Account__c: this.repairAccount, Demo_purpose1__c: '维修代用', demo_purpose2__c: purpose2, Person_In_Charge__c: this.userId, //备品出街担当 applyUser__c: this.userId, //操作者 Loaner_received_staff__c: this.lastName, // 收件者姓名 (销售或FSE) QISRepair__c: this.qisRepairId, QIS_number__c: this.qisId } this.dataFields = defaultValues; console.log('testzyh==='+this.qisRepairName); } if(this.plannedRepairCompletedDate != null){ if(confirm('修理预计完成日为'+this.plannedRepairCompletedDate+',是否确认新建申请单?')){ this.rentalApply(); }else { return; } }else { this.rentalApply(); } } else { this.showToast('申请修理后,才可以新建备品借出申请','error'); return; } } rentalApply(){ console.log('236===row12313' , this.dataFields); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Rental_Apply__c', actionName: 'new' }, state: { //nooverride: '1', defaultFieldValues: encodeDefaultFieldValues(this.dataFields) } }); console.log('236===row11111' + this.dataFields); } // 提醒、报错 showToast(msg,type) { if(type == "success"){ const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ title: '', message: msg, variant: type, mode:'sticky' }); this.dispatchEvent(event); } this.dispatchEvent(new CloseActionScreenEvent()); } }