简体   繁体   English

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

[英]Datepicker Input in Lightning Web Component

I want to any pass date value from Datepicker input of lightning web component to PostingDate variable in LWCcontroller.cls我想将来自闪电 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 public static string processCustomerRefund(List lstInvoiceLines,string bankId,boolean allocateToSalesCredit,string reference){ system.debug('start update'); CRLWC.cls @AuraEnabled public static string processCustomerRefund(List lstInvoiceLines,string bankId,boolean allocateToSalesCredit,string reference){ system.debug('开始更新'); string successMessage = 'Success';字符串 successMessage = '成功'; string responseMessage = 'Success';字符串 responseMessage = '成功'; Savepoint spTran = database.setSavePoint();保存点 spTran = database.setSavePoint(); try{ List<Sales_Invoice_Line_Item__c> lstLinesToUpdate = new List<Sales_Invoice_Line_Item__c>();尝试{ List<Sales_Invoice_Line_Item__c> lstLinesToUpdate = new List<Sales_Invoice_Line_Item__c>(); decimal amount=0;小数额=0; Id taxRate;身份证税率; Id salesinvoiceid;销售发票编号;

        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;
    
}

You need to add the new parameter postingdate to the Apex Method您需要将新参数postingdate添加到 Apex 方法

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

I'm not sure long is the correct type thought, maybe DateTime or Date, I don't remember how Salesforce handle this.我不确定 long 是正确的类型,可能是 DateTime 或 Date,我不记得 Salesforce 是如何处理这个的。 If it's long, it would be a timestamp.如果它很长,那将是一个时间戳。

Lightning input (type="date") returns a string in YYYY-MM-DD format.闪电输入 (type="date") 返回YYYY-MM-DD格式的字符串。
Here's what I did:这是我所做的:

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]));
}

You could also simply use Date as a parameter type in the apex method and that should work as well.您也可以简单地将Date用作 apex 方法中的参数类型,这也应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM