import { LightningElement,api, track, wire } from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import LightningConfirm from 'lightning/confirm'; import init from '@salesforce/apex/LexStockCancelController.init'; import updateOppotunity from '@salesforce/apex/LexStockCancelController.updateOppotunity'; import submitApprovalRequest from '@salesforce/apex/LexStockCancelController.submitApprovalRequest'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class lexStockCancel extends LightningElement { @api recordId; IsLoading=true; data; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log("进入页面"); console.log(currentPageReference); if(currentPageReference){ const urvalue=currentPageReference.state.recordId; if(urvalue){ let str=`${urvalue}`; console.log('str'); console.log(str); this.recordId=str; } } } connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); const inputAlignright = document.createElement( 'style' ); inputAlignright .innerText = '.slds-scope .slds-theme_error,.slds-scope .slds-theme--error {'+ 'color: var(--slds-g-color-neutral-base-100, var(--lwc-colorTextInverse,rgb(255, 255, 255)));'+ 'background-color: rgb(186,5,23);} '; document.body.appendChild(inputAlignright); console.log(this.recordId); init({recordId:this.recordId}).then(result=>{ console.log(result); if(result!=null){ this.data=result; this.cancelSubmit().then(res=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } }).catch(err=>{ console.log("error:"); console.log(err.message); }).finally(()=>{ }); } async cancelSubmit(){ let reason = this.data.Stock_cancel_reason__c; if (reason == null || reason == '') { const event = new ShowToastEvent({ title: '', message:'必须填写撤销备货理由。', variant: 'error', mode: 'sticky' }); this.dispatchEvent(event); return; } // CHAN-BCS8T5 LHJ 20190604 Start let stage = this.data.Whether_Upload_Question_Document__c; if (stage == '0') { const event = new ShowToastEvent({ title: "", message:'请上传质疑函。', variant: 'error', mode: 'sticky' }); this.dispatchEvent(event); return; } // CHAN-BCS8T5 LHJ 20190604 End const resul = await LightningConfirm.open({ message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?", variant: '', label: '', // setting theme would have no effect }); if (resul==false) { return; } let flag=true; await updateOppotunity({recordId:this.recordId,stStatus:"撤销填写完毕"}).then(res=>{ console.log(res); if(res!=null&&res.success==false){ let messages =""; flag=false; messages=res.errors[0]; const event = new ShowToastEvent({ title: '', message:""+messages, variant: 'error', mode: 'sticky' }); this.dispatchEvent(event); return; } }) if(flag==false)return; // let rac = new sforce.SObject("Opportunity"); // rac.Id = "{!Opportunity.Id}"; // rac.Stock_apply_status__c = "撤销填写完毕"; // let result = sforce.connection.update([rac]); // let messages = getConnectDMLErrorMessages(result); // if (messages.length > 0) { // alert(messages.join("\n")); // return; // } let ress; debugger await submitApprovalRequest({recordId:this.recordId}).then(res=>{ console.log(res); ress=res; }) console.log("777"); if (ress != null) { // let back = new window.sforce.SObject("Opportunity"); // back.Id = "{!Opportunity.Id}"; // back.Stock_apply_status__c = "批准"; // let backResult = sforce.connection.update([back]); // backMessages = getConnectDMLErrorMessages(backResult); // if (backMessages.length > 0) { // showTost("提示信息",backMessages.join("\n")); // return; // } // let errmsg = processResults[0].errors.message.toString(); // showTost("提示信息",errmsg); await updateOppotunity({recordId:this.recordId,stStatus: "批准"}).then(res=>{ console.log(res); if(res!=null&&res.success==false){ let messages =""; flag=false; messages=res.errors[0]; const event = new ShowToastEvent({ title: '', message:""+messages, variant: 'error', mode: 'sticky' }); this.dispatchEvent(event); return; } }); if(flag==false)return; const event = new ShowToastEvent({ title: '', message:ress, variant: 'error', mode: 'sticky' }); this.dispatchEvent(event); } // window.location.reload(); //fy 240125修改 start window.location.href = '/' + this.recordId; //fy 240125修改 start }; showTost(title,message){ } }