|
|
|
|
@ -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) => {
|
|
|
|
|
|