binxie
2023-06-16 da42e2995c00293af89c71fe5ba6e16cbb77e1b3
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
import { LightningElement, api, track } from 'lwc';
 
export default class CustomShipmentNumberComp extends LightningElement {
    @api recordId;
    @api shipmentNumber;
    @api isConinvoice;
    @api esdInvoiceProNotCount;
 
    connectedCallback() {
        console.log('shipmentNumber = ' + this.shipmentNumber);
    }
 
    shipmentNumberBlur(event) {
        debugger
        console.log('shipmentNumberBlur')
        this.shipmentNumber = event.target.value;
        if (this.isConinvoice) {
            if (this.hasDecimals(this.shipmentNumber)) {
                this.showMyToast('错误', '请输入整数', 'Error');
                this.shipmentNumber = 0;
            }else{
                if(this.esdInvoiceProNotCount < this.shipmentNumber){
                    this.showMyToast('错误', '发票数量不能超过还没发票数量!', 'Error');
                    this.shipmentNumber = 0;
                }
            }
        } else {
            //向下取整
            if (this.hasDecimals(this.shipmentNumber)) {
                this.showMyToast('错误', '请输入整数', 'Error');
                this.shipmentNumber = Math.floor(this.shipmentNumber)
            }
        }
        event.target.value = this.shipmentNumber;
        this.dispatchEvent(new CustomEvent('shipmentnumber', {
            composed: true,
            bubbles: true,
            cancelable: true,
            detail: {
                data: { shipmentnumber: this.shipmentNumber, recordId: this.recordId }
            }
        }));
    }
 
    hasDecimals(num) {
        return !Number.isInteger(Number(num));
    }
 
    showMyToast(title, message, variant) {
        this.isShowSpinner = false;
        this.showLoadingSpinner = false;
        this.showAttPop = false;
        this.filesUploaded = [];
        this.fileName = null;
        console.log('show custom message');
        var iconName = '';
        var content = '';
        if (variant.toLowerCase() == 'success') {
            iconName = 'utility:check';
        } else {
            iconName = 'utility:error';
        }
        if (message != '') {
            content = '<h2><strong>' + title + '<strong/></h2><h5>' + message + '</h5>';
        } else {
            content = '<h2><strong>' + title + '<strong/></h2>';
        }
        this.template.querySelector('c-common-toast').showToast(variant, content, iconName, 10000);
    }
}