buli
2023-07-14 744f42c5496e656a1f9927740a3b37c0b97a6cba
force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js
@@ -77,6 +77,9 @@
        };
        reader.readAsDataURL(file);
    },
    isNumber: function(str) {
        return /^\d+$/.test(str);
    },
    saveRecords: function (component, event, helper) {
        component.set('v.login', true);
        var action = component.get("c.processData");
@@ -101,34 +104,44 @@
                        res1 += ress[i].substr(7) + '\n';
                        if (ress[i] != '') {
                            let errorData = {}
                            if(!this.isNumber(ress[i].substr(7).substring(1, 2))){
                                continue
                            }
                            let index = errorDataRow.indexOf(ress[i].substr(7).substring(1, 2));
                            if (index == -1) {
                                errorData.errorRow = ress[i].substr(7).substring(1, 2);
                                errorDataRow.push(errorData.errorRow);
                                errorData.errorInfo = ress[i].substr(7).substring(6);
                                errorData.errorInfo = ress[i].substr(7).substring(5);
                                errorDatas.push(errorData);
                            } else {
                                errorDatas[index].errorInfo += '; ' + ress[i].substr(7).substring(6);
                                errorDatas[index].errorInfo += '; ' + ress[i].substr(7).substring(5);
                            }
                        }
                    }
                    var fileContentData = component.get("v.fileContentData").split('\n');
                    let errorColumns = [
                        { label: '错误行', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 50 },
                        { label: '错误行', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 100 },
                        { label: '错误信息', fieldName: 'errorInfo', type: 'text', hideDefaultActions: true,initialWidth: 300,wrapText: true }
                    ];
                    for (var i = 0; i < fileContentData[0].split(',').length - 1; i++) {
                        errorColumns.push({
                            label: fileContentData[0].split(',')[i], fieldName: 'field' + i, type: 'text', hideDefaultActions: true,wrapText: true
                            label: fileContentData[0].split(',')[i],
                            fieldName: 'field' + i,
                            type: 'text',
                            hideDefaultActions: true,
                            wrapText: true,
                            initialWidth: 120
                        });
                    }
                    
                    for(var i = 0; i < errorDatas.length; i++){
                        let data = fileContentData[errorDatas[i].errorRow];
                        console.log('data = ' + JSON.stringify(data));
                        for(var j = 0; j < data.split(',').length; j++){
                            let label = 'field' + j;
                            errorDatas[i][label] = data.split(',')[j];
                        if(data){
                            for(var j = 0; j < data.split(',').length; j++){
                                let label = 'field' + j;
                                errorDatas[i][label] = data.split(',')[j];
                            }
                        }
                    }
                    console.log('errorDatas = ' + JSON.stringify(errorDatas))
@@ -142,12 +155,14 @@
                    component.set('v.errorMessage', res1 + "请修改后重新上传");
                    this.showErrorToast(component);
                    component.set('v.login', false);
                    component.find('save_con').set('v.disabled', true);
                } else {
                    // this.success('导入成功');
                    component.set('v.successMessage', '导入成功');
                    this.showSuccessToast01(component);
                    component.set("v.showMain", true);
                    component.set('v.login', false);
                    component.find('save_con').set('v.disabled', false);
                }
            }
            else if (state === "INCOMPLETE") {
@@ -195,7 +210,7 @@
        window.setTimeout($A.getCallback(function () {
            $A.util.addClass(component.find('errorDiv'), 'slds-hide');
        }),
            4000
            7000
        );
    },
    success: function (message) {
@@ -283,8 +298,9 @@
    downloadCSV: function (component, csv) {
        var link = document.createElement('a');
        // 设置字符集和文件头
        let bom = "\uFEFF";
        link.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(bom+csv);
        var bom = "\uFEFF";
        link.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(bom + csv);
        //link.href = URL.createObjectURL(csvFile);
        link.download = 'data.csv';
        document.body.appendChild(link);
        link.click();