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 init from '@salesforce/apex/LexNewSICustomNewController.init';
|
import getISOPList from '@salesforce/apex/LexNewSICustomNewController.getISOPList';
|
import getProfileName from '@salesforce/apex/LexNewSICustomNewController.getProfileName';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
|
export default class lexSICustomNew extends NavigationMixin(LightningElement) {
|
@api recordId;
|
IsLoading=true;
|
//提示信息
|
msg;
|
hasError;
|
records;
|
recordTypeId;
|
SIID;
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
async connectedCallback(){
|
console.log(this.recordId);
|
await init({recordId:this.recordId}).then(res=>{
|
console.log(1);
|
console.log(res);
|
this.recordTypeId=res.id.substring(0,15);
|
this.SIID=res.typeId.substring(0,15);
|
this.main().then(res=>{
|
this.dispatchEvent(new CloseActionScreenEvent());
|
})
|
})
|
|
}
|
|
async main(){
|
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
console.log("in main");
|
var records = new Array();
|
let name=await getProfileName();
|
console.log(name);
|
if(name.length<2){
|
name=name.substr(0,name.length);
|
}else{
|
name=name.substr(0,2);
|
}
|
|
if(this.recordTypeId==this.SIID){
|
records = await getISOPList({recordId:this.recordId});
|
}
|
var RecordTypeid = this.recordTypeId;
|
|
|
|
|
|
if(RecordTypeid==this.SIID&&records.length==0){
|
window.location.href="/apex/ISO_DemandOperAndDemonsNew?OppoerID="+this.recordId;
|
}else if(name !='2S'){
|
// 添加新建需求表的限制
|
this.showToast("非营业部人员不能创建需求表",'error');
|
}else if(RecordTypeid!=this.SIID){
|
this.showToast("非SI询价,不能新建SI需求表",'error');
|
}else if(RecordTypeid==this.SIID&&records.length!=0){
|
this.showToast("存在已有的SI需求表,不能新建SI需求表",'error');
|
}
|
|
// if(RecordTypeid=='012100000006KMe'&&records.length==0){
|
// var url = "apex/ISO_DemandOperAndDemonsNew?OppoerID={!URLENCODE(Opportunity.Id)}";
|
// window.top.location.href=url;
|
// }else if('{!LEFT( $Profile.Name , 2)}' !='2S'){
|
// // 添加新建需求表的限制
|
// alert("非营业部人员不能创建需求表");
|
// }else if('{!Opportunity.RecordTypeId}'!='012100000006KMe'){
|
// alert("非SI询价,不能新建SI需求表");
|
// } else if(RecordTypeid=='012100000006KMe'&&records.length!=0){
|
// alert("存在已有的SI需求表,不能新建SI需求表");
|
// }
|
}
|
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: 'error',
|
// duration: 30000
|
mode: 'sticky'
|
});
|
this.IsReload=false;
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|
}
|