weizong song 4 weeks ago
commit a76c9e9bd8

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

Loading…
Cancel
Save