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
import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
 
import init from '@salesforce/apex/loanerArrangedEmailController.init';
import getRentalApplyEquipmentSet from '@salesforce/apex/loanerArrangedEmailController.getRentalApplyEquipmentSet';
import approvalCheck from '@salesforce/apex/RentalApplyWebService.approvalCheck';
import setShipment_request from '@salesforce/apex/RentalApplyWebService.approvalCheck';
export default class lexLoanerArrangedEmail extends LightningElement {
    @api recordId;
    IsLoading = true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if(currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if(urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback() {
        init({
            recordId: this.recordId
        }).then(result => {
            console.log(this.recordId);
            console.log('result==='+JSON.stringify(result));
            if(result != null) {
                if( result.WeiAssignedCnt > 0 ) {
                    alert("申请单内存在未分配的配套,请分配备品或分割申请单");
                }else if(result.CampaignStatus == "取消") {
                    alert("学会取消,不可出库指示"); 
                }else if (result.RaStatus == "已出库指示" && result.AssignedNotShipment == 0){
                    alert("所有的借出备品Set一览都进行过出库指示了");
                }else if (result.AssignedNotShipment == 0) {
                    alert("没有可以出库指示的明细"); 
                }else if (result.DemoPurpose1 == "长期借出" && result.ContractPdfUpdated == 0){
                    alert("长期借出时,必须先上传契约书"); 
                }else if (result.RepairId != '' && (result.RepairFinalInspectionDateF != null && result.RepairFinalInspectionDateF != '') || (result.RCReturnToOffice != null && result.RCReturnToOffice != '')){
                    alert("修理有最终检测日或修理品返送日,不可出库指示"); 
                }else if (result.IFApproved == "true" && (result.MeetingApprovedNo == null || result.MeetingApprovedNo == "")){
                    alert("没有决裁号的,暂不能出借,请更新裁决信息。"); 
                }else if (result.IFApproved == "true" && result.MeetingApprovedNo != "" && result.StatusList.indexOf(records[0].Approved_Status__c) != -1){
                    alert("已申请决裁但决裁状态不符合条件。"); 
                }else {
                    approvalCheck({
                        rentalApplyId: this.recordId
                    }).then(res=>{
                        if (res != '1') {
                            alert(rs1);
                        } else {
                            //bp2 var rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid});
                            //bp2 if (rs2 != '1') {
                            //bp2 alert(rs2);
                            //bp2 } else {
                            //var rs1 = sforce.apex.execute("RentalApplyWebService", "setShipment_request", {raid : "{!Rental_Apply__c.Id}"}); 
 
                            setShipment_request({
                                raid: this.recordId
                            }).then(res=>{
                                if (res == "状态更新到已出库指示") { 
                                    alert("状态更新到已出库指示");
                                    print();
                                    setTimeout(function() {
                                        location.href = "/{!Rental_Apply__c.Id}"; 
                                    },100);
                                }else {
                                    alert(res);
                                }
                            }).catch(e=>{
                                console.log('approvalCheck==='+e);
                            })
                        }
                    }).catch(e=>{
                        console.log('setShipment_request==='+e);
                    })                
                }
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        })
    }
 
    print() {
        getRentalApplyEquipmentSet({
            recordId: this.recordId
        }).then(result => {
            window.open("https://ocsm--partial.sandbox.lightning.force.com/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result);
        })
    }
 
    fixDate(date){
        var Month = fixTime(date.getMonth() + 1);
        var Day = fixTime(date.getDate());
        var UTC = date.toUTCString();
        var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
        var Minutes = fixTime(date.getMinutes());
        var Seconds = fixTime(date.getSeconds());
        return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
    }
}