binxie
2024-01-20 e0de9222da210f9c8eb1a9f5400f936a14923e11
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
import { LightningElement,wire,track,api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from "lightning/navigation";
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CloseActionScreenEvent } from 'lightning/actions';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForLexQuoteEntryNewbotton';
import describeSObjectCommon  from '@salesforce/apex/OpportunityLightingButtonController.describeSObjectCommon';
import selectQuoteById  from '@salesforce/apex/LexQuoteSelectbottonController.selectQuoteById';
import Error_Message9 from '@salesforce/label/c.Error_Message9';
import SIopprecordTypeId from '@salesforce/label/c.SIopprecordTypeId';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader'
 
 
export default class LexReQuotebotton 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(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.warn('recordId'+this.recordId);
        this.loseReport();
    }
    loseReport(){
        selectQuoteById({recordId:this.recordId}).then(result=>{
            var oppid = result.OpportunityId;
            init({
                recordId: oppid
            }).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);
                }
                describeSObjectCommon({objname:"Quote"}).then(result=>{
                    debugger
                    if (!result) {
                        this.showToast("没有新建报价的权限。","error");
                    } else if (this.agencyIsDeletec == "√") {
                        this.showToast("经销商处于无效状态,不能新建报价。","error");
                    } else if (this.accountIsActivec == "無効") {
                        this.showToast("科室处于无效状态,不能新建报价。","error");
                    } else if (this.hospitalIsActivec == "無効") {
                        this.showToast("医院处于无效状态,不能新建报价。","error");
                    } else  {
                        if (!this.estimationDecisionc){
                            if(this.recordTypeId ==SIopprecordTypeId){
                                window.open('/lightning/n/lexSINewQuoteEntry#oppid='+oppid+'&copyid=' + this.recordId,"_top");
                            }else{
                                window.open('/lightning/n/lexNewQuoteEntry#oppid='+oppid+'&copyid=' + this.recordId,"_top");
                            }
                        } else  {
                            this.showToast(Error_Message9,"error");
                        }
                    }
                });
            })
        });
        
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type,
            mode : "sticky"
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}