import { LightningElement ,api, wire, track} from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; //备品智能化 2023-11-15 Add by dzk Start 同步报价产品方法引用 import initGetQuoteProLine from '@salesforce/apex/LexOPDPlanProdController.initGetQuoteProLine'; import createQuotePREData from '@salesforce/apex/LexOPDPlanProdController.createQuotePREData'; //备品智能化 2023-11-15 Add by dzk End import init from '@salesforce/apex/LexOPDPlanProdController.initOriginal'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; //备品智能化 2023-11-20 Add by dzk Start 同步报价产品时,状态验证 const event = new ShowToastEvent({ message: "只有草案中才可以进行同步报价产品。", variant : "error" }); //备品智能化 同步报价产品页面,按钮验证 const event1 = new ShowToastEvent({ message: "请至少选择一个报价产品,进行同步。", variant : "error" }); //备品智能化 同步报价产品时,验证是否有询价 const event2 = new ShowToastEvent({ message: "无询价的OPD计划无需同步报价产品。", variant : "error" }); //备品智能化 2023-11-20 Add by dzk End export default class lexSynchronousQuoteProduct extends LightningElement { @api recordId; OPDPlan; //备品智能化 2023-11-20 Add by dzk Start 报价产品页面显示 @track data; @track selectCreateProductLine = []; @track showquotefalg = false; @track columns = [{ label: '产品名称', fieldName: 'Name', type: 'text', cellAttributes: { alignment: 'left' }, hideDefaultActions: true, }, { label: '报价编码', fieldName: 'QuoteNo', type: 'text', cellAttributes: { alignment: 'left' }, hideDefaultActions: true, }, { label: '产品代码', fieldName: 'ProductCode', type: 'text', cellAttributes: { alignment: 'left' }, hideDefaultActions: true, }, { label: '产品型号', fieldName: 'ProductModel', type: 'text', cellAttributes: { alignment: 'left' }, hideDefaultActions: true, }, ]; //备品智能化 2023-11-20 Add by dzk End @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(res=>{ if (res!=null) { console.log(res); this.OPDPlan=res; this.SynchronousQuoteProduct().then(res=>{ }); } else{ const eventInItError = new dispatchEvent({ message : '页面初始化错误,请联系管理员', variant : 'error' }); this.dispatchEvent(eventInItError); return; } }); } //备品智能化 2023-11-20 Add by dzk Start 显示OPD——询价——报价——报价行项目数据 @wire(initGetQuoteProLine, { recordId: '$recordId' }) wiredQuoteItems({error,data}) { if (data) { this.data = data; } else if (error) { console.log('页面初始化错误------' + JSON.stringify(error)); } } // 取消关闭按钮 CancelProduct(){ this.showquotefalg = false; this.dispatchEvent(new CloseActionScreenEvent()); } // 计划备品复选框勾选 handleRowData(event) { const selectedRows = event.detail.selectedRows; this.selectCreateProductLine = selectedRows; console.log('选中的数据---------' + JSON.stringify(selectedRows)); } // 保存按钮 SynchronousProducts(){ if(this.selectCreateProductLine.length == 0){ this.dispatchEvent(event1); return; } createQuotePREData({ records: JSON.stringify(this.selectCreateProductLine),recordId:this.recordId }).then(result => { console.error('处理结果:', result); // 处理 Apex 方法的返回结果 }).catch(error => { // 处理错误 console.error('发生错误:', error); }); this.showquotefalg = false; this.dispatchEvent(new CloseActionScreenEvent()); setTimeout(function () { //1秒后执行刷新 window.location.reload(); }, 1000); } //备品智能化 2023-11-20 Add by dzk End async SynchronousQuoteProduct(){ var opdstagename = this.OPDPlan.Status__c; var oppId = this.OPDPlan.Related_Opportunity1_ID__c; if(opdstagename !== '草案中' ){ this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); this.showquotefalg = false; return; } if(oppId === '' || oppId === null || oppId === undefined){ this.dispatchEvent(event2); this.dispatchEvent(new CloseActionScreenEvent()); this.showquotefalg = false; return; } this.showquotefalg = true; } }