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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CloseActionScreenEvent } from 'lightning/actions';
import LightningConfirm from 'lightning/confirm';
 
import init  from '@salesforce/apex/SubmitAndRefreshController.init';
import submitApproval from '@salesforce/apex/HosipitalToDeptController.submitApproval';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import {loadStyle} from 'lightning/platformResourceLoader'    
export default class LexSampleInventory extends LightningElement {
    @api recordId;
    IsLoading=true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(this.recordId);
        console.log(currentPageReference);
        console.log('1111111111');
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                this.recordId=str;
            }
        }
        console.log(this.recordId);
    }
 
    connectedCallback(){
        Promise.all([            
            loadStyle(this, lwcCSS)            
        ]);    
        init({recordId:this.recordId}).then(result=>{
            this.IsLoading = false
            console.log('init result==========',result);
            if(result!=null){
                // WYL DB202311402675【客户】客户页面增加备品送货地址栏 start
                if (result.isuploadfile == '0' && result.ChangeReason != '备品送货地址维护' || !result.isuploadfile && result.ChangeReason !='备品送货地址维护') {
                    this.showToast('请上传客户变更申请信息附件','error');
                    return;
                }
                // WYL DB202311402675【客户】客户页面增加备品送货地址栏 end
                var accname=result.hospitalName.substr(-2,2);
                console.log(accname)
                if((accname =='公司' || accname =='集团') && result.attributeType !='企业集团'){
                    // this.showToast('客户为公司或集团,医院性质不是企业集团,请核实医院性质,确认是否提交?','error');
                    LightningConfirm.open({
                        message: "客户为公司或集团,医院性质不是企业集团,请核实医院性质,确认是否提交?",
                        variant: 'headerless',
                        label: '提示信息',
                        // setting theme would have no effect
                    }).then(res => {
                        if(!res){
                            this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                        }else{
                            LightningConfirm.open({
                                message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                                variant: 'headerless',
                                label: '提示信息',
                                // setting theme would have no effect
                            }).then(res => {
                                if(!res){
                                    this.dispatchEvent(new CloseActionScreenEvent());
                                    return;
                                }else{
                                    this.submit()
                                }
                            })
                        }
                    })
                }else{
                    LightningConfirm.open({
                        message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                        variant: 'headerless',
                        label: '提示信息',
                        // setting theme would have no effect
                    }).then(res => {
                        if(!res){
                            this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                        }else{
                            this.submit()
                        }
                    })
                }
                
                // if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
                //     return;
                // }
                // submitApproval({recordId:this.recordId}).then(res => {
                //     this.IsLoading = false
                //     console.log(res,'<======res')
                //     this.showToast(res,'success')
                // }).catch(err => {
                //     this.IsLoading = false
                //     console.log(err,'<======err')
                //     this.showToast(err,'error')
                // })
            }
        });
        // console.log('connectedCallback');
        // submitApproval({recordId:this.recordId}).then(rep => {
        //     console.log(rep);
        //     if(rep==='OK'){
        //         console.log('1');
        //         this.showToast('提交审批成功','success');
        //     }else{
        //         console.log('2');
        //         this.showToast(rep,'error');
        //     }
        // }).catch(err => {
        //     console.log('3');
        //     console.log(err);
        //     this.showToast(err,'error');
        // })
    }
    submit(){
        submitApproval({recordId:this.recordId}).then(res => {
            // this.IsLoading = false
            //chenjingwu 20231225 start
            if(res.includes('未找到适用批准流程')){
                this.showToast('未找到适用批准流程。','error');
                return;
            }
            console.log(res,'<======res')
            this.showToast('提交审批成功','success')
            //chenjingwu 20231225 end
        }).catch(err => {
            // this.IsLoading = false
            console.log(err,'<======err')
            this.showToast(err,'error')
        })
    }
    showToast(msg, type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
            window.location.href = '/lightning/r/Account_Delay_Apply__c/'+this.recordId+'/view';
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode:'Sticky'
            });
            this.dispatchEvent(event);
        }
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}