liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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());
        }
    }
}