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
import { LightningElement, track, wire ,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import changeTrade from'@salesforce/apex/OpdPlanWebService.changeTrade';
import init from'@salesforce/apex/LexOPDSupplementaryController.initCancleSumbit';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import getRecordTypeByNameAndSobject from'@salesforce/apex/LexOPDSupplementaryController.getRecordTypeByNameAndSobject';
const event1 = new ShowToastEvent({
                    message:
                    "OPD计划的状态为取消或完毕时,不能取消!",
                    variant : "error" ,
                    mode :'sticky'
});
export default class lexOPDCancelSubmit extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading=true;
    OPDPlan;
    recordTypeId;
 
 
    @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=>{
            this.OPDPlan=res;
            console.log(this.OPDPlan);
            this.OPDCancelSubmit().then(res=>{
                this.IsLoading=false;
                this.dispatchEvent(new CloseActionScreenEvent());
                
            })
        })
    }
 
    async OPDCancelSubmit(){
        var Status = this.OPDPlan.Status__c;
        if(Status == '取消' || Status == '完毕' ){
            this.dispatchEvent(event1);
            return;
        }
        //判断符合条件得备品借出申请 SWAG-BUF6J5
        var opdplanid = this.OPDPlan.Id;
        var rtn = await changeTrade({opdplanId:opdplanid});
        if (rtn != 'OK') {
            const event2 = new ShowToastEvent({
                message : rtn,
                variant : 'error',
                mode : 'sticky'
            })
            this.dispatchEvent(event2);
            return;
        }
        var recordTypeId = await getRecordTypeByNameAndSobject({Name : '取消',SobjectType : 'CancelPostponePlan__c'});
        const defaultValues = encodeDefaultFieldValues({
            CancelOPDPlan__c: this.OPDPlan.Id,
            Status__c: '取消',
        });
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'CancelPostponePlan__c',
                actionName: 'new'
            },
            state: {
                nooverride: '1',
                defaultFieldValues: defaultValues,
                recordTypeId : recordTypeId
            }
        });    
 
 
    }
 
    
 
 
}