123
chenjingwu
2024-04-11 87d90d5aa2dac8ab4a52a6ca66a5d1964653e346
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
import { api, wire,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForCancelReportButton';
import queryForCancelReportButton  from '@salesforce/apex/OpportunityLightingButtonController.queryForCancelReportButton';
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';
import queryCancelReport  from '@salesforce/apex/OpportunityLightingButtonController.queryCancelReport';
export default class LexCancelReport extends NavigationMixin(LightningElement) {
    @api recordId;
    stageName;
    sapSendOK;
    cntLostCancelReport;
    cntLostCancelDraft;
    jobCategory;
    biddingProjectNameBid;
    name;
    salesAssistantName;
    salesAssistantID;
    managerName;
    salesManagerDepartmentID;
    salesOwnerBuchang;
    salesOwnerBuchangID;
    recordTypeId;
    haveLostReport;
    IsLoading = true;
    @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.cntLostCancelDraft = result.cntLostCancelDraft == undefined ? '' : result.cntLostCancelDraft;
            this.cntLostCancelReport = result.cntLostCancelReport == undefined ? '' : result.cntLostCancelReport;
            this.jobCategory = result.jobCategory == undefined ? '' : result.jobCategory;
            this.biddingProjectNameBid = result.biddingProjectNameBid == undefined ? '' : result.biddingProjectNameBid;
            this.name = result.name == undefined ? '' : result.name;
            this.salesAssistantID = result.salesAssistantID == undefined ? '' : result.salesAssistantID;
            this.salesAssistantName = result.salesAssistantName == undefined ? '' : result.salesAssistantName;
            this.managerName = result.managerName == undefined ? '' : result.managerName;
            this.salesManagerDepartmentID = result.salesManagerDepartmentID == undefined ? '' : result.salesManagerDepartmentID;
            this.salesOwnerBuchang = result.salesOwnerBuchang == undefined ? '' : result.salesOwnerBuchang;
            this.salesOwnerBuchangID = result.salesOwnerBuchangID == undefined ? '' : result.salesOwnerBuchangID;
            this.recordTypeId = result.recordTypeId;
            queryCancelReport({
                recordId: this.recordId
            }).then(result=>{
                this.haveLostReport = result;
                this.cancelReport();
            });
            
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
    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 }});
    }
    cancelReport(){
        //XLIU-CG98L5 【委托】【评估】新需求-招标项目/询价对应流标、废标改善 start
        queryForCancelReportButton({
            recordId: this.recordId
        }).then(result=>{
            var sqlResult = result;
            // alert('测试+:'+sqlResult.size);
            //XLIU-CG98L5 【委托】【评估】新需求-招标项目/询价对应流标、废标改善 end
            // jsの場合、翻訳された値がでるので、要注意
            if (this.stageName != '引合'
            && this.stageName != '询价'
            ) {
                this.showToast("状态1:" + this.stageName + "、不能做 取消 了!","error");
                
            }
            else if (this.sapSendOK == '1') {
                this.showToast("已经上传SAP、不能做 取消 了!","error");
            }
            else if (this.haveLostReport) {
                this.showToast("询价已经有 取消/失单报告 了!","error");
            }
            else if (this.jobCategory == '支援') {
                this.showToast("询价所有人是助理的,先请修改到销售担当!","error");
            }
            //XLIU-CG98L5 【委托】【评估】新需求-招标项目/询价对应流标、废标改善 start
            //else if({!NOT(ISBLANK(Opportunity.Bidding_Project_Name_Bid__c))}&& '{!Opportunity.subInfoType__c}' != '3-1:废标公告' &&'{!Opportunity.subInfoType__c}' != '3-2:流标公告'){
            else if(this.biddingProjectNameBid != '' && sqlResult.length == 0){
                this.showToast("有招投标项目时只能做失单或部分失单报告!","error");
            }
            //XLIU-CG98L5 【委托】【评估】新需求-招标项目/询价对应流标、废标改善 end
            else {
                const defaultValues = encodeDefaultFieldValues({
                    Opportunity__c: this.recordId, // 关联主记录 ID
                    Sales_assistant__c: this.salesAssistantID,
                    Manager_sales__c: this.salesManagerDepartmentID,
                    Buchang_sales__c: this.salesOwnerBuchangID
                });
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'Lost_cancel_report__c',
                        actionName: 'new'
                    },
                    state: {
                        nooverride: '1',
                        defaultFieldValues: defaultValues,
                        recordTypeId: this.recordTypeId,
                    }
                });
        }
        this.dispatchEvent(new CloseActionScreenEvent());
        });  
    }
}