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
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
 
import  updateLastMc  from '@salesforce/apex/lexToAddMaintenanceContractController.updateLastMc';
 
 
export default class lexUpdateLastMc extends LightningElement {
    @api recordId;
 
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
             let str = `${urlValue}`;
             this.recordId = str;
            }
        }
    }
 
    connectedCallback(){
        updateLastMc({
            recordId: this.recordId
        }).then(returnData => {
 
            console.log(returnData);
            this.dispatchEvent(new CloseActionScreenEvent());
            // /lightning/r/Report/00O100000058Bzh/view?fv0={!Maintenance_Contract_Estimate__c.Name}
            if(returnData !='2') {
                window.open(returnData);
            } else {
                this.showToast('报表错误,请联系管理员','error');
            }
            
            this.IsLoading = false;
        })       
    }
    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
/*var excuteFoo =function () {
    var mcpid = '{!MaintanceContractPackEstimate__c.Id}';
// 1、编写SQL通过报价的ID 获取大合同的Id
    var mapcSql = "select id,name from MaintanceContractPack__c where Estimation_Id__r.id ='"+mcpid+"'";
    var mpcsqlResult = sforce.connection.query(mapcSql);
    var records = mpcsqlResult.getArray("records");
    var msg = '';
    for(var i=0;i<records.length;i++) {
        mc = records[0];
        console.log('result:'+mc.Id);
// 2、通过大合同的id获取小合同的ID
        var mccSql = "select id,Name,LastMContract1_NO__c,LastMContract2_NO__c,LastMContract3_NO__c,LastMContract4_NO__c,LastMContract5_NO__c from Maintenance_Contract__c where MaintanceContractPack__c='"+mc.Id+"'";
        var mccsqlResult = sforce.connection.query(mccSql);
        var records2 = mccsqlResult.getArray("records");
        for(var i=0;i<records2.length;i++){
            mc2 = records2[i];
            if(mc2.LastMContract1_NO__c != null && mc2.LastMContract1_NO__c!= ''){
                msg+=mc2.LastMContract1_NO__c+',';
            }
            if(mc2.LastMContract2_NO__c != null && mc2.LastMContract2_NO__c!= ''){
                msg+=mc2.LastMContract2_NO__c+',';
            }
            if(mc2.LastMContract3_NO__c != null && mc2.LastMContract3_NO__c!= ''){
                msg+=mc2.LastMContract3_NO__c+',';
            }
            if(mc2.LastMContract4_NO__c != null && mc2.LastMContract4_NO__c!= ''){
                msg+=mc2.LastMContract4_NO__c+',';
            }
            if(mc2.LastMContract5_NO__c != null && mc2.LastMContract5_NO__c!= ''){
                msg+=mc2.LastMContract5_NO__c+',';
            }
        }
    }
    msg = msg.substring(0, msg.length - 1);
    console.log('result:'+msg);
    window.open('/00O6D000000UpHI?pv0='+msg);
}
excuteFoo();*/