高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<apex:page controller="CampaignMemberController" showHeader="false" sidebar="false" id="allPage" action="{!init}" title="参会人员">
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:stylesheet value="{!URLFOR($Resource.jquerysuggestcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquerysuggestjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
<style type="text/css">
    .visitorplace_results {
        border: 1px solid gray;
        background-color: white;
        padding: 0;
        margin: 0;
        list-style: none;
        position: absolute;
        z-index: 10000;
        display: none;
        overflow:auto;
        white-space:nowrap;
        width:400px;
        height:250px;
    }
    .visitorplace_results li {
        padding: 2px 5px 2px 0px;
        margin-left : 2px;
        color: #101010;
        text-align: left;
    }
</style>
<script>
//訪問場所インスタント検索
//allPage:allForm:allBlock:records:0:department
sforce.connection.sessionId = '{!$Api.Session_ID}';
 
var Error_Message15 = '医院科室不存在,请重新设定。';
var Error_Message16 = '请设定医院科室。';
 
function setVisitorPlace(index){
    try{
        var str = 'allPage:allForm:allBlock:records:'+ index + ':department';
        var strPage = null;
        var options = {};
 
        var ros = j$(escapeVfId('userState')).value();
 
        strPage = '/apex/CM_SearchDepartment?r=' + encodeURI(ros);
        options = {minchars:3, minwords:2, resultsClass:'visitorplace_results'};
 
        jQuery(escapeVfId(str)).unbind();
        if (strPage != null) {
            jQuery(escapeVfId(str)).suggest(strPage,options);
        }
    }catch(e){
        alert(e);
    }
 
    //setVisitorPlaceDisabled();
}
 
function vpClear2_delay(index){
    var vp = 'allPage:allForm:allBlock:records:'+ index + ':department';
    var vpHidden = 'allPage:allForm:allBlock:records:'+ index + ':departmentHidden';
    setTimeout(
        function() {
            //alert('jquerysuggest_skip_flag=' + j$(escapeVfId(vp)).attr("jquerysuggest_skip_flag"));
            if(j$(escapeVfId(vp)).attr("jquerysuggest_skip_flag") == "false") {
                if (j$(escapeVfId(vp)).value() != j$(escapeVfId(vpHidden)).value()) {
                    vpClear2(index);
                }
            }
        },
        200
    );
}
 
function vpClear2(index){
  var vp = 'allPage:allForm:allBlock:records:'+ index + ':department';
  var vpHidden = 'allPage:allForm:allBlock:records:'+ index + ':departmentHidden';
  var vpId = 'allPage:allForm:allBlock:records:'+ index + ':departmentId';
  var vpHiddenId = 'allPage:allForm:allBlock:records:'+ index + ':departmentHiddenId';
  if (j$(escapeVfId(vp)).value() != j$(escapeVfId(vpHidden)).value() || j$(escapeVfId(vpId)).value() != j$(escapeVfId(vpHiddenId)).value()) {
    changeFlg = 'false';
    v1 = 'allPage:allForm:allBlock:records:' + index + ':contact';
 
    if(j$(escapeVfId(v1)).value() != null && j$(escapeVfId(v1)).value() != ''){changeFlg = 'true';}
 
    unblockUI();
    //alert('changeFlg+' +changeFlg);
    if(changeFlg == 'true'){
        alert('设定参会人员后,不能变更医院科室。');
        vpBefore = j$(escapeVfId('allPage:allForm:allBlock:records:' + index + ':departmentHidden')).value();
        vpIdBefore = j$(escapeVfId('allPage:allForm:allBlock:records:' + index + ':departmentHiddenId')).value();
        j$(escapeVfId('allPage:allForm:allBlock:records:' + index + ':department')).val(vpBefore);
        j$(escapeVfId('allPage:allForm:allBlock:records:' + index + ':departmentId')).val(vpIdBefore);
        document.getElementById('allPage:allForm:allBlock:records:' + index + ':department').blur();
        return;
    }
  }
  resetValue('allPage:allForm:allBlock:records:'+ index + ':department');
}
 
    //関連する引合インスタント検索
    function setRelOppId(index, id, hiddenId){
        try{
            var str = 'allPage:allForm:allBlock:records:'+ index + ':' + id;
            var strPD = 'allPage:allForm:allBlock:records:'+ index + ':department';
            var aNamePD = j$(escapeVfId(strPD)).value();
            if(aNamePD == ''){
                // 訪問場所を設定してください。
                document.getElementById(str).blur();
                alert(Error_Message16);
                return;
            }
 
            var strVP = 'allPage:allForm:allBlock:records:'+ index + ':departmentId';
            var vl = j$(escapeVfId(strVP)).value();
            if(vl.length == 0){
                // 訪問場所が存在しません。
                document.getElementById(str).blur();
                alert(Error_Message15);
                return;
            }
 
            var match = sforce.apex.execute("Add_Report","checkAccountMatch",{name:aNamePD,id:vl});
            if(match == "NG"){
                // 訪問場所IDマッチしていない
                document.getElementById(str).blur();
                alert("无法确定访问场所,请再设定一次访问场所。");
                return;
            }
 
            var strPage = '/apex/CM_SearchOpportunity?r=' + encodeURI(vl);
            jQuery(escapeVfId(str)).unbind();
            jQuery(escapeVfId(str)).suggest(strPage,{});
        }catch(e){
            alert(e);
        }
    }
 
