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 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)});
|
}
|
removeRow(event){
|
const indexPos = event.currentTarget.name;
|
let remList = [];
|
remList = this.invRecords;
|
remList.splice(indexPos,1);
|
this.invRecords = remList;
|
}
|
handleClick(){
|
console.log('保存');
|
this.toSaveLabel = 'Saving...'
|
let toSaveList = this.invRecords.slice(0);;
|
toSaveList.forEach((element, index) => {
|
console.log( index + ' ==> ' + JSON.stringify(element.Name));
|
let eleType = typeof element.Name;
|
console.log( 'typeof ==> ' + eleType);
|
if(element.Name === '' || eleType=='object'){
|
toSaveList.splice(index);
|
}
|
});
|
// refreshApex(this.invRecord);
|
|
this.inventoryTempRecords();
|
console.log( 'Save ==> ' + JSON.stringify(toSaveList));
|
}
|
|
handleProductChange(event){
|
|
let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
|
console.log('=====>foundelement'+foundelement);
|
foundelement.productNumber = event.target.value;
|
this.accRecords = [this.accRecords];
|
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.accRecords = [this.accRecords];
|
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.accRecords = [this.accRecords];
|
console.log(' ==>第三' + JSON.stringify(this.invRecords));
|
}
|
|
}
|