import { LightningElement,api, track, wire } from 'lwc';
|
import {CurrentPageReference} from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
const event1 = new ShowToastEvent({
|
message:
|
"询价状态为:失单、取消、注残、发货、完毕、目标,不允许创建OPD计划",
|
variant : "error" ,
|
mode : 'sticky'
|
});
|
//备品智能化 2023-11-05 Add by dzk Start无报价时,新建OPD计划验证
|
const event2 = new ShowToastEvent({
|
message:
|
"询价未创建报价,不允许创建OPD计划",
|
variant : "error"
|
});
|
//备品智能化 2023-11-05 Add by dzk End
|
//备品智能化 2023-11-05 Add by dzk 产品查询页面验证
|
const event3 = new ShowToastEvent({
|
message:
|
"请至少选择一个报价产品,进行OPD计划创建。",
|
variant : "error"
|
});
|
//备品智能化 2023-11-05 Add by dzk End
|
import init from '@salesforce/apex/LexNewOPDButtonOpportunityController.initNewOPDButton2';
|
//备品智能化 2023-11-05 Add by dzk 产品页面初始化、保存产品方法引用
|
import initGetQuote from '@salesforce/apex/LexNewOPDButtonOpportunityController.initGetQuote';
|
import createProductTags from '@salesforce/apex/LexNewOPDButtonOpportunityController.createProductTags';
|
//备品智能化 2023-11-05 Add by dzk End
|
export default class lexNewOPDButtonOpportunity extends NavigationMixin(LightningElement) {
|
@api recordId;
|
IsLoading=true;
|
@track showproductfalg = false;
|
@api Opportunity;//当前询价
|
QuoteNum;//询价中报价的数量
|
//备品智能化 2023-11-05 Add by dzk Start 产品显示页面数据显示
|
@track data;
|
@track selectProductLine = [];
|
@track columns = [{
|
label: '商品名称',
|
fieldName: 'ProductName',
|
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-05 Add by dzk End
|
|
//备品智能化 2023-11-05 Add by dzk Start 页面选中数据方法
|
handleRowSelection(event) {
|
const selectedRows = event.detail.selectedRows;
|
this.selectProductLine = selectedRows;
|
// 在这里处理选中的行数据
|
console.log('选中的行数据:'+ JSON.stringify(selectedRows));
|
}
|
//备品智能化 2023-11-05 Add by dzk End
|
|
//备品智能化 2023-11-05 Add by dzk Start 产品页面数据初始化显示
|
@wire(initGetQuote, { recordId: '$recordId' })
|
wiredQuoteItems({error,data}) {
|
if (data) {
|
this.data = data;
|
} else if (error) {
|
console.log('页面初始化错误------' + JSON.stringify(error));
|
}
|
}
|
//备品智能化 2023-11-05 Add by dzk End
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
init({recordId:this.recordId}).then(res=>{
|
if (res!=null) {
|
console.log(res);
|
//备品智能化 2023-11-05 Add by dzk Start 修改初始化方法接受收参数
|
this.Opportunity=res.opp;
|
this.QuoteNum=res.quoteNum;
|
console.log('this.Opportunity>>>>>' + this.Opportunity);
|
console.log('this.QuoteNum>>>>>' + this.QuoteNum);
|
//备品智能化 2023-11-05 Add by dzk End
|
this.newOPDButtonOpportunity().then(res=>{
|
this.IsLoading=false;
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
else{
|
const eventInItError = new dispatchEvent({
|
message : '页面初始化错误,请联系管理员',
|
variant : 'error' ,
|
mode : 'sticky'
|
});
|
this.dispatchEvent(eventInItError);
|
return;
|
}
|
|
});
|
}
|
|
|
async newOPDButtonOpportunity(){
|
//备品智能化 2023-11-05 Start by dzk Start 按钮点击验证追加无报价验证
|
var oppstagename = this.Opportunity.StageName;
|
var quotenumber = this.QuoteNum;
|
if(oppstagename=='目標' || oppstagename=='完了' || oppstagename=='敗戦' || oppstagename=='削除' || oppstagename=='注残' || oppstagename=='出荷'){
|
this.dispatchEvent(event1);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}else if(quotenumber == 0){
|
this.dispatchEvent(event2);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}else{
|
this.showproductfalg = true;
|
}
|
//备品智能化 2023-11-05 Add by dzk End
|
}
|
|
//备品智能化 2023-11-05 Add by dzk Start OPD计划新建标准页面与保存按钮合并
|
NewQuotationProducts(event){
|
this.showproductfalg = false;
|
if(this.selectProductLine.length == 0){
|
this.dispatchEvent(event3);
|
this.showproductfalg = true;
|
}else{
|
createProductTags({ records: JSON.stringify(this.selectProductLine), recordId:this.recordId }).then(result => {
|
// 处理 Apex 方法的返回结果
|
console.log('Apex 方法返回的结果:', result);
|
}).catch(error => {
|
// 处理错误
|
console.error('发生错误:', error);
|
});
|
//新建OPD计划数据
|
const defaultValues = encodeDefaultFieldValues({
|
Related_Opportunity1_ID__c: this.recordId,
|
Account_Laboratory__c: this.Opportunity.AccountId,
|
Related_Opportunity1__c : this.Opportunity.Name,
|
OPDType__c : '询价',
|
Name : '*',
|
retURL : '%2F' + this.recordId
|
});
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'OPDPlan__c',
|
actionName: 'new'
|
},
|
state: {
|
nooverride: '1',
|
defaultFieldValues: defaultValues,
|
}
|
});
|
}
|
}
|
|
|
openSetProduct(event){
|
this.showproductfalg = false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
//备品智能化 2023-11-05 Add by dzk End
|
}
|