buli
2023-05-04 50b39c4b52bf5fd61ec46ada365c51e05a16d2ae
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
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-20 15:04:03
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-28 17:33:23
 */
const columns=[
    { "label" : "失单品牌", "apiName" : "LostBrandName__c" ,"fieldType":"picklist","objectName":"PCLLostProduct__c"}, 
    { "label" : "失单对手型号", "apiName" : "LostProduct__c" ,"fieldType":"lookup","objectName":"PCLLostProduct__c"},
    { "label" : "失单数量", "apiName" : "Quantity__c","fieldType":"text","objectName":"PCLLostProduct__c" },
    { "label" : "失单对手型号(手动)", "apiName" : "LostProductMannual__c","fieldType":"text","objectName":"PCLLostProduct__c" },
    { "label" : "失单产品类别", "apiName" : "ProductClass__c","fieldType":"picklist","objectName":"PCLLostProduct__c" },
    { "label" : "失单产品区分", "apiName" : "ProductCategory__c","fieldType":"picklist","objectName":"PCLLostProduct__c" }
];
const columns2=[
    { label: '--无--', value: '' },
    { label: '无信息,跟进不及时', value: '无信息,跟进不及时' },
    { label: '价格', value: '价格' },
    { label: '医生偏好', value: '医生偏好' },
    { label: '服务不到位', value: '服务不到位' },
    { label: '行政决策', value: '行政决策' },
    { label: '竞品原有基础上增添设备', value: '竞品原有基础上增添设备' },
    { label: '渠道因素', value: '渠道因素' },
    { label: '某种产品缺失', value: '某种产品缺失' },
    { label: '采购平衡', value: '采购平衡' }
];
 
