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
/*
 * @Date: 2023-03-28 16:47:34
 * @Author: @zyh
 * @LastEditTime: 2023-04-17 10:33:27
 * @Descripttion: 
 */
import { LightningElement,wire,track,api } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import init from '@salesforce/apex/OPDLwcController.initOPDCancelSubmit';
import RecordType from '@salesforce/apex/OPDLwcController.RecordType';
// import applySelect from '@salesforce/apex/OPDLwcController.applySelect';
import changeTrade from '@salesforce/apex/OpdPlanWebService.changeTrade';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
 
export default class OpdUpdateDate extends NavigationMixin(LightningElement) {
    @api recordId;
    Status;
    Name;
    Id;
    rtnRecordType;
 
    @wire(CurrentPageReference)
    getStateParmeters(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('zheli'+this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            console.log('zheli11'+result);
 
            console.log(result);
            if(result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.Status = result.Status;
                this.Name = result.Name;
                console.log("123");
                console.log(this.Id);
                console.log(this.Status);
                console.log(this.Name);
                this.testupdate();
                this.updateDateSubmit();
                this.dispatchEvent(new CloseActionScreenEvent());
                // this.dispatchEvent(new ShowToastEvent({
                //     title: '1111',
                //     message: 'message',
                //     variant: 'success'
                // }));
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            
        });
    }
    testupdate(){
        var typertn = [];
        RecordType({
            RecordType : '01210000000gQyMAAU'
        }).then(result => {
            console.log(result);
            const defaultValues = encodeDefaultFieldValues({
                RecordTypeId: result,
                Status__c: '延期报告',
                CancelOPDPlan__c: this.Id
            });
            console.log(defaultValues);
            this.rtnRecordType = defaultValues;
            console.log(this.rtnRecordType+'======123131typertn');
            
        });
    }
    updateDateSubmit(){
        var rtn = [];
        changeTrade({
            opdplanId: this.Id
        }).then(result => {
            console.log(result);
            console.log('typertn+++++'+this.rtnRecordType);
            rtn = result;
            console.log('4-14');
            if (rtn.lenth > 0) {
            //     alert('只有当OPD计划中的备品申请单无/草案/备品申请的出库指示为空时,才可以进行改期操作!');
            //     return;
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '只有当OPD计划中的备品申请单无/草案/备品申请的出库指示为空时,才可以进行改期操作!',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                return;
            }
            if (rtn != 'OK') {
                alert(rtn);
                return;
            }
            // window.open('/a3D/e?CF00N10000008ps4s='+this.Name +'&00N10000008ps4u=延期报告&RecordType=01210000000gQyM');
            
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'CancelPostponePlan__c', // 要新建的对象API
                    actionName: 'new'//,
                    // RecordTypeId: '01210000000gQyM'
                },
                state:{
                    // defaultFieldValues:'CancelOPDPlan__c='+this.Id// 要复制的字段API
                    defaultFieldValues:this.rtnRecordType// 要复制的字段API
                    
                }
            });
            
        });
    }
 
 
}