高章伟
2023-10-30 e48cd34b21a3841cac102402c15903e8e075ad02
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
import { LightningElement, track } from 'lwc';
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
import selectInfrastructureProjectById from '@salesforce/apex/infrastructureProjectRelatedOpController.selectInfrastructureProjectById';
import selectoppByAccountId from '@salesforce/apex/infrastructureProjectRelatedOpController.selectoppByAccountId';
import selectoppByOpportunityNoc from '@salesforce/apex/infrastructureProjectRelatedOpController.selectoppByOpportunityNoc';
import saveOppInfrastructureProject from '@salesforce/apex/infrastructureProjectRelatedOpController.saveOppInfrastructureProject';
 
 
export default class InfrastructureProjectRelatedOpp extends LightningElement {
    InfProId = '';
    @track
    IsLoading = false;
    @track
    InfPro = {Id:'',Name:'',OCSM_Hospital__c:'',OCSM_Hospital__r:{}};
    @track
    jzDataToOpp={};
    stylesLoaded = false;
    renderedCallback(){ 
        if (!this.stylesLoaded) {
            Promise.all([loadStyle(this, WrappedHeaderTable)])
                .then(() => {
                    console.log("Custom styles loaded");
                    this.stylesLoaded = true;
                })
                .catch((error) => {
                    console.error("Error loading custom styles");
                });
        }
    }
    connectedCallback() {
        this.IsLoading = true;
        this.InfProId =  this.getQueryVariable('Id');
        selectInfrastructureProjectById({InfProId:this.InfProId}).then(res=>{
            debugger
            this.InfPro = res;
            this.InfPro.url = '/'+res.OCSM_Hospital__c;
            selectoppByAccountId({OCSMHospital:this.InfPro.OCSM_Hospital__c}).then(opp=>{
                debugger
                this.jzDataToOpp = opp;
                this.IsLoading = false;
            });
        });
    }
    getQueryVariable(variable) { //id字符串
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return '';
    }
    SelectedOppValue = [];
    saveValue = [];
    Selectedopp(event){
        let arr = event.detail.rows;
        this.SelectedOppValue = arr;
        this.saveValue = [];
        var selectId =  new Map();
        if(this.SelectedOppValue){
            this.SelectedOppValue.forEach(itm=>{
                selectId.set(itm.Id,itm.Id);
            });
            this.jzDataToOpp.forEach(item=>{
                if(selectId.has(item.Id)){
                    item.Infrastructure_Project__c = this.InfProId;
                    this.saveValue.push(item);
                }else{
                    item.Infrastructure_Project__c = null;
                }
            });
        }
        debugger
    }
    OppValue;
    jzOppsearchChange(event){
        if(this.OppValue != event.target.value){
            this.OppValue = event.target.value;
        }
    }
    jzOppsearchbutton(){
        debugger
        this.IsLoading = true;
        selectoppByOpportunityNoc({OCSMHospital:this.InfPro.OCSM_Hospital__c,OpportunityNoc:this.OppValue}).then(rvalue=>{
            debugger
            this.jzDataToOpp = rvalue;
            this.IsLoading = false;
        });
    }
    saveOpp(){
        this.IsLoading = true;
        var saveValuec = JSON.stringify(this.saveValue);
        saveOppInfrastructureProject({saveValuec:saveValuec}).then(res=>{
            debugger
            if(res != 'success'){
                alert(res);
            }else{
                window.location.hash = "Refresh"+"=="+this.InfProId;
            }
            this.IsLoading = false;
        });
    }
    initDataTableToOpp = {
        columns: [
            {
                label: '状态1',
                fieldName: 'StageName__c',
                editable: false,
                cellAttributes: {
                    class: {},
                    alignment: 'left'
                },
                hideDefaultActions: true,
                initialWidth:60
            },
            {
                label: '询价名称',
                fieldName: 'Name',
                type: 'text',
                cellAttributes: {
                    alignment: 'left'
                },
                hideDefaultActions: true,
            },
            {
                label: '询价编码',
                fieldName: 'Opportunity_No__c',
                cellAttributes: {
                    alignment: 'left'
                },
                hideDefaultActions: true,
            },
            {
                label: '询价阶段',
                fieldName: 'Opportunity_stage__c',
                cellAttributes: {
                    alignment: 'left'
                },
                hideDefaultActions: true,
            }
        ],
        sortInterfaces: false,
        searchColumns: []
    };
    getTableDataToOpp(){
    }
 
}