|
@@ -14,6 +14,7 @@
|
|
|
:rules="rules"
|
|
:rules="rules"
|
|
|
label-width="120px"
|
|
label-width="120px"
|
|
|
class="el-form-box"
|
|
class="el-form-box"
|
|
|
|
|
+ :disabled="isView"
|
|
|
>
|
|
>
|
|
|
<div class="section-title">资料信息</div>
|
|
<div class="section-title">资料信息</div>
|
|
|
|
|
|
|
@@ -130,7 +131,10 @@
|
|
|
class="table-form-item"
|
|
class="table-form-item"
|
|
|
label-width="0"
|
|
label-width="0"
|
|
|
>
|
|
>
|
|
|
- <fileMain v-model="scope.row.attachment" type="add" />
|
|
|
|
|
|
|
+ <fileMain
|
|
|
|
|
+ v-model="scope.row.attachment"
|
|
|
|
|
+ :type="isView ? 'view' : 'add'"
|
|
|
|
|
+ />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
@@ -150,18 +154,29 @@
|
|
|
</el-form>
|
|
</el-form>
|
|
|
|
|
|
|
|
<template v-slot:footer>
|
|
<template v-slot:footer>
|
|
|
- <el-button type="primary" @click="save()" :loading="loading"
|
|
|
|
|
|
|
+ <el-button
|
|
|
|
|
+ v-if="!isView"
|
|
|
|
|
+ type="primary"
|
|
|
|
|
+ @click="save()"
|
|
|
|
|
+ :loading="loading"
|
|
|
>保存</el-button
|
|
>保存</el-button
|
|
|
>
|
|
>
|
|
|
- <el-button @click="cancel">取消</el-button>
|
|
|
|
|
|
|
+ <el-button @click="cancel">{{ isView ? '关闭' : '取消' }}</el-button>
|
|
|
</template>
|
|
</template>
|
|
|
</ele-modal>
|
|
</ele-modal>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import DeptSelect from '@/components/CommomSelect/dept-select.vue';
|
|
import DeptSelect from '@/components/CommomSelect/dept-select.vue';
|
|
|
|
|
+ import dictMixins from '@/mixins/dictMixins';
|
|
|
|
|
+ import {
|
|
|
|
|
+ getById,
|
|
|
|
|
+ save as saveTrainingMaterial,
|
|
|
|
|
+ update as updateTrainingMaterial
|
|
|
|
|
+ } from '@/api/trainingMaterials/index.js';
|
|
|
|
|
|
|
|
const defResource = {
|
|
const defResource = {
|
|
|
|
|
+ id: '',
|
|
|
resourceName: '',
|
|
resourceName: '',
|
|
|
duration: '',
|
|
duration: '',
|
|
|
teacher: '',
|
|
teacher: '',
|
|
@@ -169,6 +184,7 @@
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const defForm = {
|
|
const defForm = {
|
|
|
|
|
+ id: '',
|
|
|
name: '',
|
|
name: '',
|
|
|
category: '',
|
|
category: '',
|
|
|
deptId: '',
|
|
deptId: '',
|
|
@@ -182,18 +198,13 @@
|
|
|
components: {
|
|
components: {
|
|
|
DeptSelect
|
|
DeptSelect
|
|
|
},
|
|
},
|
|
|
|
|
+ mixins: [dictMixins],
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
visible: false,
|
|
visible: false,
|
|
|
loading: false,
|
|
loading: false,
|
|
|
dialogType: 'add',
|
|
dialogType: 'add',
|
|
|
form: JSON.parse(JSON.stringify(defForm)),
|
|
form: JSON.parse(JSON.stringify(defForm)),
|
|
|
- categoryOptions: [
|
|
|
|
|
- { label: '安全生产', value: '1' },
|
|
|
|
|
- { label: '通用企业培训课件', value: '2' },
|
|
|
|
|
- { label: '职业健康', value: '3' },
|
|
|
|
|
- { label: '环境保护', value: '4' }
|
|
|
|
|
- ],
|
|
|
|
|
rules: {
|
|
rules: {
|
|
|
name: [
|
|
name: [
|
|
|
{ required: true, message: '请输入资料名称', trigger: 'blur' }
|
|
{ required: true, message: '请输入资料名称', trigger: 'blur' }
|
|
@@ -229,14 +240,35 @@
|
|
|
view: '查看培训资料'
|
|
view: '查看培训资料'
|
|
|
};
|
|
};
|
|
|
return titleMap[this.dialogType] || '培训资料';
|
|
return titleMap[this.dialogType] || '培训资料';
|
|
|
|
|
+ },
|
|
|
|
|
+ isView() {
|
|
|
|
|
+ return this.dialogType === 'view';
|
|
|
|
|
+ },
|
|
|
|
|
+ categoryOptions() {
|
|
|
|
|
+ return (this.dict[this.dictEnum['培训资料专业类别']] || []).map(
|
|
|
|
|
+ (item) => ({
|
|
|
|
|
+ label: item.dictValue,
|
|
|
|
|
+ value: String(item.dictCode)
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- open(row, type = 'add') {
|
|
|
|
|
|
|
+ async open(row, type = 'add') {
|
|
|
this.visible = true;
|
|
this.visible = true;
|
|
|
this.dialogType = type;
|
|
this.dialogType = type;
|
|
|
|
|
+ this.requestDict('培训资料专业类别');
|
|
|
if (row && row.id) {
|
|
if (row && row.id) {
|
|
|
- this.form = JSON.parse(JSON.stringify({ ...defForm, ...row }));
|
|
|
|
|
|
|
+ this.loading = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const detail = await getById(row.id);
|
|
|
|
|
+ this.form = this.mapDetailToForm(detail);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.$message.error(error.message || '获取培训资料失败');
|
|
|
|
|
+ this.cancel();
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ this.loading = false;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
this.form = JSON.parse(JSON.stringify(defForm));
|
|
this.form = JSON.parse(JSON.stringify(defForm));
|
|
|
}
|
|
}
|
|
@@ -252,6 +284,56 @@
|
|
|
onDeptChange(deptId, node) {
|
|
onDeptChange(deptId, node) {
|
|
|
this.form.deptName = node ? node.name : '';
|
|
this.form.deptName = node ? node.name : '';
|
|
|
},
|
|
},
|
|
|
|
|
+ attachmentToArray(attachment) {
|
|
|
|
|
+ if (Array.isArray(attachment)) return attachment;
|
|
|
|
|
+ return attachment
|
|
|
|
|
+ ? String(attachment)
|
|
|
|
|
+ .split(',')
|
|
|
|
|
+ .filter((item) => item)
|
|
|
|
|
+ : [];
|
|
|
|
|
+ },
|
|
|
|
|
+ mapDetailToForm(detail) {
|
|
|
|
|
+ const resources = (detail.trainingResourceList || []).map((item) => ({
|
|
|
|
|
+ id: item.id || '',
|
|
|
|
|
+ resourceName: item.resourceName || '',
|
|
|
|
|
+ duration: item.suggestDuration || '',
|
|
|
|
|
+ teacher: item.teacherName || '',
|
|
|
|
|
+ attachment: this.attachmentToArray(item.attachment)
|
|
|
|
|
+ }));
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: detail.id || '',
|
|
|
|
|
+ name: detail.materialName || '',
|
|
|
|
|
+ category:
|
|
|
|
|
+ detail.professionalType === undefined ||
|
|
|
|
|
+ detail.professionalType === null
|
|
|
|
|
+ ? ''
|
|
|
|
|
+ : String(detail.professionalType),
|
|
|
|
|
+ deptId: detail.departmentId || '',
|
|
|
|
|
+ deptName: detail.departmentName || '',
|
|
|
|
|
+ position: detail.applicablePositions || '',
|
|
|
|
|
+ intro: detail.description || '',
|
|
|
|
|
+ resources: resources.length ? resources : [{ ...defResource }]
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
+ buildPayload() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: this.form.id || undefined,
|
|
|
|
|
+ materialName: this.form.name,
|
|
|
|
|
+ professionalType:
|
|
|
|
|
+ this.form.category === '' ? undefined : Number(this.form.category),
|
|
|
|
|
+ departmentId: this.form.deptId,
|
|
|
|
|
+ departmentName: this.form.deptName,
|
|
|
|
|
+ applicablePositions: this.form.position,
|
|
|
|
|
+ description: this.form.intro,
|
|
|
|
|
+ trainingResourceList: this.form.resources.map((item) => ({
|
|
|
|
|
+ id: item.id || undefined,
|
|
|
|
|
+ resourceName: item.resourceName,
|
|
|
|
|
+ suggestDuration: item.duration,
|
|
|
|
|
+ teacherName: item.teacher,
|
|
|
|
|
+ attachment: (item.attachment || []).join(',')
|
|
|
|
|
+ }))
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
handleAddResource() {
|
|
handleAddResource() {
|
|
|
this.form.resources.push({ ...defResource });
|
|
this.form.resources.push({ ...defResource });
|
|
|
},
|
|
},
|
|
@@ -266,19 +348,22 @@
|
|
|
this.form.resources.splice(index, 1);
|
|
this.form.resources.splice(index, 1);
|
|
|
},
|
|
},
|
|
|
save() {
|
|
save() {
|
|
|
- this.$refs.form.validate((valid) => {
|
|
|
|
|
|
|
+ this.$refs.form.validate(async (valid) => {
|
|
|
if (valid) {
|
|
if (valid) {
|
|
|
this.loading = true;
|
|
this.loading = true;
|
|
|
- setTimeout(() => {
|
|
|
|
|
- this.loading = false;
|
|
|
|
|
- const messageMap = {
|
|
|
|
|
- add: '添加成功',
|
|
|
|
|
- edit: '编辑成功'
|
|
|
|
|
- };
|
|
|
|
|
- this.$message.success(messageMap[this.dialogType] || '保存成功');
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const request = this.form.id
|
|
|
|
|
+ ? updateTrainingMaterial
|
|
|
|
|
+ : saveTrainingMaterial;
|
|
|
|
|
+ await request(this.buildPayload());
|
|
|
|
|
+ this.$message.success(this.form.id ? '编辑成功' : '添加成功');
|
|
|
this.cancel();
|
|
this.cancel();
|
|
|
this.$emit('reload');
|
|
this.$emit('reload');
|
|
|
- }, 500);
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.$message.error(error.message || '保存失败');
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ this.loading = false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|