function saveJs() {
    blockme();
    saveLine();
}
function addJs() {
    blockme();
    addLine();
}
function closeJs() {
    window.close();
}
function deleteJs(line) {
    blockme();
    deleteLine(line);
}
 
function openSearchContact(line) {
    var vpHiddenId = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':departmentHiddenId')).value();
    if (vpHiddenId == null || vpHiddenId == '') {
        alert("请先选择医院科室。");
        return false;
    }
    var urlStr = 'apex/CM_SearchContact?line='+ line + '&acc=' + vpHiddenId;
    var w = window.open(urlStr,'CM_SearchContact','menubar=no,height=580,width=620');
    w.focus();
}
 
function openCreateLead(line) {
    var username = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':contact')).value();
    var userid = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':contactId')).value();
    var contactSDCName = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':contactSDCName')).value();
    var acc = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':department')).value();
    var accid = j$(escapeVfId('allPage:allForm:allBlock:records:'+ (line-1) + ':departmentId')).value();
    var campaign = j$(escapeVfId('campaignName')).value();
    var campaignId = j$(escapeVfId('campaignId')).value();
    
    console.log('userid:'+userid+'---'+'contactSDCName:'+contactSDCName);
 
    var sql = "select id,name,Department_Class__c,Department_Class__r.Name from Account where Id='"+accid+"'";
    var sqlResult = sforce.connection.query(sql);
    var records = sqlResult.getArray("records"); 
 
    console.log('aaaaa:'+records[0].Department_Class__c+',bbbbb:'+records[0].Department_Class__r.Name);
 
    var surname = username.replace(/\s/g,"");
    if(surname.length == 3 || surname.length == 2){
        var family_name = surname.substring(0,1);
        var last_name = surname.substring(1);
    }else if(surname.length == 4){
        var family_name = surname.substring(0,2);
        var last_name = surname.substring(1);
    }else{
        var family_name ='';
        var last_name ='';
    }
    console.log('姓:'+family_name +'名:'+last_name);
    if (username == null || username == '') {
        alert("请先选择参会人员。");
    } else{
        //JZ-20191009 通过学会·培训记录区分新建意向还是新建询问单 START
        var recordType = "{!cam.recordType.developerName}";
        console.log(recordType);
        if(recordType !='Society' && recordType !='BusinessTraining'){
            // 新建意向URL
            var urlStr = '/00Q/e?RecordType=01210000000QiRa&ent=Lead&name_lastlea2=' + encodeURI(username) +
                    '&CF00N10000006ps6f=' + encodeURI(username) +
                    '&CF00N10000006ps6f_lkid=' + userid +
                    '&lea3=' + encodeURI(acc) +
                    '&CF00N10000002CvC5=' + encodeURI(acc) +
                    '&CF00N10000002CvC5_lkid=' + accid +
                    '&lea20=' + encodeURI(campaign) + 
                    '&lea20_lkid=' + campaignId +
                    '&CF00N10000004oN28=' + encodeURI(campaign) + 
                    '&CF00N10000004oN28_lkid=' + campaignId +
                    '&lea5=' + encodeURI('学会/沙龙') + 
                    '&CF00N10000006qNtt=' + encodeURI(contactSDCName);
        }else{      
            //新建询问单 URL  客户姓名 科室  询问单来源 主要学会 公司 意向学会
            var urlStr = '/a41/e?ent=Inquiry_form&name_lastlea2=' + encodeURI(username) +
                    '&CF00N1000000962n8=' + encodeURI(username) + 
                    '&CF00N1000000962n8_lkid=' + userid +
                    '&00N1000000962n5=' + encodeURI(acc) +
                    '&CF00N1000000962nJ=' + encodeURI(acc) + 
                    '&CF00N1000000962nJ_lkid=' + accid +
                    '&CF00N1000000962n3=' + encodeURI(campaign) + 
                    '&CF00N1000000962n3_lkid=' + campaignId +
                    '&00N1000000962nO=' + encodeURI('学会/沙龙') +
                    '&CF00N1000000962nC=' + encodeURI(records[0].Department_Class__r.Name)+
                    '&CF00N1000000962nC_lkid=' + encodeURI(records[0].Department_Class__c)+
                    '&Name='+encodeURI(username)+
                    '&00N1000000962nH='+encodeURI(family_name)+
                    '&00N1000000962nN='+encodeURI(last_name)+
                    '&00N1000000962nT='+ encodeURI('信息');
        }
        //JZ-20191009 通过学会·培训记录区分新建意向还是新建询问单 END
 
        window.open(urlStr);
    }
}
 
