buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-27 11:15:23
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-05-08 11:39:23
 */
import { LightningElement, track,wire, api } from 'lwc';
import getPickList from '@salesforce/apex/lexPCLLostReportLwcController.getPickList';
import searchBrands from '@salesforce/apex/lexPCLLostReportLwcController.searchBrands';
export default class LexInputPickListCell extends LightningElement {
    @track options=[];
    @api value;
    @api record;
    @api field;
    @api fieldType;
    @api objectName;
    @api readOnly;
    @api required;
    value1;
    label;
    connectedCallback() {
        this.value1 = this.record[this.field];
        this.label = this.field;
        if(this.objectName!==undefined && this.isPickList)
        {
            if(this.label!= 'LostBrandName__c'){
                this.getPicklist(this.objectName,this.field);
            }else{
                this.getSearchBrands();
            }
        }
    }
    get isRequired(){
        return this.required;
    }
    getSearchBrands(){
        searchBrands().then(result=>{
            this.options = JSON.parse(result);
        });
    }
    
    getPicklist(obj,field)
    {
        getPickList({ objectName : obj, fieldName :field})
        .then(result => {
           if(result)
           {
                for(let i=0; i<result.length; i++) {
                    console.log('id=' + result[i]);
                    this.options = [...this.options ,{value: result[i] , label: result[i]}];                                   
                }     
                this.error = undefined;
            }
        })
        .catch(error => {
            this.message = undefined;
            this.error = error;
        });
    }
    handleChange(event) {
        this.value = event.target.value; 
    }
    get isPickList() {
        if(this.fieldType)
        {
            return this.fieldType.toLowerCase()=='picklist';
        }
        return false;
    }
    get isReadOnly(){
        if(this.readOnly == true){
            return true;
        }else{
            return false;
        }
    }
    
    @api
    inputValue() {
        return { value : this.value, field: this.field };
    }
}