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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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/LexSIAbortBtnController.init';
import setAbortSI from '@salesforce/apex/LexSIAbortBtnController.setAbortSI';
import LightningPrompt from 'lightning/prompt'; 
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
//SI项目需求表 终止SI需求表
export default class lexSIAbortBtnEnd extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading=true;
    //提示信息
    msg;
    hasError;
    rentalApplyIds;
    decideFLG;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({recordId:this.recordId}).then(res=>{
            console.log(1);
            console.log(res);
            this.decideFLG=res;
            this.main().then(res=>{
                this.dispatchEvent(new CloseActionScreenEvent());
            })
        })
    }
 
    async main(){
        let hasError ='0';
        let decideFLG=this.decideFLG;
        let str;
        if(decideFLG ==true){
            this.msg="报价已决定,不能终止";
            hasError ='1';
        }else{
            await LightningPrompt.open({
                message: '请输入终止理由',
                //theme defaults to "default"
                label: '', // this is the header text
                defaultValue: '', //this is optional
            }).then((result) => {
                str=result;
            });
        }
 
        console.log("ttt1");
        let ids= '';
        if (hasError == '0') {
            ids+= this.recordId;
            let id = this.recordId;
            try{
                console.log("ttt1.1");
                let rtn='Fin';
                await setAbortSI({isoID:ids,AbortReason:str}).then(res=>{
                    rtn=res;
                });
                if(rtn!='Fin'){
                    this.showToast(rtn,'error');
                }else{
                    // window.top.location.reload();
                    this.showToast('终止成功','success');
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }
            }catch(e){
                this.showToast(e,'error');
            }
        }
    }
    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());
        }
    }
}