liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
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';
const event1 = new ShowToastEvent({
                    message:
                    "询价状态为:失单、取消、注残、发货、完毕、目标,不允许创建OPD计划",
                    variant : "error" ,
                    mode : 'sticky'
});
//备品智能化 2023-11-05 Add by dzk Start无报价时,新建OPD计划验证
const event2 = new ShowToastEvent({
                    message:
                    "询价未创建报价,不允许创建OPD计划",
                    variant : "error" 
});
//备品智能化 2023-11-05 Add by dzk End
//备品智能化 2023-11-05 Add by dzk 产品查询页面验证
const event3 = new ShowToastEvent({
                    message:
                    "请至少选择一个报价产品,进行OPD计划创建。",
                    variant : "error" 
});
//备品智能化 2023-11-05 Add by dzk End
import init  from '@salesforce/apex/LexNewOPDButtonOpportunityController.initNewOPDButton2';
//备品智能化 2023-11-05 Add by dzk 产品页面初始化、保存产品方法引用
import initGetQuote  from '@salesforce/apex/LexNewOPDButtonOpportunityController.initGetQuote';
import createProductTags  from '@salesforce/apex/LexNewOPDButtonOpportunityController.createProductTags';
//备品智能化 2023-11-05 Add by dzk End
export default class lexNewOPDButtonOpportunity extends NavigationMixin(LightningElement) {
@api recordId;
         IsLoading=true;
    @track showproductfalg = false;
    @api Opportunity;//当前询价
         QuoteNum;//询价中报价的数量
    //备品智能化 2023-11-05 Add by dzk Start 产品显示页面数据显示
    @track data;
    @track selectProductLine = [];
      @track columns = [{
            label: '商品名称',
            fieldName: 'ProductName',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '报价编码',
            fieldName: 'QuoteNo',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '产品代码',
            fieldName: 'ProductCode',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '产品型号',
            fieldName: 'ProductModel',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
   
    ];
      //备品智能化 2023-11-05 Add by dzk End
 
      //备品智能化 2023-11-05 Add by dzk Start 页面选中数据方法
      handleRowSelection(event) {
        const selectedRows = event.detail.selectedRows;
        this.selectProductLine = selectedRows;
        // 在这里处理选中的行数据
        console.log('选中的行数据:'+ JSON.stringify(selectedRows));    
      }
      //备品智能化 2023-11-05 Add by dzk End
 
      //备品智能化 2023-11-05 Add by dzk Start 产品页面数据初始化显示
     @wire(initGetQuote, { recordId: '$recordId' })
    wiredQuoteItems({error,data}) {
           if (data) {
            this.data = data;
        } else if (error) {
            console.log('页面初始化错误------' + JSON.stringify(error));
        }
    }
    //备品智能化 2023-11-05 Add by dzk End
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
    Promise.all([
      loadStyle(this, lwcCSS)
    ]);
        init({recordId:this.recordId}).then(res=>{
            if (res!=null) {
                console.log(res);
                //备品智能化 2023-11-05 Add by dzk Start 修改初始化方法接受收参数
                this.Opportunity=res.opp;
                this.QuoteNum=res.quoteNum;
                console.log('this.Opportunity>>>>>' + this.Opportunity);
                console.log('this.QuoteNum>>>>>' + this.QuoteNum);
                //备品智能化 2023-11-05 Add by dzk End
                this.newOPDButtonOpportunity().then(res=>{
                this.IsLoading=false;
                    // this.dispatchEvent(new CloseActionScreenEvent());        
                });    
            }
            else{
                const eventInItError = new dispatchEvent({
                    message : '页面初始化错误,请联系管理员',
                    variant : 'error' ,
                    mode : 'sticky'
                });
                this.dispatchEvent(eventInItError);
                return;
            }
 
        });
    }
 
 
    async newOPDButtonOpportunity(){
    //备品智能化 2023-11-05 Start by dzk Start 按钮点击验证追加无报价验证
        var oppstagename = this.Opportunity.StageName;
        var quotenumber = this.QuoteNum;
        if(oppstagename=='目標' || oppstagename=='完了' || oppstagename=='敗戦' || oppstagename=='削除' || oppstagename=='注残' || oppstagename=='出荷'){
            this.dispatchEvent(event1);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else if(quotenumber == 0){
            this.dispatchEvent(event2);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            this.showproductfalg = true;
        }
        //备品智能化 2023-11-05 Add by dzk End
    }
    
    //备品智能化 2023-11-05 Add by dzk Start OPD计划新建标准页面与保存按钮合并
    NewQuotationProducts(event){
        this.showproductfalg = false;
        if(this.selectProductLine.length == 0){
            this.dispatchEvent(event3);
            this.showproductfalg = true;
        }else{
            createProductTags({ records: JSON.stringify(this.selectProductLine), recordId:this.recordId }).then(result => {
                   // 处理 Apex 方法的返回结果
                console.log('Apex 方法返回的结果:', result);
            }).catch(error => {
                // 处理错误
                console.error('发生错误:', error);
            });
            //新建OPD计划数据 
            const defaultValues = encodeDefaultFieldValues({
                   Related_Opportunity1_ID__c: this.recordId,
                Account_Laboratory__c: this.Opportunity.AccountId,
                Related_Opportunity1__c : this.Opportunity.Name,
                OPDType__c : '询价',
                Name : '*',
                retURL : '%2F' + this.recordId
            });
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'OPDPlan__c',
                    actionName: 'new'
                },
                state: {
                    nooverride: '1',
                    defaultFieldValues: defaultValues,
                }
            });    
        }
    }
    
 
    openSetProduct(event){
        this.showproductfalg = false;
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    //备品智能化 2023-11-05 Add by dzk End
}