import { api, wire,track,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import save from '@salesforce/apex/lexPCLLostReportLwcController.save';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import setbrand from '@salesforce/apex/lexPCLLostReportLwcController.setBrand';
import init from '@salesforce/apex/lexPCLLostReportLwcController.init';
import multiSelectCombobox from 'c/multiSelectCombobox'
import searchBrands from '@salesforce/apex/lexPCLLostReportLwcController.searchBrands';
import getNewLostBrand from '@salesforce/apex/lexPCLLostReportLwcController.getNewLostBrand';
import getLostReport from '@salesforce/apex/lexPCLLostReportLwcController.getLostReport';
export default class LexPCLLostReportPage extends LightningElement {
 
 
    @track records;
    @api recordJson;
    @track columns=columns;
    @track columns2=columns2;
    @api reasonValue;
    oppId = '0061000001R2xjWAAR';
    lostReportId = '';
    pageStatus = 'Create';
    lostType = '失单';
    submitFlag = '';
    searchResult;
    brandsCount = [""];
    @track LostReport = {
        LostBrands: [],
        lostReport: {}
    };
    @track brandOptions = [];
    connectedCallback(){
        init({
            oppId1: this.oppId,
            lostReportId1: this.lostReportId,
            pageStatus1: this.pageStatus,
            lostType1: this.lostType,
            submitFlag1: this.submitFlag
        }).then(result=>{
            console.log(result);
            if(result.message != null){
                if(result.message == '提交成功!'){
                    this.showToast(result.message,"success");
                    this.LostReport = result.LostReport;
                    console.log(this.LostReport);
                }else{
                    console.log("211");
                    this.showToast(result.message,"error");
                    console.log("985");
                }  
            }else{
                this.LostReport = result.LostReport;
                console.log("520");
            }
            console.log('success');
            }).catch(error=>{
                console.log("error");
                console.log(error);
            });
        searchBrands().then(result=>{
            console.log(result);
            this.brandOptions = JSON.parse(result);
            console.log(this.brandOptions);
            // const div = this.template.querySelector('[data-Id="initDiv"]');
            // console.log(success);
            // div.classList.add("mynewclass");
            const multiCombobox = this.template.querySelector('c-multi-select-combobox');
            multiCombobox.refreshOptions(this.brandOptions);
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
 
    
    //失单类型
    RecordTypeOptions = [{ label: '--无--', value: '' },
                    { label: '失单', value: '失单' },
                    { label: '部分失单', value: '部分失单' }];
    @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.oppId = str;
            }
        }
    }
    getBrandLabel(index){
        return "失单品牌" + (this.LostReport.LostBrands[index].lineno + 1);
    }
    // connectedCallback(){
    //     this.initAll();
    // }
    
    
    // connectedCallback(){
    //     console.log("1");
    //     initForApex({
    //         oppId1: this.oppId,
    //         lostReportId1: this.lostReportId,
    //         pageStatus1: this.pageStatus,
    //         lostType1: this.lostType,
    //         submitFlag1: this.submitFlag
    //     }).then(()=>{
    //         console.log("2");
    //         init().then(result=>{
    //             console.log("3");
    //             console.log(result);
    //             if(result.message == '提交成功!'){
    //                 this.showToast(result.message,"success");
    //                 this.LostReport = result.LostReport;
    //             }else{
    //                 console.log("211");
    //                 this.showToast(result.message,"error");
    //                 console.log("985");
    //             }
    //         });
    //     });
    // }
    
 
    getParamValue(paramName) {
        // Use the URLSearchParams API to get the value of a query parameter
        const params = new URLSearchParams(window.location.search);
        return params.get(paramName);
    }
    saveJs() {
        save().then(result=>{
            if(result){
                this.showToast(result,"success");
                this.clearBrandMannualName();
            }
        })
    }
    addBrandJs() {
        getNewLostBrand({
            lineNo: this.LostReport.LostBrands.length
        }).then(result=>{
            this.LostReport.LostBrands.push(result);
        })
    }
    submitJS() {
        submit().then(result=>{
            if(result.get('error')){
                this.showToast(result.get('error'),"error");
            }else{
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        uri: result.get('uri'),
                        Id: result.get('Id'),
                        pageStatus: result.get('pageStatus'),
                        submitFlag: result.get('submitFlag')
                    }
                }); 
            }
        });
    }
    addProductJs(number) {
        
    }
    RemoveJs(number) {
        Remove().then(()=>{ 
        });
    }
    // add tcm 20211118 start
    searchJs(topNum, secondNum) {
        search().then(()=>{
        });
    }
    get pageStatusIsCreateOrEdit() {
        return this.pageStatus === 'Create' || this.pageStatus === 'Edit';
    }
 
    get isBrandCount2(){
        var flag = true;
        if(this.LostReport.LostBrands.length > 1){
            flag = false;
        }
        return flag;
    }
 
    deleteBrandJs(event){
        var str = event.target.name;
        this.LostReport.LostBrands.splice(str,1);
        console.log(this.LostReport);
    }
    
    // add tcm 20211118 end
    setLostTotalAmount() {
        //console.log('setLostTotalAmount start:');
        var totalAmount = this.template.querySelector('[data-id="LostTotalAmount"]');
        var totalAmountHidden = this.template.querySelector('[data-id="LostTotalAmountHidden"]');
        var brandAmountObjects = this.template.querySelectorAll('[data-id^="BrandContent:LostPriceOut"]');
        var brandCompanyObjects = this.template.querySelectorAll('[data-id^="BrandContent:Lost_By_CompanyOut"]');
        if (!!totalAmount && !!totalAmountHidden) {
            var tempLostAmount = 0.0;
            var brandCount = parseInt(this.brandCount);
            //console.log(brandCount);
 
            for (var i = 0; i < brandCount; i++) {
                var brandAmountObject = brandAmountObjects[i];
                var brandCompanyObject = brandCompanyObjects[i];
    
                if (!!brandAmountObject && !!brandCompanyObject) {
                    var brandCompanyText = brandCompanyObject.innerText;
                    var brandCompanyValue = brandCompanyObject.value;
    
                    if (!!brandCompanyText && brandCompanyText !== '--无--' && !!brandCompanyValue) {
                        var brandAmount = parseFloat(brandAmountObject.value);
                        tempLostAmount = tempLostAmount + brandAmount;
                    }
                }
            }
            totalAmount.innerHTML = toNumComma(tempLostAmount);
            totalAmountHidden.value = tempLostAmount;
        }
        //console.log('setLostTotalAmount end');
    }
    setBrandName(brandNumber) {
        setbrand().then(()=>{
            this.clearBrandMannualName();
        });
    }
    setBrandMannualName(event) {
        var set = event;
        console.log(set);
    }
   
    // 失单品牌不等于其他时,失单品牌(手动)清空并且不允许填写,失单品牌等于其他时,失单对手型号不可用  thh 2022-01-13 start
    clearBrandMannualName(value){
        if (value == '其他') {
            // this.template.querySelector('[data-id="LostProduct"]').setAttribute('disabled', true);
            this.template.querySelector('[data-id="LostProduct"]]').disabled = true;
            console.log("213");
        } else {
            console.log("5435");
            this.template.querySelector('[data-id="Lost_By_Company_Mannual"]').value = '';
            // this.template.querySelector('[data-id="Lost_By_Company_Mannual"]').setAttribute('disabled', true);
            this.template.querySelector('[data-id="Lost_By_Company_Mannual"]').disabled = true;
        }
    }
    cancel() {
        // Navigate to the specified opportunity page using the NavigationMixin
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.oppId,
                actionName: 'view'
            }
        });
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    handleStatus1Change(){
        
    }
    
}