liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { updateRecord } from 'lightning/uiRecordApi';
import init from '@salesforce/apex/LexNewTransferApplyController.init';
import getRecordId from '@salesforce/apex/LexNewTransferApplyController.getRecordId';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexNewTransferApply extends NavigationMixin(LightningElement){
 
    @api recordId;
    IsLoading = true;
    raId;
    raName;
 
    @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(result =>{
            this.raId = result.raId;
            this.raName = result.raName;
 
            let raDetailSet = result.rae;
            let IsCanCreateTransfer = false; 
            if(raDetailSet.length > 0){
                if(raDetailSet[0].Rental_Apply__r.RecordType.DeveloperName != 'AgencyRequest'){
                    this.showToast('此记录类型不支持新建调拨单','warning');
                    return;
                }else{
                    for(let i=0; i<raDetailSet.length; i++){
                        console.log('raDetailSet[i].Asset__c' + JSON.stringify(raDetailSet[i]));
                        console.log(raDetailSet[i].Is_Body__c);
                        if(raDetailSet[i].Asset__c != null){
                            //画面默认且仅显示符合调拨要求的数据(①欠品断念后找回的主体 ②(主体上架ok)欠品断念后找回的附属品 ③主体待修理的整个配套 ④(主体上架ok)待修理的附属品)⑤主体断念后单独的附属品    
                            if(raDetailSet[i].Is_Body__c){
                                //①欠品断念后找回的主体
                                if(raDetailSet[i].Lost_item_giveup__c){
                                    IsCanCreateTransfer = true; break;
                                } 
                                //③主体待修理的整个配套
                                if(raDetailSet[i].Arrival_wh_Result_Agency__c != null && (raDetailSet[i].Arrival_wh_Result_Agency__c == '待修理' || raDetailSet[i].Arrival_wh_Result_Agency__c == '移至报废区' )){
                                    IsCanCreateTransfer = true; break;
                                } 
                            }else{
                                //③主体待修理的整个配套(不是欠品的附属品) 
                                if(raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_Result_Agency__c != null &&
                                (raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_Result_Agency__c == '待修理' ||
                                raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_Result_Agency__c == '移至报废区' ) &&
                                raDetailSet[i].OneToOne_Flag__c &&
                                raDetailSet[i].Arrival_wh_Result_Agency__c != null
                                ){
                                    IsCanCreateTransfer = true; break;
                                } 
 
                                //②主体欠品断念后的整个配套(不是欠品的附属品)
                                //有主体得是一对一附属品 
                                if(raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Lost_item_giveup__c &&
                                raDetailSet[i].OneToOne_Flag__c &&
                                raDetailSet[i].Arrival_wh_Result_Agency__c != null){
                                    IsCanCreateTransfer = true; break;
                                } 
 
                                //④(主体上架ok)待修理的附属品 
                                if(raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_Result_Agency__c !=null &&
                                raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_Result_Agency__c == 'OK' &&
                                raDetailSet[i].OneToOne_Flag__c &&
                                raDetailSet[i].Arrival_wh_Result_Agency__c != null && (raDetailSet[i].Arrival_wh_Result_Agency__c == '待修理' || raDetailSet[i].Arrival_wh_Result_Agency__c == '移至报废区')){
                                    IsCanCreateTransfer = true; break;
                                } 
 
                                //⑤ 断念后的附属品
                                if(raDetailSet[i].Lost_item_giveup__c){
                                    IsCanCreateTransfer = true; break;
                                } 
 
                                if(raDetailSet[i].Rental_Apply_Equipment_Set__r.First_You_Xiao_Ku_Cun__c <= 0
                                && raDetailSet[i].OneToOne_Flag__c && raDetailSet[i].Check_lost_Item__c != null && raDetailSet[i].Check_lost_Item_Final__c !=null && raDetailSet[i].Check_lost_Item__c == '欠品' && raDetailSet[i].Check_lost_Item_Final__c == 'OK'
                                && raDetailSet[i].Arrival_in_wh__c
                                && raDetailSet[i].Arrival_wh_time__c != raDetailSet[i].Rental_Apply_Equipment_Set__r.First_RAESD__r.Arrival_wh_time__c ){
                                    IsCanCreateTransfer = true; break;
                                } 
                            }
                        }
                    }
                    console.log('IsCanCreateTransfer=='+IsCanCreateTransfer);
                    if(IsCanCreateTransfer){
                        getRecordId().then(res=>{
                            console.log('res===='+res);
                            const defaultValues = encodeDefaultFieldValues({
                                Name: '*',
                                Rental_Apply__c: this.recordId
                            });
 
                            this[NavigationMixin.Navigate]({
                                type: 'standard__objectPage',
                                attributes: {
                                    objectApiName: 'TransferApply__c',
                                    actionName: 'new',
                                    RecordType: res
                                },
                                state:{
                                    nooverride: '1',// 20230924 ljh add
                                    // defaultFieldValues: this.defaultValues
                                    defaultFieldValues: defaultValues
                                    // 20230924 ljh update
                                }
                            })
                        })
                    }else{
                        this.showToast('该申请没有符合条件的借出备品配套一览明细!','warning');
                        return;
                    }
                }
            }else{
                this.showToast('该申请没有符合条件的借出备品配套一览明细!','warning');
                return;
            }
        })
        .catch(err=>{
            this.dispatchEvent(new CloseActionScreenEvent());
            console.log('init==='+err);
        })
    }
 
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.updateRecordView(this.recordId);
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}