binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import init from '@salesforce/apex/LexStockCancelController.init';
import updateOppotunity from '@salesforce/apex/LexStockCancelController.updateOppotunity';
import submitApprovalRequest from '@salesforce/apex/LexStockCancelController.submitApprovalRequest';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexStockCancel extends LightningElement {
    @api recordId;
    IsLoading=true;
    data;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                console.log('str');
                console.log(str);
                this.recordId=str;
            }
        }
    }
 
 
 
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        const inputAlignright = document.createElement( 'style' );
        inputAlignright .innerText =  '.slds-scope .slds-theme_error,.slds-scope .slds-theme--error {'+
                                        'color: var(--slds-g-color-neutral-base-100, var(--lwc-colorTextInverse,rgb(255, 255, 255)));'+
                                        'background-color: rgb(186,5,23);} ';
        document.body.appendChild(inputAlignright);
        console.log(this.recordId);
        init({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                this.data=result;
                this.cancelSubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });    
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err.message);
        }).finally(()=>{
 
        });
    }
 
 
 
    async cancelSubmit(){
        let reason = this.data.Stock_cancel_reason__c;
        if (reason == null || reason == '') {
            const event = new ShowToastEvent({
                title: '',
                message:'必须填写撤销备货理由。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
 
        // CHAN-BCS8T5 LHJ 20190604 Start
        let stage = this.data.Whether_Upload_Question_Document__c;
        if (stage == '0') {
            const event = new ShowToastEvent({
                title: "",
                message:'请上传质疑函。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
        // CHAN-BCS8T5 LHJ 20190604 End
        const resul = await LightningConfirm.open({
            message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
            variant: '',
            label: '',
            // setting theme would have no effect
        });
        if (resul==false) {
            return;
        }
        let flag=true;
        await updateOppotunity({recordId:this.recordId,stStatus:"撤销填写完毕"}).then(res=>{
            console.log(res);
            if(res!=null&&res.success==false){
                let messages ="";
                flag=false;
                messages=res.errors[0];
                const event = new ShowToastEvent({
                    title: '',
                    message:""+messages,
                    variant: 'error',
                    mode: 'sticky'
                });
                this.dispatchEvent(event);
                return;
            }
        })
        if(flag==false)return;
 
        // let rac = new sforce.SObject("Opportunity");
        // rac.Id = "{!Opportunity.Id}";
        // rac.Stock_apply_status__c = "撤销填写完毕";
        // let result = sforce.connection.update([rac]);
        // let messages = getConnectDMLErrorMessages(result);
        // if (messages.length > 0) {
        //     alert(messages.join("\n"));
        //     return;
        // }
        let ress;
          await submitApprovalRequest({recordId:this.recordId}).then(res=>{
              console.log(res);
              ress=res;
          })
          console.log("777");
        if (ress != null) {
            // let back = new window.sforce.SObject("Opportunity");
            // back.Id = "{!Opportunity.Id}";
            // back.Stock_apply_status__c = "批准";
            // let backResult = sforce.connection.update([back]);
            // backMessages = getConnectDMLErrorMessages(backResult);
            // if (backMessages.length > 0) {
            //     showTost("提示信息",backMessages.join("\n"));
            //     return;
            // }
 
            // let errmsg = processResults[0].errors.message.toString();
            // showTost("提示信息",errmsg);
 
            await updateOppotunity({recordId:this.recordId,stStatus: "批准"}).then(res=>{
                console.log(res);
                if(res!=null&&res.success==false){
                    let messages ="";
                    flag=false;
                    messages=res.errors[0];
                    const event = new ShowToastEvent({
                        title: '',
                        message:""+messages,
                        variant: 'error',
                        mode: 'sticky'
                    });        
                    this.dispatchEvent(event);
                    return;
                }
            });
            if(flag==false)return;
            const event = new ShowToastEvent({
                title: '',
                message:ress,
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
        // window.location.reload();
    };
 
 
    showTost(title,message){
        
    }
 
                    
}