import { LightningElement, api } from 'lwc'; import { NavigationMixin } from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import checkStatus from '@salesforce/apex/LexQISCloneButtonController.checkStatus'; import getClonedValues from '@salesforce/apex/LexQISCloneButtonController.getClonedValues'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆 export default class lexQISCloneButton extends NavigationMixin(LightningElement) { @api recordId; connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); window.clearTimeout(this.delayTimeout); this.delayTimeout = setTimeout(() => { this.handleClick(); }, 0); } handleClick(){ checkStatus({recordId: this.recordId}) .then(result => { console.log('result:', result); if (result) { //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆 start // var pageurl = '/lightning/cmp/c__LexQISPIPLAura?c__isClone=true&c__recordId=' + this.recordId; // this.navigate(pageurl); getClonedValues({ recordId: this.recordId, objectAPIName : 'QIS_Report__c' }).then(data => { console.log('this.recordId = ' + this.recordId); const map = new Map(Object.entries(data)); let keys = Object.keys(data); let finalObj = {}; for (let i = 0; i < keys.length; i++) { var skey = keys[i]; var val = map.get(keys[i]); if(val) { finalObj[skey] = val; } if (skey == 'QIS_Status__c') { finalObj[skey] = '草案中'; } } finalObj['QIS_pre__c'] = this.recordId; console.log('finalObj>>'+ JSON.stringify(finalObj)); // 创建导航事件 const defaultFieldValues = encodeDefaultFieldValues(finalObj); console.log('defaultFieldValues = ' + JSON.stringify(defaultFieldValues)); console.log('this.recordId = ' + this.recordId); this[NavigationMixin.Navigate]({ type: "standard__objectPage", attributes: { objectApiName: 'QIS_Report__c', actionName: "new", recordId: this.recordId, },state: { nooverride: '1', defaultFieldValues:defaultFieldValues } }); }).catch(error => { console.log('error>> ' + JSON.stringify(error)); }); //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆 end } else { const evt = new ShowToastEvent({ title: 'Warning', message: '状态为取消的QIS才可以被复制并新建', variant: 'warning', mode: 'dismissable' }); this.dispatchEvent(evt); } this.dispatchEvent(new CloseActionScreenEvent()); }) } navigate(pageurl) { window.open(pageurl, '_self'); // this[NavigationMixin.GenerateUrl]({ // type: 'standard__webPage', // attributes: { // url: pageurl // } // }).then(generatedUrl => { // console.log('generatedUrl = ' + generatedUrl); // // setTimeout(() => { // // window.open(generatedUrl, '_self'); // // }, 0); // }); } }