buli
2022-05-09 0953b3b5fcf19c627c6479a6b86648df653c40db
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
<apex:page standardController="Opportunity" showHeader="false" sidebar="false">
    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
    <apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
    <script type="text/javascript">
        var is_new = '{!Opportunity.IsNew__c}' == 'true';
        var approval_status = '{!Opportunity.ApprovalStatus_D__c}';
        var productSegment = '{!Opportunity.ProductSegment__c}';
        var recordTypeId = '{!Opportunity.RecordTypeId}';
        
        if (productSegment == 'BS' || productSegment == 'IE' || productSegment == 'RVI' || recordTypeId.substring(0,15) == '01228000000NJt5') {
            if (approval_status == 'Pass' && '{!Opportunity.DealerSelectOwner__c}' != '{!Opportunity.OwnerId}') {
                var oid = "{!Opportunity.Id}"; 
                var uid = "{!Opportunity.OwnerId}"; 
                
                var rac = new sforce.SObject("Opportunity"); 
                rac.Id = "{!Opportunity.Id}"; 
                rac.OwnerId = '{!Opportunity.DealerSelectOwner__c}';
                var result = sforce.connection.update([rac]); 
                var messages = getConnectDMLErrorMessages(result); 
                if (messages.length > 0) { 
                    alert(messages.join("\n")); 
                } else {
                    var rs = sforce.apex.execute("OpportunityWebService", "UpdateShare", {opportunityId: oid, userId: uid});
                    if (rs == '1') {
                        window.top.location.reload();
                    } else {
                        alert(rs);
                    }
                }
            }
        } else {
            var now_status = '{!Opportunity.Amount_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Budget_Amount_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Cancel_Reason_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Cancel_reason_IsChangedc__c}' == 'true' || 
                                '{!Opportunity.CloseDate_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Company_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product2_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product3_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product4_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product5_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product6_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product7_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product8_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code2_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code3_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code4_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code5_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code6_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code7_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Competitor_Product_Code8_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Dealer_Sales_Staff_Name_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Dealer_Service_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Expected_delivery_date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Expected_Order_Date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Inquiry_result_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Inquiry_result_cancel_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Inquiry_result_lost_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Inquiry_result_order_IsChanged__c}' == 'true' || 
                                '{!Opportunity.LeadSource_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Lost_competitor_product_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Lost_Reason_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Lost_reason_IsChangedc__c}' == 'true' || 
                                '{!Opportunity.New_Inquiry_Date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Phase1Date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Phase2Date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Phase3Date_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Sales_Channel_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Sub_Dealer_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Trade_Type_IsChanged__c}' == 'true' || 
                                '{!Opportunity.Sub_Dealer_IsChanged__c}' == 'true';
            if ((is_new || now_status) && approval_status != 'Submit') {
                //alert("新建或修改询价信息后,请及时提交审批。");
            }
        }
        var syncquo = '{!Opportunity.SyncedQuote_No__c}';
        var uploadquo = '{!Opportunity.the_Upload_of_quotation_number__c}';
        if (uploadquo != '' && uploadquo != syncquo) {
            alert("同步的报价和最近上传的报价不一致,请上传当前同步的报价。");
        }
 
 
function getConnectDMLErrorMessages(results) { 
var messages = [], 
i = 0, 
len = results.length, 
r; 
for (; i < len; i++) { 
r = results[i]; 
if (! r.getBoolean("success")) { 
messages = messages.concat(getConnectDMLMessagesOfAResult(r)); 
return messages; 
}; 
function getConnectDMLMessagesOfAResult(res) { 
var messages = [], 
errors = res.getArray("errors"), 
i = 0, 
len = errors.length, 
e; 
for (; i < len; i++) { 
e = errors[i]; 
messages.push(e.message + " " + getConnectDMLErrorFields(e)); 
return messages; 
}; 
function getConnectDMLErrorFields(error) { 
var fields = error.getArray('fields'); 
if (fields.length > 0) { 
return "[" + fields.join(",") + "]" 
} else { 
return ""; 
}; 
    </script>
</apex:page>