buli
2023-05-22 71b93327e8f3fb3bffffc7c033c1f782e7b6ab32
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
import { LightningElement, track,api } from 'lwc';
import Product_Number_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
import ONE_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
import TWO_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class InventoryEditingLWC extends LightningElement {
    // @track invRecord = {ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)};
    @track invRecords = [];
    toSaveLabel = 'Save';
 
    connectedCallback(){
        console.log('  === connectedCallback === ');
        this.inventoryTempRecords();
    }
    inventoryTempRecords(){
        console.log('===>初始化');
        this.invRecord = [];
        // for(var i=0; i < 1 ; i++){
        //     this.invRecords.push({ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)});
        // }
    }
 
    addRow(){
        // console.log('=====>进入行项目');
        // const len = this.invRecords.length;
        // this.invRecords.push({ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)});
        let objRow = {
            ProductNumber: '',
            Inventory1: '',
            Inventory2: '',
            id: ++this.keyIndex
        }
        this.invRecords = [...this.invRecords, Object.create(objRow)];
    }
    removeRow(event){
        const indexPos = event.currentTarget.name;
        let remList = [];
        remList = this.invRecords;
        remList.splice(indexPos,1);
        this.invRecords = remList;
    }
    handleClick(){
        console.log('保存');
        console.log('this.invRecords'+JSON.stringify(this.invRecords));
        this.inventoryTempRecords();
        console.log( 'Save ==> ' + JSON.stringify(toSaveList));
    }
 
    handleProductChange(event){ 
        if (event.target.name == 'productNumber') {
            this.invRecords[event.currentTarget.dataset.index].productNumber = event.target.value;
            console.log('===>invrecords'+JSON.stringify(this.invRecords));
           
        }
        else if (event.target.name == 'inventory1') {
            this.invRecords[event.currentTarget.dataset.index].inventory1 = event.target.value;
        }
        else if (event.target.name == 'inventory2') {
            this.invRecords[event.currentTarget.dataset.index].inventory2 = event.target.value;
        }
     
     
 
    //     let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
    //     console.log('=====>foundelement'+foundelement);
    //     foundelement.productNumber = event.target.value;
    //     this.invRecords = [this.invRecords];
    //     console.log(' ==>第一行' +   foundelement.productNumber);
    //     console.log(' ==>第一行' +  JSON.stringify(this.invRecords));
    // }
    // handleinv1Change(event){
    //     let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
    //     foundelement.Inventory1 = event.target.value;
    //     this.invRecords = [this.invRecords];
    //     // if( foundelement.Inventory1)
    //     console.log(' ==> 第二' +  JSON.stringify(this.invRecords));
 
    // }
 
    // handleinv2Change(event){
    //     let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
    //     foundelement.Inventory2 = event.target.value;
    //     this.invRecords = [this.invRecords];
    //     console.log(' ==>第三' +  JSON.stringify(this.invRecords));
    }
    
 
 
 
    //数字验证
isNum(num){
    var reNum =/^[0-9]+$/;
    return (reNum.test(num));
    }
    
}