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
import { LightningElement,wire,track,api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForLexQuoteEntryNewbotton';
import describeSObjectCommon  from '@salesforce/apex/OpportunityLightingButtonController.describeSObjectCommon';
import setQuote  from '@salesforce/apex/ControllerUtil.setQuote';
import getStatusForISO  from '@salesforce/apex/ControllerUtil.getStatusForISO';
import Error_Message9 from '@salesforce/label/c.Error_Message9';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader'
import SIopprecordTypeId from '@salesforce/label/c.SIopprecordTypeId';
 
 
export default class LexQuoteEntryNewbottonLwc extends NavigationMixin(LightningElement) {
    @api recordId;
    agencyIsDeletec;
    accountIsActivec;
    hospitalIsActivec;
    estimationDecisionc;
    recordTypeId;
    IsLoading = true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(currentPageReference);
 
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.warn("str");
            console.warn(str);
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
        console.warn('recordId'+this.recordId);
        init({
            recordId: this.recordId
        }).then(result=>{
            this.agencyIsDeletec = result.agencyIsDeletec;
            this.accountIsActivec = result.accountIsActivec;
            this.hospitalIsActivec = result.hospitalIsActivec;
            this.estimationDecisionc = result.estimationDecisionc;
            if(result.recordTypeId){
                this.recordTypeId = result.recordTypeId.substring(0,15);
            }
            console.warn('111');
            this.loseReport();
            console.warn('222');
        })
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
    }
    loseReport(){
        debugger
        var oppid = this.recordId ;
        describeSObjectCommon({objname:"Quote"}).then(result=>{
            getStatusForISO({opporID:oppid}).then(excuteRs=>{
                debugger
                if (!result) {
                    this.showToast("没有新建报价的权限。","error");
                    // alert('没有新建报价的权限。');
                } else if (this.agencyIsDeletec == "√") {
                    // alert('经销商处于无效状态,不能新建报价。');
                    this.showToast("经销商处于无效状态,不能新建报价。","error");
                } else if (this.accountIsActivec == "無効") {
                    // alert('科室处于无效状态,不能新建报价。');
                    this.showToast("科室处于无效状态,不能新建报价。","error");
                } else if (this.hospitalIsActivec == "無効") {
                    // alert('医院处于无效状态,不能新建报价。');
                    this.showToast("医院处于无效状态,不能新建报价。","error");
                } 
                else if ((excuteRs !='CommitCode')&&this.recordTypeId ==SIopprecordTypeId) {
                    // alert('没有批准的需求表,不能报价。');
                    this.showToast("没有批准的需求表,不能报价。","error");
                } else  {
                    if (!this.estimationDecisionc){
                        if(this.recordTypeId ==SIopprecordTypeId){
                            setQuote({oppid:oppid}).then(ite=>{
                                window.open('/lightning/n/lexSINewQuoteEntry#oppid='+oppid,"_self");
                            });
                        }else{
                            window.open('/lightning/n/lexNewQuoteEntry#oppid='+oppid,"_self");
                        }
                    } else  {
                        // alert(Error_Message9);
                        this.showToast(Error_Message9,"error");
                    }
                }
                this.IsLoading = false;
            })
        });
        
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            message: msg,
            variant : type,
            mode : 'sticky'
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}