buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
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
import { LightningElement, api, track, wire } from 'lwc';
import init from '@salesforce/apex/lexCustomDeleteController.initForCustomDelete';
import {CurrentPageReference} from 'lightning/navigation'
import UserInfo_Owner from '@salesforce/apex/TaskFeedbackController.UserInfo_Owner';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import deleteRepair from '@salesforce/apex/ControllerUtil.deleteRepair';
 
export default class lexCustomDeleteLWC extends LightningElement {
 
 
    @api recordId;
    @api message;
 
    @track Status ;
    @track FSE ;
    @track SAP;
    @track cre ;
    @track Rep ;
    @track acc ;
    @track fSE ;
    @track id;
    @track rtn;
 
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log(111);
        console.log(currentPageReference);
        if(currentPageReference){
            const urlValue=currentPageReference.state.recordId;
            if(urlValue){
                let str='${urlValue}';
                console.log("str");
                console.log(str);
                this.recordId=str;
            }
        }
    }
    connectedCallback(){
        console.log(this.recordId);
        init({
            recordId:this.recordId
        }).then(result=>{
            console.log(result);
            if(result!=null){
                this.FSE=result.FSEApplyForRepairtime;
                this.Rep=result.Rep;
                this.SAP=result.SAP;
                this.Status=result.Status;
                this.acc=result.acc;
                this.id=result.Id;
                this.cre=result.cre;
                this.fSE=result.FSEownerId;
                console.log("end");
                this.handleDeleteAction();
                console.log("end2");
 
            }
        })
    }
   
    handleDeleteAction(){
    if (this.Status != null && this.Status.length > 0) {
        if (this.Status != "草案中"&& this.Status != "1.受理完毕(SAP待发送)"&& this.Status != "4.修理品返送阶段") {
            this.message = "不是草案中,不能删除";
            const event = new ShowToastEvent({
                title: 'error',
                variant:'error',
                message: 
                    this.message,
            });
            this.dispatchEvent(event);
        }
        else if (this.Status == "0.申请完毕"&& (this.FSE != "")) {
            message = "FSE已经申请,不能删除";
        console.log('***action4');
 
            const event = new ShowToastEvent({
                title: 'warning',
                message:
                    this.message,
            });
            this.dispatchEvent(event);
        }
        else if (this.Status == "4.修理品返送阶段"&& (this.SAP != "" || this.Rep!= "")){
            message = "已经发送过SAP,不能删除";
            const event = new ShowToastEvent({
                title: 'warning',
                message:
                    this.message,
            });
            this.dispatchEvent(event);
        }
        else if (UserInfo_Owner.Id.substring(0,15) != this.cre.substring(0,15) && UserInfo_Owner.Id.substring(0,15) != this.acc.substring(0,15)&& UserInfo_Owner.Id.substring(0,15) != this.fSE.substring(0,15)) {
            message = "不是所有人、创建人或FSE主负责人,不能删除";
            const event = new ShowToastEvent({
                title: 'warning',
                message:
                    this.message,
            });
            this.dispatchEvent(event);
        }
        else {
            
            // sforce.connection.sessionId = '{!$Api.Session_ID}';
            // var rtn=sforce.apex.execute("ControllerUtil","deleteRepair",{rid:this.id});
            deleteRepair({
                rid:this.id
            }).then(result=>{
                console.log(result);
                if(result!=null){
                    this.rtn=result;
                }
            })
 
            if (this.rtn == "OK") {
                 reload();
            } else {
                alert(this.rtn);
 
            }
        }
     }
 
    function reload(){
        var str="";
        if(getParam('retURL')!==null){
            str +=getParam('retURL');
        }
        window.open(str,'_self');
    }
 
    function getParam(paramName) {
        paramValue = "", isFound = !1;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
            arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
            while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
        }
    return paramValue == "" && (paramValue = null), paramValue
}
 
}
 
}