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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
function initLwc(SelectFieldParamList,flage){
    for (var i = SelectFieldParamList.length - 1; i >= 0; i--) {
        let parm=SelectFieldParamList[i]
        if(flage&&parm.oldElm){
            let clm=document.getElementById(parm.lightningId);
            console.log(clm.parentNode.replaceChild(parm.oldElm,clm));
            initLwcData(parm,0);
            continue;  
        }
        $Lightning.use("c:LexSelectFieldApp", function() {
            $Lightning.createComponent(
                "c:LexSelectFieldCmp",
                {
                    "objApiName": parm.objType,
                    "fieldApiName": parm.field,
                    "recordId" : parm.recordId,
                },
                parm.lightningId,
                function(cmp) {
                    console.log(cmp);
                    unblockUI();
                    setTimeout(()=>{
                        initLwcData(parm,0);
                    },1000);
                    // setTimeout(()=>{
                    //     resetInitValue(parm,0);
                    // },1500);
                }
            );
        });
    }
}
function initLwcData(parm,count){
    if(count>10){return;}
    try{
        console.log(document.getElementById(parm.lightningId));
        console.log(document.getElementById(parm.lightningId).querySelectorAll('input'));
        if(!document.getElementById(parm.lightningId).querySelectorAll('input')){
            return;
        }
        let inp=document.getElementById(parm.lightningId).querySelectorAll('input')[0].id.replace('combobox-input-','');
        console.log('combobox-input-'+inp+'-0-' + inp);
        let comboxId='#combobox-input-'+inp+'-0-' + inp;
        let style = document.createElement('style');
        style.innerHTML=
            comboxId+'{'+
            'display:none'+
            '}';
        let ref=document.querySelector('script');
        ref.parentNode.insertBefore(style, ref);
        console.log(style);
    }catch(e){
        console.log("初始化失败:"+count);
        console.log(e);
        setTimeout(()=>{
            initLwcData(parm,count+1);
        },1000);
    }
}
//重新设置初始数据
function resetInitValue(parm,count){
    if(count>10){
        return;
    }
    try{
        lwcItem=document.getElementById(parm.lightningId);
        let liIrtem=lwcItem.querySelectorAll('lightning-base-combobox-item');
        console.log(liIrtem);
        let objId=document.getElementById(parm.inputFieldId + '_lkid').value;
        if(!liIrtem[1]){
            setTimeout(()=>{
                resetInitValue(parm,count+1);
            },1000);
            return;
        }
        setNodeValue(liIrtem[1],objId).then(function (){
            liIrtem[1].click();
        })
    }catch(e){
        console.log(e);
        setTimeout(()=>{
            resetInitValue(parm,count+1);
        },1000);
    }
}
//设置节点数值
function setNodeValue(node,setid){
    return new Promise(function(resolve, reject) {
        node.attributes.getNamedItem('data-value').value=setid;
        resolve();
    });
}
//刷新数据
function refreshSelectFieldValue(SelectFieldParamList,elm){
    let elmId=elm.id;
    let SelectFieldParamParam;
    for (var i = SelectFieldParamList.length - 1; i >= 0; i--) {
        if(SelectFieldParamList[i].lightningId==elmId){
            SelectFieldParamParam=SelectFieldParamList[i];
            break;
        }
    }
    let lcm=document.getElementById(SelectFieldParamParam.lightningId);
    const inputFields = lcm.querySelectorAll('input');
    if (inputFields) {
        try{
            setTimeout(()=>{
                let objName=inputFields[0].attributes.getNamedItem('data-value');
                objName=objName.value;
                let objId=inputFields[1].value;
                if(objId==null||objId=='000000000000000AAA'||objId=='000000000000000'){
                    return;
                }
                j$(escapeVfId(SelectFieldParamParam.inputFieldId)).val(objName);
                j$(escapeVfId(SelectFieldParamParam.inputFieldId + '_lkold')).val(objName);
                j$(escapeVfId(SelectFieldParamParam.inputFieldId + '_lkid')).val(objId);
                j$(escapeVfId(SelectFieldParamParam.inputHiddenId)).val(objId);
                SelectFieldParamParam.oldElm=lcm;
                console.log('更新数值:');
                console.log(objName);
                console.log(objId);
            },100); 
        }catch(e){
            console.log(e);
        }
    } 
}
//标准控件修改 end
 
 
function resetOpenPage(SelectFieldParamList){
    for (var i = SelectFieldParamList.length - 1; i >= 0; i--) {
        try{
            let parm=SelectFieldParamList[i];
            console.log("dddd");
            console.log(parm);
            if(document.getElementById(parm.inputFieldId).type=='hidden'){
                let newId=parm.inputFieldId+'_lkid';
                console.log(newId);
                console.log(document.getElementById(newId))
                document.getElementById(newId).parentNode.children[1].removeAttribute("href");
                document.getElementById(newId).parentNode.children[1].onclick = function() {
                    OpenSelectPage(parm);
                };
            }else{
                console.log(document.getElementById(parm.inputFieldId));
                document.getElementById(parm.inputFieldId).parentNode.children[2].removeAttribute("href");
                document.getElementById(parm.inputFieldId).parentNode.children[2].onclick = function() {
                    OpenSelectPage(parm);
                };
            }
 
        }catch(e){
            console.log(e);
            continue;
        }
 
    }
}
let newSelectPage;
function OpenSelectPage(parm){
    let searchContactKeyWord = document.getElementById(parm.inputFieldId).value;
    let responsibleNodeId = document.getElementById(parm.inputFieldId).value;
    let accountValue=searchContactKeyWord;
    console.log('accountValue:'+accountValue);
    if (accountValue != '000000000000000') {
        let baseUrl = "/apex/SearchContactPageLWC";
        // let suffixUrl = "?contactId=" + responsibleNodeId + "&accountId=" + accountValue+"&searchContactKeyWord=" + searchContactKeyWord +
        // "&Type=OFS" + '&ObjectType=' + parm.ObjectType + '&QueryFieldApiName=' + parm.QueryFieldApiName +
        let suffixUrl = "?searchContactKeyWord=" + searchContactKeyWord + '&ObjectType=' + parm.ObjectType + '&QueryFieldApiName=' + parm.QueryFieldApiName +
        '&inputFieldId=' + parm.inputFieldId +
        // '&SelectObj=' + parm.SelectObj + '&SelectFld=' + parm.SelectFld;
        '&SelectObj=' + parm.SelectObj + '&FilterSql='+ parm.FilterSql;
        //20231104 李文涛 setVal查询条件 start
        if(parm.setVal){
            console.log('setVal:=');
            console.log(parm.setVal);
           suffixUrl = suffixUrl +'&setVal='+parm.setVal;
        }
        //20231104 李文涛 setVal查询条件 end
        let newSearchContactParam = 'height=500,width=800,left=100,top=100,dialogHide=true,resizable=no,scrollbars=yes,toolbar=no,status=no';
        newSelectPage = window.open(baseUrl + suffixUrl, 'Popup', newSearchContactParam);
        if (window.focus) {
            newSelectPage.focus();
        }
        return false;
    } else {
        alertErrorMessage('请先输入查询名称');
    }
}