binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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 { api, wire,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForRequestDBButton';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class LexRequestDB extends NavigationMixin(LightningElement) {
    @api recordId;
    stageName;
    sapSendOK;
    cntLostCancelReport;
    cntLostCancelDraft;
    agency1;
    agency1Id;
    name;
    bidPlannedDate;
    salesAssistantName;
    salesAssistantID;
    profileId;
    systemProfileId;
    s1ProfileId;
    s4ProfileId;
    recordTypeId;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
 
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
        init({
            recordId: this.recordId
        }).then(result=>{
            console.log(result);
            this.stageName = result.stageName == undefined ? '' : result.stageName;
            this.sapSendOK = result.sapSendOK == undefined ? '' : result.sapSendOK;
            this.cntLostCancelReport = result.cntLostCancelReport == undefined ? '' : result.cntLostCancelReport;
            this.cntLostCancelDraft = result.cntLostCancelDraft == undefined ? '' : result.cntLostCancelDraft;
            this.agency1 = result.agency1 == undefined ? '' : result.agency1;
            this.agency1Id = result.agency1Id == undefined ? '' : result.agency1Id;
            this.name = result.name == undefined ? '' : result.name;
            this.bidPlannedDate = result.bidPlannedDate == undefined ? '' : result.bidPlannedDate.replace(/-/g, '/');;
            this.salesAssistantName = result.salesAssistantName == undefined ? '' : result.salesAssistantName;
            this.salesAssistantID = result.salesAssistantID == undefined ? '' : result.salesAssistantID;
            this.profileId = result.profileId == undefined ? '' : result.profileId;
            this.systemProfileId = result.systemProfileId == undefined ? '' : result.systemProfileId;
            this.s1ProfileId = result.s1ProfileId == undefined ? '' : result.s1ProfileId;
            this.s4ProfileId = result.s4ProfileId == undefined ? '' : result.s4ProfileId;
            this.recordTypeId = result.recordTypeId == undefined ? '' : result.recordTypeId;
            this.requestDB();
        })
    }
    requestDB(){
        var profileId = this.profileId;
        if (profileId != this.systemProfileId && profileId != this.s1ProfileId &&
        profileId != this.s4ProfileId) {
            this.showToast("您没有授权委托的权限。请联系系统管理员。","error");
        }
        // jsの場合、翻訳された値がでるので、要注意
        else if (this.stageName != '引合'
        && this.stageName != '询价'
        ) {
            this.showToast("状态1:" + this.stageName + "、不能做授权申请!","error");
        }
        else if (this.sapSendOK == '1') {
            this.showToast("已经上传SAP、不能做授权申请了!","error");
        }
        else if (this.cntLostCancelReport - this.cntLostCancelDraft > 0) {
            this.showToast("询价已经有取消/失单报告了!","error");
        }
        else {
        // location.href = '/a2C/e?retURL=%2F' + 
        //     encodeURI(this.recordId) +
        //     '&RecordType=01210000000RNXi' +
        //     '&CF00N10000006QdJz=' +
        //     encodeURI(this.agency1) +
        //     '&CF00N10000006QdJz_lkid=' +
        //     encodeURI(this.agency1Id) +
        //     '&CF00N10000006QdKn=' +
        //     encodeURI(this.name) +
        //     '&CF00N10000006QdKn_lkid=' +
        //     encodeURI(this.recordId) +
        //     '&00N10000006QdK4=' +
        //     encodeURI(this.name) +
        //     '&00N10000006QdYB=' +
        //     encodeURI(this.bidPlannedDate) +
        //     '&CF00N10000006QdZT=' +
        //     encodeURI(this.salesAssistantName) +
        //     '&CF00N10000006QdZT_lkid=' +
        //     encodeURI(this.salesAssistantID) +
        //     '';
            const defaultValues = encodeDefaultFieldValues({
                Bid_distributor__c: this.agency1Id,
                Prospect_name__c: this.recordId,
                Product_discription__c: this.name,
                Tedner_date__c: this.bidPlannedDate,
                Request_target__c: this.salesAssistantID
            });
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Request_tedner_doc__c',
                    actionName: 'new'
                },
                state: {
                    nooverride: '1',
                    defaultFieldValues: defaultValues,
                    RecordTypeId: this.recordTypeId,
                }
            });
        }
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }   
    }
    updateRecordView(recordId) {
      updateRecord({fields: { Id: recordId }});
    }
}