liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
113
114
115
116
117
118
119
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/StartTradingController2.init';
import start  from '@salesforce/apex/StartTradingController2.start';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
export default class LexStartTrading extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading=true;
    Hospital_Name__c;
    Close_Forecasted_Date__c;
    Opp_Name_Search__c;
    begin_opp_name__c;
    Status;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                this.recordId=str;
            }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
        init({Id:this.recordId}).then(result=>{
            console.log('init result==========',result);
            if(result!=null){
                // 给参数赋值
                this.Hospital_Name__c = result.Hospital_Name__c;
                this.Close_Forecasted_Date__c = result.Close_Forecasted_Date__c;
                this.Opp_Name_Search__c = result.Opp_Name_Search__c;
                this.begin_opp_name__c = result.begin_opp_name__c;
                this.Status = result.Status;
                // 执行判断
                this.InquiryJudgment();
            }
        });
        // .catch(err=>{
        //     console.log("init error:");
        //     console.log(err);
        // }).finally(()=>{});
    }
 
    InquiryJudgment(){
        console.log('InquiryJudgment check');
        let status_list = ['完毕','无需求','已有询价','確認済み','不要','开始询价'];
        let lead_status = this.Status;
        let that = this;
        if(this.Hospital_Name__c == ''){
            this.showToast('病院名称を設定してください','error');
        } else if (this.comparDate(this.Close_Forecasted_Date__c)) {
            this.showToast('预测OCSM签约日不能小于今天','error');
        } else if (this.Opp_Name_Search__c == '' || !this.begin_opp_name__c == '' || status_list.indexOf(lead_status) !== -1) {
            this.showToast('已存在转化的询价或不需要转化询价','error');
        } else{
            console.log('start at: ' + this.recordId);
            start({Id:this.recordId}).then(result=>{
                console.log('start result==========',result);
                if(result!=null){
                    this.showToast('已成功转化询价','success');
                    console.log(result);
                    // window.location = '/lightning/r/Opportunity/'+result+'/view';
                    this[NavigationMixin.Navigate]({
                        type: "standard__recordPage",
                        attributes: {
                            recordId: result,
                            actionName:"edit"
                        },
                        state: {
                            nooverride: '1',
                            backgroundContext: '/lightning/r/Opportunity/'+result+'/view'
                        }
                    });
                }
            }).catch(error=>{
                console.log('error');
                console.log(error);
            });
            // .catch(err=>{
            //     console.log("start error:");
            //     console.log(err);
            // }).finally(()=>{});
        }
 
    }
    comparDate(dateValue) {
        return new Date().getTime() >= new Date(dateValue).getTime() + 3600 * 1000 * 24;
    }
 
    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());
        }   
    }
}