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
import { LightningElement, track, wire,api } from 'lwc';
import {CurrentPageReference,NavigationMixin} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
 
 
 
import transferApplyPDF from '@salesforce/apex/TransferApplyController.transferApplyPDF';
export default class lexTransferApplyPDF extends LightningElement {
    @api recordId;
    transferApplyPDFRes;
    IsLoading=true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        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() {
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.log('this.transferApplyId:' + this.recordId);
        transferApplyPDF({
            transferApplyId : this.recordId
        }).then(result => {
            console.log(result);
            this.transferApplyPDFRes = result;            
            this.cancelSubmit().then(res=>{
                this.IsLoading=false;
                this.dispatchEvent(new CloseActionScreenEvent());
            });    
                    
        }).catch( error =>{
            console.log(error);
        });
    }
    async cancelSubmit(){
        let records = new Array();
        records = this.transferApplyPDFRes;
        var size =records.length;
        if(size>0){
            var length = size%10 ==0? size/10 : parseInt(size/10) +1;
            for(var i =0;i<length;i++){
                window.open('/apex/TransferApplyPDF?raid='+this.recordId+'&page=' + i);
            }
        }else{
            this.showToast('当前的申请单中没有已批准备品。','warning');
        }            
    }
 
    showToast(msg, type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
    }
 
}
 
//old js'
/*
{!RequireScript("/soap/ajax/51.0/connection.js")}
{!RequireScript("/soap/ajax/51.0/apex.js")}
var foo = function() {
 
    var sql = "select Id from TransferApplySummary__c where TransferApply__c = '{!TransferApply__c.Id}' and ApprovalDetails__c > 0 and TAS_Status__c != '取消'";
    //Yi_StockDown__c->ApprovalDetails__c 20210805 ljh SFDC-C56D3K 已下架->已批准
    var sqlResult = sforce.connection.query(sql);
    var records = sqlResult.getArray("records");
    var size =records.length;
    if(size>0){
        var length = size%10 ==0? size/10 : parseInt(size/10) +1;
        for(var i =0;i<length;i++){
        window.open('/apex/TransferApplyPDF?raid={!TransferApply__c.Id}&page=' + i);
        }
    }else{
        alert('当前的申请单中没有已批准备品。');
    }
}
foo();
*/