liwentao
2023-08-07 6dde84354d1679817df4b38cada7aa32dad1db5e
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
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'; 
//SI项目需求表 终止SI需求表
export default class lexSIAbortBtn extends NavigationMixin(LightningElement) {
    @api recordId;
    
    @api rentalApplyIds;
    IsLoading=true;
    //提示信息
    msg;
    hasError;
    rentalApplyIds;
    decideFLG;
    connectedCallback(){
        init({recordId:this.recordId}).then(res=>{
            console.log(1);
            console.log(res);
            this.decideFLG=res;
            this.main().then(res=>{
                this.IsLoading=false;
                
                if(this.msg==""){
                    this.dispatchEvent(new CloseActionScreenEvent());
                    this.closeAction();
                }
                
            })
        })
    }
 
    async main(){
        // let rentalApplyIds = {!GETRECORDIDS($ObjectType.IS_Opportunity_Demand__c)};
        // //alert(rentalApplyIds );
        // let decideFLG ='{!Opportunity.Estimation_Decision__c}';
        let hasError ='0';
        let decideFLG=this.decideFLG;
        let str;
        if(decideFLG ==true){
            // alert('报价已决定,不能终止');
            this.msg="报价已决定,不能终止";
            hasError ='1';
        }else{
            // str=prompt("请输入终止理由"," ");
            await LightningPrompt.open({
                message: '请输入终止理由',
                //theme defaults to "default"
                label: '', // this is the header text
                defaultValue: '', //this is optional
            }).then((result) => {
                str=result;
            });
        }
        if (this.rentalApplyIds.length == 0) {
            // alert("请选择一个需求表。");
            this.msg="请选择一个需求表。";
            hasError = '1';
        } else if (this.rentalApplyIds.length > 1) {
            // alert("只能选择一个需求表。");
            this.msg="只能选择一个需求表。";
            hasError = '1';
        }
        console.log("ttt1");
        let ids= '';
        if (hasError == '0') {
            ids+= this.rentalApplyIds[0];
            let id = this.rentalApplyIds[0];
            try{
                console.log("ttt1.1");
                let rtn='Fin';
                await setAbortSI({isoID:ids,AbortReason:str}).then(res=>{
                    rtn=res;
                });
                console.log(rtn);
                console.log("ttt1.2");
                if(rtn!='Fin'){
                    // alert(rtn);
                    this.msg=rtn;
                    console.log("ttt2");
                }else{
                    this.msg='';
                    // window.top.location.reload();
                    console.log("ttt3");
                }
            }catch(e){
                // alert(e);
                console.log(e.message);
                this.msg=e;
                console.log("ttt4");
            }
        }
    }
    closeAction() {
        //返回当前的备品申请
        window.open("/"+this.recordId,'_self');
    }
}