import { api, wire,LightningElement } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import init from '@salesforce/apex/OpportunityLightingButtonController.initForRequestDBButton';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
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';
|
export default class LexRequestDB extends NavigationMixin(LightningElement) {
|
@api recordId;
|
stageName;
|
sapSendOK;
|
cntLostCancelReport;
|
cntLostCancelDraft;
|
agency1;
|
agency1Id;
|
name;
|
bidPlannedDate;
|
salesAssistantName;
|
salesAssistantID;
|
profileId;
|
systemProfileId;
|
s1ProfileId;
|
s4ProfileId;
|
recordTypeId;
|
@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=>{
|
console.log(result);
|
this.stageName = result.stageName == undefined ? '' : result.stageName;
|
this.sapSendOK = result.sapSendOK == undefined ? '' : result.sapSendOK;
|
this.cntLostCancelReport = result.cntLostCancelReport == undefined ? '' : result.cntLostCancelReport;
|
this.cntLostCancelDraft = result.cntLostCancelDraft == undefined ? '' : result.cntLostCancelDraft;
|
this.agency1 = result.agency1 == undefined ? '' : result.agency1;
|
this.agency1Id = result.agency1Id == undefined ? '' : result.agency1Id;
|
this.name = result.name == undefined ? '' : result.name;
|
this.bidPlannedDate = result.bidPlannedDate == undefined ? '' : result.bidPlannedDate.replace(/-/g, '/');;
|
this.salesAssistantName = result.salesAssistantName == undefined ? '' : result.salesAssistantName;
|
this.salesAssistantID = result.salesAssistantID == undefined ? '' : result.salesAssistantID;
|
this.profileId = result.profileId == undefined ? '' : result.profileId;
|
this.systemProfileId = result.systemProfileId == undefined ? '' : result.systemProfileId;
|
this.s1ProfileId = result.s1ProfileId == undefined ? '' : result.s1ProfileId;
|
this.s4ProfileId = result.s4ProfileId == undefined ? '' : result.s4ProfileId;
|
this.recordTypeId = result.recordTypeId == undefined ? '' : result.recordTypeId;
|
this.requestDB();
|
})
|
}
|
requestDB(){
|
var profileId = this.profileId;
|
if (profileId != this.systemProfileId && profileId != this.s1ProfileId &&
|
profileId != this.s4ProfileId) {
|
this.showToast("您没有授权委托的权限。请联系系统管理员。","error");
|
}
|
// jsの場合、翻訳された値がでるので、要注意
|
else if (this.stageName != '引合'
|
&& this.stageName != '询价'
|
) {
|
this.showToast("状态1:" + this.stageName + "、不能做授权申请!","error");
|
}
|
else if (this.sapSendOK == '1') {
|
this.showToast("已经上传SAP、不能做授权申请了!","error");
|
}
|
else if (this.cntLostCancelReport - this.cntLostCancelDraft > 0) {
|
this.showToast("询价已经有取消/失单报告了!","error");
|
}
|
else {
|
// location.href = '/a2C/e?retURL=%2F' +
|
// encodeURI(this.recordId) +
|
// '&RecordType=01210000000RNXi' +
|
// '&CF00N10000006QdJz=' +
|
// encodeURI(this.agency1) +
|
// '&CF00N10000006QdJz_lkid=' +
|
// encodeURI(this.agency1Id) +
|
// '&CF00N10000006QdKn=' +
|
// encodeURI(this.name) +
|
// '&CF00N10000006QdKn_lkid=' +
|
// encodeURI(this.recordId) +
|
// '&00N10000006QdK4=' +
|
// encodeURI(this.name) +
|
// '&00N10000006QdYB=' +
|
// encodeURI(this.bidPlannedDate) +
|
// '&CF00N10000006QdZT=' +
|
// encodeURI(this.salesAssistantName) +
|
// '&CF00N10000006QdZT_lkid=' +
|
// encodeURI(this.salesAssistantID) +
|
// '';
|
const defaultValues = encodeDefaultFieldValues({
|
Bid_distributor__c: this.agency1Id,
|
Prospect_name__c: this.recordId,
|
Product_discription__c: this.name,
|
Tedner_date__c: this.bidPlannedDate,
|
Request_target__c: this.salesAssistantID
|
});
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'Request_tedner_doc__c',
|
actionName: 'new'
|
},
|
state: {
|
nooverride: '1',
|
defaultFieldValues: defaultValues,
|
RecordTypeId: this.recordTypeId,
|
}
|
});
|
}
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
showToast(msg,type) {
|
if(type == 'success'){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
});
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode: 'sticky'
|
});
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|
updateRecordView(recordId) {
|
updateRecord({fields: { Id: recordId }});
|
}
|
}
|