rt-sim-training-client/src/views/organization/classManage/bindLessons.vue
2021-03-25 14:09:03 +08:00

101 lines
3.2 KiB
Vue

<template>
<el-dialog v-dialogDrag title="班级排课" :visible.sync="dialogShow" width="400px" :before-close="doClose">
<el-form ref="form" :model="classModel" :rules="rules" label-width="120px" size="mini">
<el-form-item label="班级名称:" prop="name">
<el-input v-model="classModel.name" style="width: 220px;" :disabled="true" />
</el-form-item>
<el-form-item label="安排课程:" prop="lessonIds">
<el-select v-model="classModel.lessonIds" multiple placeholder="请选择">
<el-option
v-for="item in lessonList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogShow = false">{{ $t('global.cancel') }}</el-button>
<el-button type="primary" :loading="loading" @click="create">{{ $t('global.confirm') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { getLessonProjectListNoPage } from '@/api/jmap/lesson';
import { getClassAssociatedLessons, setClassAssociatedLessons } from '@/api/company';
export default {
name: 'CreateClass',
data() {
return {
dialogShow: false,
loading: false,
lessonList: [],
classModel: {
id: '',
name: '',
lessonIds: []
}
};
},
computed: {
rules() {
const baseRules = {
name: [
{ required: true, message: '请输入班级名称', trigger: 'blur' }
],
lessonIds: [
{ required: true, message: '请选择安排课程', trigger: 'change' }
]
};
return baseRules;
}
},
methods: {
async doShow(row) {
try {
this.lessonList = [];
const resp = await getLessonProjectListNoPage();
this.lessonList = resp.data;
const rest = await getClassAssociatedLessons(row.id);
this.classModel.id = row.id;
this.classModel.name = row.name;
this.classModel.lessonIds = [];
rest.data && rest.data.forEach(item => {
this.classModel.lessonIds.push(item.id);
});
this.dialogShow = true;
} catch {
this.$message.error('获取课程列表或班级数据异常!');
}
},
create() {
this.$refs.form.validate((valid) => {
if (valid) {
setClassAssociatedLessons( this.classModel.id, this.classModel.lessonIds).then(response => {
this.doClose();
this.$message.success('班级排课成功!');
}).catch(() => {
this.$message.error('班级排课失败!');
});
}
});
},
doClose() {
this.$refs.form.resetFields();
this.dialogShow = false;
}
}
};
</script>
<style>
.option-group {
margin: 10px 100px;
}
</style>