buli
2023-07-11 0c4796706fc9473d069b620321a54b20a119906c
force-app/main/default/lwc/customShippingUnitPriceComp/customShippingUnitPriceComp.js
@@ -1,24 +1,41 @@
import { LightningElement,api,track } from 'lwc';
import { LightningElement, api, track } from 'lwc';
export default class CustomShippingUnitPriceComp extends LightningElement {
    @api recordId;
    @api shippingUnitPrice;
    connectedCallback(){
    connectedCallback() {
        console.log('shippingUnitPrice = ' + this.shippingUnitPrice);
    }
    shipmentUnitPriceBlur(event){
        console.log('shipmentUnitPriceBlur')
    limitDecimals(event) {
        const value = parseFloat(event.target.value); // 将输入值转换为数字类型
        const roundedValue = Math.round(value * 100) / 100; // 将数字四舍五入到两位小数
        if (isNaN(value) || isNaN(roundedValue)) {
            // 如果数字无效,则清空输入框
            event.target.value = '';
        } else if (roundedValue !== value) {
            // 如果输入框的值超出了两位小数,则修改为两位小数
            event.target.value = roundedValue.toFixed(2);
        }
    }
    shipmentUnitPriceBlur(event) {
        console.log('shipmentUnitPriceBlur');
        this.shippingUnitPrice = event.target.value;
        this.dispatchEvent(new CustomEvent('shipmentunitprice', {
            composed: true,
            bubbles: true,
            cancelable: true,
            detail: {
                data: { shipmentunitprice: this.shippingUnitPrice, recordId: this.recordId }
            }
        }));
        this.dispatchEvent(
            new CustomEvent('shipmentunitprice', {
                composed: true,
                bubbles: true,
                cancelable: true,
                detail: {
                    data: {
                        shipmentunitprice: this.shippingUnitPrice,
                        recordId: this.recordId
                    }
                }
            })
        );
    }
}
}