</script>
 
    <apex:form id="allForm">
        <apex:actionFunction name="saveLine" action="{!saveLine}" rerender="allForm,allPanel,allBlock" oncomplete="checkLine('1');">
        </apex:actionFunction>
        <apex:actionFunction name="addLine" action="{!addLine}" rerender="allForm,allPanel,allBlock,records" oncomplete="checkLine();">
        </apex:actionFunction>
        <apex:actionFunction name="deleteLine" action="{!deleteLine}" rerender="allForm,allPanel,allBlock,records" oncomplete="checkLine();">
            <apex:param name="firstParam" assignTo="{!lineNo}" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="checkLine" action="{!checkLine}" rerender="allForm,allPanel,allBlock,records" oncomplete="unblockUI();">
            <apex:param name="firstParam" assignTo="{!saveflg}" value="" />
        </apex:actionFunction>
        <apex:outputPanel id="allPanel">
            <apex:pageBlock id="allBlock">
                <apex:pageBlockButtons location="top">
                    <apex:commandButton immediate="true" onclick="saveJs();" value="保存" rerender="dummy"/>
                    <apex:commandButton immediate="true" onclick="addJs();" value="添加行" rerender="dummy"/>
                    <apex:commandButton immediate="true" onclick="closeJs();" value="关闭" rerender="dummy"/>
                </apex:pageBlockButtons>
 
                <apex:outputPanel id="message">
                    <apex:pageMessages />
                </apex:outputPanel>
 
                <input type="hidden" id="campaignName" value="{!campaignName}"/>
                <input type="hidden" id="campaignId" value="{!campaignId}"/>
                <input type="hidden" id="hasError" value="{!hasError}"/>
                <input type="hidden" id="userState" value="{!localuser.State_Hospital__c}"/>
 
                <table class="linetable" border="1" style="border-collapse: collapse;width:850px;table-layout:fixed;">
                    <colgroup>
                        <col width="40px"/>
                        <col width="300px"/>
                        <col width="150px"/>
                        <!-- SWAG-B9J9YR 2-19-02-19 start -->
 
                        <apex:variable value="Training_event" var="Training_event" rendered="{!IF(cam.recordType.developerName == 'Training_event', false, true)}">
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 START -->
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',false,true)}">
                                <col width="150px" />
                            </apex:variable>
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 END -->
                                <col width="60px"/>
                        </apex:variable>
                         <!-- SWAG-B9J9YR 2-19-02-19 end -->
                        <col width="100px"/>
                        <col width="50px"/>
                    </colgroup>
                    <tr style="background-color:#DCDCDC;">
                        <th style="text-align:center">No.</th>
                        <!-- <th style="text-align:center">{!$ObjectType.CampaignMember__c.fields.Department__c.label}</th> -->
                        <!-- SWAG-BLPDK7 update by vivek 2020-02-12 start  -->
                        <th style="text-align:center">
                            <!-- {!$ObjectType.CampaignMember__c.fields.Department__c.label} -->
                            医院科室/经销商
                        </th>
                        <!-- SWAG-BLPDK7 update by vivek 2020-02-12 end  -->
                        <th style="text-align:center">{!$ObjectType.CampaignMember__c.fields.Contact__c.label}</th>
                        <!-- SWAG-B9J9YR 2-19-02-19 start -->
                        <apex:variable value="Training_event" var="Training_event" rendered="{!IF(cam.recordType.developerName == 'Training_event', false, true)}">
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 START -->
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',false,true)}">
                                <th style="text-align:center">{!$ObjectType.CampaignMember__c.fields.Opportunity__c.label}</th>
                            </apex:variable>
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',true,false)}">
                               <th style="text-align:center">询问单</th>
                            </apex:variable>
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',false,true)}">
                                <th style="text-align:center">新建意向</th>
                            </apex:variable>
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 END -->
                        </apex:variable>
                         <!-- SWAG-B9J9YR 2-19-02-19 end -->
                        <th style="text-align:center">{!$ObjectType.CampaignMember__c.fields.Type__c.label}</th>
                        <th style="text-align:center">操作</th>
                    </tr>
                </table>
                <div style="width:875px;height:260px;overflow:auto;">
                <table id="linetable" class="linetable" border="1" style="border-collapse: collapse;width:850px;table-layout:fixed;">
                    <colgroup>
                        <col width="40px"/>
                        <col width="300px"/>
                        <col width="150px"/>
                        <!-- SWAG-B9J9YR 2-19-02-19 start -->
                        <apex:variable value="Training_event" var="Training_event" rendered="{!IF(cam.recordType.developerName == 'Training_event', false, true)}">
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 START -->
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',false,true)}">
                                <col width="150px" />
                            </apex:variable>
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 END -->
                                <col width="60px"/>
                        </apex:variable>
                         <!-- SWAG-B9J9YR 2-19-02-19 end -->
                        <col width="100px"/>
                        <col width="50px"/>
                    </colgroup>
                    <apex:repeat value="{!lineInfoList}" var="lineInfo" id="records">
                    <tr>
                        <td align="center">
                            <apex:outputText id="line" value="{!lineInfo.line}"></apex:outputText>
                        </td>
                        <td align="center">
                            <apex:inputField id="department" value="{!lineInfo.cm.Department__c}" onblur="vpClear2_delay({!lineInfo.line - 1});" onfocus="setVisitorPlace({!lineInfo.line - 1});" style="width:95%;"></apex:inputField>
                            <apex:inputHidden id="departmentId" value="{!lineInfo.cm.Department_ID__c}" />
                            <apex:inputHidden id="departmentHidden" value="{!lineInfo.cm.Department__c}" />
                            <apex:inputHidden id="departmentHiddenId" value="{!lineInfo.cm.Department_ID__c}" />
                        </td>
                        <td align="center">
                            <apex:inputField id="contact" value="{!lineInfo.cm.Contact__c}" onclick="openSearchContact({!lineInfo.line})" style="width: 95%"></apex:inputField>
                            <apex:inputHidden id="contactId" value="{!lineInfo.cm.Contact_ID__c}"></apex:inputHidden>
                            <apex:inputHidden id="contactSDCName" value="{!lineInfo.cm.Contact_ID__r.Strategic_dept_Class__r.Name}"></apex:inputHidden>
                        </td>
                        <!-- SWAG-B9J9YR 2-19-02-19 start -->
                         <apex:variable value="Training_event" var="Training_event" rendered="{!IF(cam.recordType.developerName == 'Training_event', false, true)}">
                            <!--JZ-20191120 学会会议和营业部会议 隐藏询价字段 START -->
                            <apex:variable value="Society" var="Society" rendered="{!IF(cam.recordType.developerName == 'Society' || cam.recordType.developerName == 'BusinessTraining',false,true)}">
                                <td align="center">
                                <apex:inputField id="opportunity" value="{!lineInfo.cm.Opportunity__c}" onfocus="setRelOppId({!lineInfo.line - 1},'opportunity','opportunityId');" onchange="resetValue('allPage:allForm:allBlock:records:{!lineInfo.line - 1}:opportunity');" style="width:95%;"></apex:inputField>
                                <apex:inputHidden id="opportunityId" value="{!lineInfo.cm.Opportunity_ID__c}" />
                                <apex:inputHidden id="opportunityHidden" value="{!lineInfo.cm.Opportunity__c}" />
                                <apex:inputHidden id="opportunityHiddenId" value="{!lineInfo.cm.Opportunity_ID__c}" />
                            </td>
                            </apex:variable>
                            <td align="center">
                                <input style="width:90%;" type="button" value="新建" onclick="openCreateLead({!lineInfo.line});"/>
                            </td>
                        </apex:variable>
                         <!-- SWAG-B9J9YR 2-19-02-19 end -->
                        <td align="center">
                            <apex:inputField id="type" value="{!lineInfo.cm.Type__c}"></apex:inputField>
                        </td>
                        <td align="center">
                            <input style="width:90%;" type="button" value="删除" onclick="deleteJs({!lineInfo.line})"/>
                        </td>
                    </tr>
                    </apex:repeat>
                </table>
                </div>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>