buli
2022-04-26 5835379ec30b1667c4e522db9d294c9b7bb8633a
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<apex:page standardController="loaner_user__c" extensions="NewLoanerUserController" id="allPage" showHeader="true" sidebar="false" action="{!init}" title="新建样机借用客户">
<!-- <apex:page standardController="loaner_user__c" extensions="NewLoanerUserController" showHeader="true" sidebar="false" action="{!init}" title="新建样机借用客户"> -->
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <!-- Update 20220317 By Yang Kaiyu Start -->
    <apex:includeScript value="{!URLFOR($Resource.CommonUtilJs)}"/>
    <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
    <apex:includeScript value="/soap/ajax/40.0/connection.js"/>
    <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script>
    <!-- Update 20220317 By Yang Kaiyu End -->
    <script>
        // Update 20220317 By Yang Kaiyu Start
        AWSService.sfSessionId = '{!GETSESSIONID()}';
        var staticResource = JSON.parse('{!staticResource}');
        var staticResourceContact = JSON.parse('{!staticResourceContact}');
        var aws_data = {};
        let conList = [];
        //替换vlookup
        var closeField = '';
        var newSearchContactWindow = null;
        var contactInfoStr = '';
        var conValue = ''
        //自定义lookup查询
        function searchContact(contactNodeId,field,conValue,conid){
            closeField = conid;
            this.conValue = conValue;
            let accountValue = "";
            if (document.getElementById(field)!=null) {
                accountValue = document.getElementById(field).value;   
            } 
            console.log(accountValue);
            if(accountValue !='000000000000000'){
                let baseUrl = "/apex/SearchContactPage";
                let searchContactKeyWord = document.getElementById(conid).value;
                let suffixUrl = "?contactId="+contactNodeId+"&accountId="+accountValue+"&searchContactKeyWord=" + searchContactKeyWord;
                let newSearchContactParam = 'height=600,width=800,left=100,top=100,dialogHide=true,resizable=no,scrollbars=yes,toolbar=no,status=no';
                newSearchContactWindow = window.open(baseUrl+suffixUrl, 'Popup', newSearchContactParam);
                if (window.focus) {
                    newSearchContactWindow.focus();
                }
                return false;
            }else{
                alert('请先选择客户再选择联系人')
            }
        }
        var dataLinesJson;
        function replaceSearchContactLookup() {
            conList = JSON.parse('{!conListJson}');
            dataLinesJson = JSON.parse('{!dataLinesJson}');
            console.log('dataLinesJson = ' + dataLinesJson);
            for(var i = 0;i<dataLinesJson.length;i++){
                let ii = i;
                document.getElementById('allPage:allForm:allBlock:lines:'+ii+':contact').addEventListener('click',function(){
                    searchContact('allPage:allForm:contactId','allPage:allForm:allBlock:lines:'+ii+':customer_lkid','allPage:allForm:allBlock:lines:'+ii+':contactId_Hidden','allPage:allForm:allBlock:lines:'+ii+':contact');
                });
            }
            
            
        }
        function htmlToElement(html) {
            var template = document.createElement('template');
            html = html.trim(); // Never return a text node of whitespace as the result
            template.innerHTML = html;
            return template.content.firstChild;
        }
        function closePopupWindow() {
            if (null != newSearchContactWindow) {
                newSearchContactWindow.close();
            }
            contactInfoStr = document.getElementById('allPage:allForm:contactId').value;
            console.log('closePopup:'+contactInfoStr);
            let contactInfo = JSON.parse(contactInfoStr);
            let contactNodeId = conValue;
            document.getElementById(contactNodeId).value = contactInfo.ContactId;
            document.getElementById(closeField).value = contactInfo.Name;     
        }
        function DecryptAll(){
            let dataIds = [];
            
            //"{!conList}".each((i,e)=>{
            //    console.log('------------------')
            //    console.log(e);
            //    let v = "{!conList}"[i].contactIdValue;
            //    if (v) {
            //        dataIds.push(v);
            //    }
            //});
            conList = JSON.parse('{!conListJson}');
            if(conList){
                for(var i=0 ;i<conList.length;i++){
                    if(conList[i]!=null){
                        let v = conList[i].contactIdValue;
                        if (v) {
                            dataIds.push(v);
                        }
                    }
                }
            }
            
            Decrypt(dataIds);
        }
        j$(function(){
            DecryptAll();
            
        })
        function Decrypt(dataIds){
            let Foo = function(){
                for (const id in dataIds) {
                    if (aws_data.hasOwnProperty(dataIds[id])) {
                        let d = aws_data[dataIds[id]];
                        let $e =j$("[aws-id='"+d.dataId+ "']");
                        //$e.html(d[$e.attr("aws-id")]);
                        $e.each(function(i,e){
                            j$(e).val(d.lastName);
                        })
                    }
                }
            }
            let ids = [];
            //for (const id in dataIds) {
            //    if (!aws_data.hasOwnProperty(id)) {
            //        ids.push(id);
            //    }
            //}
            for(var i =0 ;i<dataIds.length;i++){
                if (!aws_data.hasOwnProperty(dataIds[i])) {
                    ids.push(dataIds[i]);
                }
            }
            if (ids.length > 0) {
                blockme();
                AWSService.search(staticResourceContact.searchUrl,
                JSON.stringify({
                    "dataIds":ids
                }),
                function(data){
                    unblockUI();
                    if(data.object && data.object.length > 0){
                        
                        for(let d in data.object){
                            console.log('----------------')
                            console.log(d);
                            if(data.object[d].dataId){
                                aws_data[data.object[d].dataId] = data.object[d];
                            }
                        }
                        Foo();
                    }
                },
                staticResourceContact.token);
            }else{
                Foo();
            }
        }
        // Update 20220317 By Yang Kaiyu End
        function saveJs() {
        if(confirm('联系人和客户为必填信息,如果为空将不保存此条记录,是否已确认所有需要保存的信息该字段都不为空?')){
            blockme();
            updateUser();
        }
    }
    </script>
 
 
 
    <style type="text/css">
        .dateFormat{
            display: none;
        }
    </style>
 
    <apex:form id="allForm">
        <!-- Update 20220317 By Yang Kaiyu Start -->
         <apex:inputHidden value="{!contactId}" id="contactId" />
         <!-- Update 20220317 By Yang Kaiyu End -->
         <apex:actionFunction name="updateUser" action="{!updateUser}" rerender="allForm,message,allPanel" onComplete="unblockUI();"></apex:actionFunction>
         <apex:outputPanel id="message">
            <apex:messages />
        </apex:outputPanel>
 
         <apex:outputPanel id="allPanel">
            <apex:pageBlock id="allBlock">
                <table style="width: 100%;">
                    <tr>
                        <th style="text-align: left;font-size: 20px;">
                            新建样机借用客户
                        </th>
                        <th style="text-align: right;">
                            <apex:commandButton action="{!cancelBtn}" value="返回" rerender="dummy" style="width: 70px;"/>
                            <apex:commandButton onclick="saveJs();" value="确认" rerender="allForm" style="width: 70px;"/>
                        </th>
                    </tr>
                </table>
                    <div style="overflow: scroll;height: 300px;width: 1260px; ">
                       <apex:variable value="{!1}" var="cnt" />
                    <apex:repeat value="{!dataLines}" var="line" id="lines">
                        <div style="width: 1260px;">
                            {!$ObjectType.loaner_user__c.fields.Customer__c.label}:
                            <!-- Update 20220317 By Yang Kaiyu Start -->
                            <apex:inputField id="customer" value="{!line.Customer__c}" />
                            <!-- Update 20220317 By Yang Kaiyu End -->
                               {!$ObjectType.loaner_user__c.fields.Contact__c.label}:
                            <!-- Update 20220317 By Yang Kaiyu Start -->
                               <!-- <apex:inputField id="contact"  value="{!line.Contact__c}" html-aws-id="{!line.Contact__r.AWS_Data_Id__c}" /> -->
                            <apex:inputText id="contact" html-aws-id="{!line.Contact__r.AWS_Data_Id__c}" disabled="false" value="{!line.Contact__r.LastName}" ></apex:inputText> 
                            <apex:inputText id="contactId_Hidden" value="{!line.Contact__c}" style="display:none"/>                     
                            <!-- Update 20220317 By Yang Kaiyu End -->
 
                               {!$ObjectType.loaner_user__c.fields.FromThePeriod__c.label}:
                               <apex:inputField value="{!line.FromThePeriod__c}"/>
                               {!$ObjectType.loaner_user__c.fields.EndThePeriod__c.label}:
                               <apex:inputField value="{!line.EndThePeriod__c}"/>
                            {!$ObjectType.loaner_user__c.fields.Follow_UP_Opp__c.label}:
                            <apex:inputField value="{!line.Follow_UP_Opp__c}"/>
                               {!$ObjectType.loaner_user__c.fields.Remarks__c.label}:
                               <apex:inputField value="{!line.Remarks__c}"/>
                               <apex:variable value="{!cnt + 1}" var="cnt" />
                           </div>
                    </apex:repeat>
                    <!-- Update 20220317 By Yang Kaiyu Start -->
                    <script>
                        sfdcPage.appendToOnloadQueue(function () {
                            //Replace Vlookup Field
                            
                            replaceSearchContactLookup();
                        })
                    </script>
                    <!-- Update 20220317 By Yang Kaiyu End -->
                </div>
 
            </apex:pageBlock>
        </apex:outputPanel>
 
    </apex:form>
 
 
</apex:page>