weizong song 6 days ago
commit a76c9e9bd8

@ -35,8 +35,8 @@
size="small"
@click="handleSelectAll"
style="margin-left: 10px;"
:disabled="editableCount === 0">
{{ isAllSelected ? '取消全选' : '全选可编辑' }}
:disabled="tableList.length === 0">
{{ isAllSelected ? '取消全选' : '全选' }}
</el-button>
</div>
<el-table
@ -50,8 +50,7 @@
<el-table-column
type="selection"
width="55"
align="center"
:selectable="checkSelectable">
align="center">
</el-table-column>
<el-table-column type="index" label="序号" width="60" align="center"></el-table-column>
<el-table-column prop="type" label="类型" width="180" align="center">
@ -62,7 +61,6 @@
clearable
size="small"
style="width: 100%;"
:disabled="scope.row.course_id !== null && scope.row.course_id !== undefined"
@change="handleTypeChange(scope.row)">
<el-option label="元禾员工参与" :value="1"></el-option>
<el-option label="干部培训" :value="2"></el-option>
@ -162,6 +160,7 @@
style="margin-bottom: 20px;">
<div slot="title">
<div>提示若不填写则保留原值</div>
<div style="margin-top: 5px;">类型会应用到全部选中行已匹配系统课程的行不会改课程名称和日期</div>
<div style="margin-top: 5px;">将应用到选中的数据 {{ selectedRows.length }} </div>
</div>
</el-alert>
@ -259,23 +258,8 @@ export default {
};
},
computed: {
//
editableCount() {
return this.tableList.filter(item =>
item.course_id === null || item.course_id === undefined
).length;
},
//
editableRows() {
return this.tableList.filter(item =>
item.course_id === null || item.course_id === undefined
);
},
//
isAllSelected() {
return this.editableRows.length > 0 &&
this.selectedRows.length === this.editableRows.length &&
this.editableRows.every(row => this.selectedRows.includes(row));
return this.tableList.length > 0 && this.selectedRows.length === this.tableList.length;
}
},
methods: {
@ -296,25 +280,20 @@ export default {
row.type_name = '';
}
},
//
checkSelectable(row) {
return row.course_id === null || row.course_id === undefined;
isCourseLocked(row) {
return row.course_id !== null && row.course_id !== undefined;
},
//
handleSelectionChange(selection) {
this.selectedRows = selection;
},
// /
handleSelectAll() {
if (this.isAllSelected) {
//
this.$refs.table.clearSelection();
} else {
//
this.editableRows.forEach(row => {
this.$refs.table.toggleRowSelection(row, true);
});
return;
}
this.tableList.forEach(row => {
this.$refs.table.toggleRowSelection(row, true);
});
},
//
showBatchEditDialog() {
@ -338,89 +317,65 @@ export default {
};
this.batchEditDialogVisible = true;
},
//
applyBatchEdit() {
// 使
const editableRows = this.selectedRows.filter(item =>
item.course_id === null || item.course_id === undefined
);
if (editableRows.length === 0) {
if (this.selectedRows.length === 0) {
this.$message({
message: '选中的数据中没有可编辑的数据',
message: '请先选择要批量编辑的数据',
type: 'warning'
});
return;
}
let updateCount = 0;
//
editableRows.forEach(row => {
this.selectedRows.forEach(row => {
let hasUpdate = false;
// null undefined
const locked = this.isCourseLocked(row);
if (this.batchEditForm.type !== null && this.batchEditForm.type !== undefined) {
row.type = this.batchEditForm.type;
// type_name
if (row.type === 1) {
row.type_name = '元禾员工参与';
} else if (row.type === 2) {
row.type_name = '干部培训';
} else {
row.type_name = '';
}
hasUpdate = true;
}
// trim
if (this.batchEditForm.course_name !== null &&
this.batchEditForm.course_name !== undefined &&
String(this.batchEditForm.course_name).trim() !== '') {
row.course_name = String(this.batchEditForm.course_name).trim();
hasUpdate = true;
}
//
if (this.batchEditForm.start_date !== null &&
this.batchEditForm.start_date !== undefined &&
String(this.batchEditForm.start_date).trim() !== '') {
row.start_date = String(this.batchEditForm.start_date).trim();
hasUpdate = true;
}
//
if (this.batchEditForm.end_date !== null &&
this.batchEditForm.end_date !== undefined &&
String(this.batchEditForm.end_date).trim() !== '') {
row.end_date = String(this.batchEditForm.end_date).trim();
this.handleTypeChange(row);
hasUpdate = true;
}
// trim
if (this.batchEditForm.company_name !== null &&
this.batchEditForm.company_name !== undefined &&
String(this.batchEditForm.company_name).trim() !== '') {
row.company_name = String(this.batchEditForm.company_name).trim();
hasUpdate = true;
}
// trim
if (this.batchEditForm.name !== null &&
this.batchEditForm.name !== undefined &&
String(this.batchEditForm.name).trim() !== '') {
row.name = String(this.batchEditForm.name).trim();
hasUpdate = true;
}
// trim
if (this.batchEditForm.department !== null &&
this.batchEditForm.department !== undefined &&
String(this.batchEditForm.department).trim() !== '') {
row.department = String(this.batchEditForm.department).trim();
hasUpdate = true;
if (!locked) {
if (this.batchEditForm.course_name !== null &&
this.batchEditForm.course_name !== undefined &&
String(this.batchEditForm.course_name).trim() !== '') {
row.course_name = String(this.batchEditForm.course_name).trim();
hasUpdate = true;
}
if (this.batchEditForm.start_date !== null &&
this.batchEditForm.start_date !== undefined &&
String(this.batchEditForm.start_date).trim() !== '') {
row.start_date = String(this.batchEditForm.start_date).trim();
hasUpdate = true;
}
if (this.batchEditForm.end_date !== null &&
this.batchEditForm.end_date !== undefined &&
String(this.batchEditForm.end_date).trim() !== '') {
row.end_date = String(this.batchEditForm.end_date).trim();
hasUpdate = true;
}
if (this.batchEditForm.company_name !== null &&
this.batchEditForm.company_name !== undefined &&
String(this.batchEditForm.company_name).trim() !== '') {
row.company_name = String(this.batchEditForm.company_name).trim();
hasUpdate = true;
}
if (this.batchEditForm.name !== null &&
this.batchEditForm.name !== undefined &&
String(this.batchEditForm.name).trim() !== '') {
row.name = String(this.batchEditForm.name).trim();
hasUpdate = true;
}
if (this.batchEditForm.department !== null &&
this.batchEditForm.department !== undefined &&
String(this.batchEditForm.department).trim() !== '') {
row.department = String(this.batchEditForm.department).trim();
hasUpdate = true;
}
}
if (hasUpdate) {
updateCount++;
}
@ -433,15 +388,42 @@ export default {
this.batchEditDialogVisible = false;
},
normalizePreviewRow(item) {
const typeMap = {
'元禾员工参与': 1,
'元和员工参与': 1,
'员工参与数': 1,
'员工参与': 1,
'1': 1,
'干部培训': 2,
'干部培训数': 2,
'2': 2
};
const typeNameMap = {
1: '元禾员工参与',
2: '干部培训'
};
const newItem = { ...item };
let typeValue = newItem.type;
if (typeof typeValue === 'string') {
typeValue = typeMap[typeValue.trim()] ?? null;
} else if (typeValue === 1 || typeValue === 2 || typeValue === '1' || typeValue === '2') {
typeValue = Number(typeValue);
} else if (typeValue != null && typeValue !== '') {
const numeric = Number(typeValue);
typeValue = numeric === 1 || numeric === 2 ? numeric : null;
} else {
typeValue = null;
}
newItem.type = typeValue;
newItem.type_name = typeNameMap[typeValue] || '';
return newItem;
},
//
exportExcel() {
const headers = ['类型', '课程名称', '公司名称', '姓名', '部门'];
const tipRow = ['类型请填入元禾员工参与或干部培训,如参与的是系统内课程,请确保课程名称与系统内课程名称一致', '', '', '', ''];
const data = [
headers,
tipRow
];
//
const data = [headers];
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
@ -489,35 +471,7 @@ export default {
dataList = res.data;
}
// type_name
dataList = dataList.map(item => {
const newItem = { ...item }; //
//
let typeValue = newItem.type;
if (typeof typeValue === 'string') {
if (typeValue === '元禾员工参与' || typeValue === '1') {
typeValue = 1;
newItem.type_name = '元禾员工参与';
} else if (typeValue === '干部培训' || typeValue === '2') {
typeValue = 2;
newItem.type_name = '干部培训';
} else {
typeValue = null;
newItem.type_name = '';
}
} else if (typeValue === 1) {
newItem.type_name = '元禾员工参与';
} else if (typeValue === 2) {
newItem.type_name = '干部培训';
} else if (!newItem.type_name) {
newItem.type_name = '';
}
newItem.type = typeValue;
return newItem;
});
dataList = dataList.map(item => this.normalizePreviewRow(item));
// course_id null
dataList.sort((a, b) => {

Loading…
Cancel
Save