Lightning Web组件中的日期选择器输入



我想将闪电web组件的Datepicker输入中的任何日期值传递到LWCcontroller.cls 中的PostingDate变量

import { LightningElement,api ,track} from 'lwc';
import getInvoiceData from '@salesforce/apex/CustomerRefundLwcController.getInvoiceData';
import getBankAccounts from '@salesforce/apex/CustomerRefundLwcController.getBankAccounts';
import processCustomerRefund from '@salesforce/apex/CustomerRefundLwcController.processCustomerRefund';
export default class CustomerRefund extends LightningElement {
@api recordId; /*Sales Credit Id*/
@track invoiceData;
@track invoiceLinesData;
@api headerText;
@api recordProcessing;
@api bankAccounts = new Array();
@track selectedBankId;
@track allocateToSalesCredit;
@track referenceDetail;
@track bShowModal = false;
@track PostingDate;
/*Toast Event Variables*/
@api isError = false;
@api iswarning = false;
@api issuccess = false;
@api ToastMessage;
PostingDateChange(event)
{
this.PostingDate = event.target.value;
this.invoiceData.PostingDate = this.PostingDate;
}

processRefundHandler() {
this.recordProcessing = true;
//console.log('this.formData----'+JSON.stringify(this.invoiceLinesData));
console.log('this.formData----'+JSON.stringify(this.invoiceData));
processCustomerRefund({ lstInvoiceLines : this.invoiceLinesData, bankId : this.selectedBankId, allocateToSalesCredit : this.allocateToSalesCredit, reference : this.referenceDetail, postingdate : this.PostingDate })
.then(result => {
var responseMessage = result;
this.recordProcessing = false;

this.ToastMessage = responseMessage;
if(responseMessage == "Success"){
//this.issuccess = true;
this.isError = false;
this.ToastMessage = "Your Bank Customer Refund has been created";
this.bShowModal = true;
}else{
this.isError = true;
}
})
.catch(error => {
this.isError = true;
this.ToastMessage = error ;
console.log(error);
});
}
<div class="slds-col"> 

<label class="slds-form-element__label slds-no-flex">Posting Date</label>
<lightning-input type="date" 
name="Postingdate" 
value={PostingDate}
onchange={PostingDateChange}
>
</lightning-input>  

</div>

CRLWC.cls@AuraEnabled公共静态字符串processCustomerRefund(列出lstInvoiceLines,字符串bankId,布尔分配ToSalesCredit,字符串引用({system.debug("启动更新"(;string successMessage="成功";string responseMessage="成功";Savepoint spTran=数据库.setSavePoint((;尝试{列表<销售_语音_线路_项目__c>lstLinesToUpdate=新列表<销售_语音_线路_项目__c>((;小数位数=0;Id taxRate;Id saleinvoiceid;

boolean isValid = true;
boolean allocateToInvoice = allocateToSalesCredit;
map<id,Sales_Invoice_Line_Item__c> mapOfSelectedLines = new map<id,Sales_Invoice_Line_Item__c>();
for(ScLineWrapper lineWrapper : lstInvoiceLines){
system.debug('isselect>> ' + lineWrapper.isSelected);
if(lineWrapper.isSelected){
salesinvoiceid = lineWrapper.InvoiceLine.Sales_Invoice__c;
decimal lineAmount = lineWrapper.InvoiceLine.Foreign_Gross__c;
if(lineAmount != null && lineAmount > 0){
amount += lineAmount;
mapOfSelectedLines.put(lineWrapper.InvoiceLine.id,lineWrapper.InvoiceLine);
}
if(lineWrapper.InvoiceLine.Tax_Rate__c != null){
taxRate = lineWrapper.InvoiceLine.Tax_Rate__c;
}
}
}
if(salesinvoiceid == null){
isValid = false;
responseMessage = 'Please select at least one sales invoice line';
}else if(bankId == null){
isValid = false;
responseMessage = 'Please select bank account';
}else if(amount <= 0){
isValid = false;
responseMessage = 'Refund amount should be greater than zero';
}
system.debug('updatelst>> ' + lstLinesToUpdate);
//update lstLinesToUpdate;
if(isValid){
Sales_Invoice__c siInfo = [select id,Status__c,Account__c,Name from Sales_Invoice__c where id=: salesinvoiceid];
BankCustomerRefundService objCustomerRefundService = new BankCustomerRefundService();
BankCustomerRefundService.BankCustomerRefundWrapper objRefundWrapper = new BankCustomerRefundService.BankCustomerRefundWrapper();
Id accountId = siInfo.Account__c;
objRefundWrapper.AccountId = accountId;
objRefundWrapper.PostingDate = Date.Today()+(-216);
objRefundWrapper.BankAccountId = bankId;
objRefundWrapper.TaxRate = taxRate;
objRefundWrapper.Amount = amount;
objRefundWrapper.Reference = reference;
BankCustomerRefundService.Response objResponse = objCustomerRefundService.CreateBankCustomerRefund(objRefundWrapper);
responseMessage = objResponse.ResponseMessage;
if(allocateToInvoice && responseMessage == successMessage){
Bank_Payment__c objBankPayment = objResponse.BankPayments.get(accountId);
List<Ledger__c> listofLedgers = [Select id,name,Foreign_Gross_Total__c,Type__c
FROM Ledger__c
Where Customer_Supplier_Account_Name__c =: accountId AND Show_On_Transaction__c=1
AND Paid__c = 'N' AND Is_Deleted__c = false
AND (Sales_Invoice_Line_Item__c IN: mapOfSelectedLines.keyset() OR Bank_Payment__c =: objBankPayment.id) ];

if(!listofLedgers.isEmpty()){
BankAllocateCreditsAndPaymentsService objAllocateCreditsAndPaymentService = new BankAllocateCreditsAndPaymentsService();
BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsWrapper objAllocateCreditWrapper = new BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsWrapper();
objAllocateCreditWrapper.AccountId = accountId;
objAllocateCreditWrapper.PostingDate = Date.Today()+(-216);
List<BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsLineWrapper> BankAllocateCreditsAndPaymentsLines = new List<BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsLineWrapper>();
for(Ledger__c ledger : listofLedgers){
BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsLineWrapper objPaymentLine = new BankAllocateCreditsAndPaymentsService.BankAllocateCreditsAndPaymentsLineWrapper();
objPaymentLine.LedgerName = ledger.Name;
objPaymentLine.Amount = ledger.Foreign_Gross_Total__c;
BankAllocateCreditsAndPaymentsLines.add(objPaymentLine);
}
objAllocateCreditWrapper.BankAllocateLines = BankAllocateCreditsAndPaymentsLines;
BankAllocateCreditsAndPaymentsService.Response objAllocateResponse = objAllocateCreditsAndPaymentService.BankAllocateCustomerBalance(objAllocateCreditWrapper);
responseMessage = objAllocateResponse.ResponseMessage;
system.debug('Response>>' + objAllocateResponse.ResponseMessage);
}                                                    
}

}
}catch(Exception ex){
responseMessage = ex.getStackTraceString();
}

if(responseMessage != successMessage){
Database.rollback(spTran);
}
system.debug('Response>>' + responseMessage);
return responseMessage;

}

您需要将新参数postingdate添加到Apex方法

@AuraEnabled 
public static string processCustomerRefund (
List lstInvoiceLines,
String bankId,
Boolean allocateToSalesCredit,
String reference,
Long postingdate
) { 

我不确定long是正确的类型,可能是DateTime或Date,我不记得Salesforce是如何处理的。如果它很长,它将是一个时间戳。

Lightning输入(type="date"返回YYYY-MM-DD格式的字符串
以下是我所做的:

public static Date convertDate(String datestr){
List<String> dateSplit = datestr.split('-');
return Date.newInstance(Integer.valueOf(dateSplit[0]), Integer.valueOf(dateSplit[1]), Integer.valueOf(dateSplit[2]));
}

您也可以简单地在apex方法中使用Date作为参数类型,这也应该有效。

最新更新