import { LightningElement, track, wire ,api} from 'lwc'; import LightningConfirm from 'lightning/confirm'; import jquery183minjs from '@salesforce/resourceUrl/jquery183minjs'; import PleaseWaitDialog from '@salesforce/resourceUrl/PleaseWaitDialog'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import { CurrentPageReference } from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import TradeComplianceStatusFlagFW from '@salesforce/label/c.TradeComplianceStatusFlagFW'; import IFTradeComplianceAlert from '@salesforce/label/c.IFTradeComplianceAlert'; import init from "@salesforce/apex/lexMaintenanceContractUrlController.lexCustomNewContract"; import accSendEmailFW from "@salesforce/apex/OpportunityWebService.accSendEmailFW"; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; //sx 贸易合规2期 add import accSendEmailFW2 from "@salesforce/apex/lexSelectAssetEstimateVMController.accSendEmailFW"; // WYL 贸易合规2期 add import IFTradeComplianceAlertName from '@salesforce/label/c.IFTradeComplianceAlertName'; // WYL 贸易合规2期 add export default class lexCustomNewContract extends NavigationMixin(LightningElement) { @api recordId; IsLoading=true; name; Hospital; Department_Class; Department; Service_Contract_Staff; Estimate_Target; Dealer; recordtypeId; accDealerBlacklist; a=IFTradeComplianceAlert; b=TradeComplianceStatusFlagFW; //20231120 sx 贸易合规2期 add proTradeComplianceStatus; violationName; @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(){ Promise.all([ loadStyle(this, lwcCSS) ]); init({ recordId: this.recordId }).then(result => { if (result != null) { this.IsLoading = false; this.name = result.name; this.Hospital = result.hospital; this.Department_Class = result.department_Class; this.Service_Contract_Staff = result.service_Contract_Staff; this.Department = result.department; this.Estimate_Target = result.estimate_Target; this.Dealer = result.dealer; this.recordtypeId = result.recordtypeId; this.accDealerBlacklist = result.accDealerBlacklist; //sx 贸易合规 add start this.proTradeComplianceStatus = result.proTradeComplianceStatus; this.violationName = result.violationName; //sx 贸易合规 add end this.invid(); } }).catch(error => { console.log(error); }) } navigateToNewObjectPage() { // console.log('RepairApplicantName=='+this.RepairApplicantName); // console.log('this.id=='+this.id); const defaultFieldValues =encodeDefaultFieldValues({ Name: 'Copy of '+this.name, Hospital__c: this.Hospital, Department_Class__c: this.Department_Class, Service_Contract_Staff__c: this.Service_Contract_Staff, Department__c: this.Department, Estimate_Target__c:this.Estimate_Target, Dealer__c:this.Dealer, Last_year_service_contract__c:this.recordId, CopyFlg__c : true, NotUse_Oxygenated_Water__c : false, copyOfMc__c:this.recordId }); console.log('合同名='+this.name); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Maintenance_Contract__c', actionName: 'new' }, state: { nooverride: '1', defaultFieldValues: defaultFieldValues, recordTypeId: this.recordtypeId } }); this.dispatchEvent(new CloseActionScreenEvent()); } invid() { console.log('IFTradeComplianceAlert=='+this.a); console.log('TradeComplianceStatusFlagFW=='+this.b); console.log('accDealerBlacklist=='+this.accDealerBlacklist); if(this.b=='true'){ var oppflag=false; if(this.accDealerBlacklist==1){ const evt = new ShowToastEvent({ title : '您所选择的医院存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+this.a, message: '', variant: 'error', mode: 'sticky' }); this.dispatchEvent(evt); this.dispatchEvent(new CloseActionScreenEvent()); oppflag=true; }else if(this.accDealerBlacklist==2){ const evt = new ShowToastEvent({ title : '您所选择的医院存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+this.a, message: '', variant: 'error', mode: 'sticky' }); this.dispatchEvent(evt); this.dispatchEvent(new CloseActionScreenEvent()); oppflag=true; }else if(this.accDealerBlacklist==12){ const evt = new ShowToastEvent({ title : '您所选择的医院和经销商存在贸易合规风险,无法签订服务合同,建议您向客户做好不签约说明,'+this.a, message: '', variant: 'error', mode: 'sticky' }); this.dispatchEvent(evt); this.dispatchEvent(new CloseActionScreenEvent()); oppflag=true; }else if(this.accDealerBlacklist==5 || this.accDealerBlacklist==6 || this.accDealerBlacklist==56){ console.log('IFTradeComplianceAlert2=='+IFTradeComplianceAlert2); console.log(this.proTradeComplianceStatus); if(this.proTradeComplianceStatus == '0'){ accSendEmailFW2({ mcid : this.recordId, titles :'【贸易合规】--多年保修合同新建新服务合同涉及警示产品', type :'2', violationName:this.violationName.slice(0, -1) }) .then(result=>{ return; }).catch(err=>{ console.log('邮件错误'+err); }) LightningConfirm.open({ //message: '您所选择的医院存在贸易合规警示风险,不建议签订服务合同,请您确认是否继续申请,'+this.a, message: '您此次申请的业务可能存在贸易合规风险,请联系法务本部贸易合规窗口'+IFTradeComplianceAlertName+'进一步评估(一般需5-10个工作日)', variant: 'headerless', label: 'this is the aria-label value', }).then(cancel=>{ if(cancel) { this.navigateToNewObjectPage(); } else { this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); return; } }); }else{ this.navigateToNewObjectPage(); } } // else if(this.accDealerBlacklist==6){ // LightningConfirm.open({ // message: '您所选择的经销商存在贸易合规警示风险,不建议签订服务合同,请您确认是否继续申请,'+this.a, // variant: 'headerless', // label: 'this is the aria-label value', // }).then(cancel=>{ // if(cancel) { // this.navigateToNewObjectPage(); // } else { // this.IsLoading=false; // this.dispatchEvent(new CloseActionScreenEvent()); // return; // } // }); // }else if(this.accDealerBlacklist==56){ // LightningConfirm.open({ // message: '您所选择的医院和经销商存在贸易合规警示风险,不建议签订服务合同,请您确认是否继续申请,'+this.a, // variant: 'headerless', // label: 'this is the aria-label value', // }).then(cancel=>{ // if(cancel) { // this.navigateToNewObjectPage(); // } else { // this.IsLoading=false; // this.dispatchEvent(new CloseActionScreenEvent()); // return; // } // }); // } //20231211 贸易合规二期 add start // else if(this.hosTradeComplianceStatus == '警示名单' || this.deaTradeComplianceStatus == '警示名单'){ // if(result.proTradeComplianceStatus == '0'){ // LightningConfirm.open({ // message: '您所选择的客户/经销商和最新报价里的产品,存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert2+'(一般需5-10个工作日)。', // variant: 'headerless', // label: 'this is the aria-label value', // }).then(confirm=>{ // if(confirm){ // this.navigateToNewObjectPage(); // }else{ // this.IsLoading=false; // this.dispatchEvent(new CloseActionScreenEvent()); // return; // } // }).catch(err=>{ // console.log('贸易合规2err====='+err.getMessage()); // }) // } // }//20231211 贸易合规二期 add end else{ this.navigateToNewObjectPage(); } console.log('oppflag=='+oppflag); if(oppflag){ var FSEStr1 = new Array(); accSendEmailFW({ AccDealerBlacklist:this.accDealerBlacklist, accname:this.Hospital, angency:this.Dealer, mcid:this.recordId, sendalert:'Main_Con', FSEStr:FSEStr1 }) .then(result=>{ return; }).catch(err=>{ console.log(error); }) } } else { this.navigateToNewObjectPage(); } } }