feat:增加考试时选择部门

This commit is contained in:
zty 2024-05-21 17:25:49 +08:00
parent 8e6e0d4c93
commit f9cfd0f83b
8 changed files with 201 additions and 83 deletions

View File

@ -51,7 +51,6 @@ export function createCertificate(data) {
//课程
export function getCourseList(query) {
return request({

View File

@ -210,4 +210,20 @@ export function deleteExamRecord(id) {
url: `/exam/examrecord/${id}/`,
method: 'delete'
})
}
}
// 获取课程列表
export function getCourse() {
return request({
url: `/edu/course/`,
method: 'get'
})
}
// 获取当前部门下的所有部门
export function getDepartment() {
return request({
url: `/system/organization/sub/`,
method: 'get'
})
}

View File

@ -48,4 +48,12 @@ export function changePassword(data) {
method: 'put',
data
})
}
export function impData(data) {
return request({
url: '/system/userexam/imp/',
method: 'post',
data
})
}

View File

@ -53,6 +53,12 @@
<span>{{ scope.row.create_admin_username }}</span>
</template>
</el-table-column>
<el-table-column label="参加人数">
<template slot-scope="scope">{{ scope.row.user_count }}</template>
</el-table-column>
<el-table-column label="完成人数">
<template slot-scope="scope">{{ scope.row.submit_count }}</template>
</el-table-column>
<el-table-column align="center" label="操作" fixed="right">
<template slot-scope="scope">
<el-button
@ -125,6 +131,50 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item label = "出具证书">
<el-select v-model="exam.certificate" placeholder="是否出具证书" style="width:100%" clearable>
<el-option
label = ""
value = 'true'>
</el-option>
<el-option
label = ''
value= 'false'>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="课程名称" prop="course_name" v-if="exam.certificate==='true'">
<el-select v-model="exam.course_name" multiple placeholder = "请选择课程名称">
<el-option
v-for="item in courseOptions"
:key = "item.id"
:label = "item.name"
:value = "item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="考试部门" prop="participant_dep" style="width:100%" clearable>
<el-button @click="selectAll">全选部门</el-button>
<el-select v-model="exam.participant_dep" multiple placeholder = "选择部门" >
<el-option
v-for="item in depOptions"
:key = "item.id"
:label = "item.name"
:value = "item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="考试人员" prop="participant_user" style="width:100%" clearable>
<el-select v-model="exam.participant_user" multiple placeholder = "请选择人员">
<el-option
v-for="item in userOptions"
:key = "item.id"
:label = "item.name"
:value = "item.id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button>
@ -134,10 +184,12 @@
</div>
</template>
<script>
import { getPaperList,getExamList, createExam, updateExam,deleteExam} from "@/api/exam";
import { getPaperList,getExamList, createExam, updateExam,deleteExam, getCourse, getDepartment} from "@/api/exam";
import {getUserList} from "@/api/user";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination"
const defaultexam = {
id: "",
name: "",
@ -147,13 +199,17 @@
proctor_name:'',
proctor_phone:'',
chance:3,
paper:''
paper:'',
certificate:'',
course_name:[],
participant_dep:[],
participant_user:[],
};
const listQuery = {
page: 1,
limit: 20,
search: ""
}
};
export default {
components: { Pagination },
data() {
@ -163,6 +219,10 @@
id: "",
name: "",
},
// has_certificate:'true',
courseOptions:[],
depOptions:[],
userOptions:[],
listQuery:listQuery,
tableData: {count:0},
listLoading: true,
@ -186,17 +246,20 @@
mounted() {
this.getPaperOptions();
this.getList();
this.getCourseList();
this.getDepartmentList();
},
methods: {
checkPermission,
getPaperOptions(){
getPaperList({page:0}).then(res=>{
debugger;
console.log(res)
this.paperOptions = res.data
})
},
selectAll(){
this.exam.participant_dep = this.depOptions.map(option => option.id);
},
getList() {
this.listLoading = true;
debugger;
@ -205,6 +268,24 @@
this.listLoading = false;
});
},
getDepartmentList(){
getDepartment().then(response =>{
this.depOptions = response.data
return this.depOptions
})
},
getUserList(){
getUserList().then(response =>{
this.userOptions = response.data
console.log(this.userOptions)
})
},
getCourseList(){
getCourse(this.listQuery).then(response =>{
this.courseOptions = response.data.results
this.listLoading = false;
})
},
resetFilter() {
this.listQuery = {
page: 1,
@ -257,6 +338,7 @@
async confirmexam(form) {
this.$refs[form].validate(valid => {
if (valid) {
this.exam.certificate = this.exam.certificate === 'true';
const isEdit = this.dialogType === "edit";
if (isEdit) {
updateExam(this.exam.id, this.exam).then(() => {

View File

@ -267,7 +267,6 @@ export default {
handleUpSuccess(res, file, filelist) {
this.Content.file = res.data.id;
this.impForm.file = res.data.path;
},
handleRemove(file, filelist) {
this.Content.file = null;

View File

@ -76,14 +76,49 @@
icon="el-icon-refresh-left"
@click="resetFilter"
>重置</el-button>
<!-- <el-button
<el-button
class="filter-item"
style="margin-left: 10px"
type="primary"
icon="el-icon-download"
@click="exportExcel"
icon="el-icon-upload"
@click="handleImport"
:loading="listLoading"
>导出</el-button> -->
>批量导入</el-button>
<el-card style="margin-top: 10px">
<el-dialog
:visible.sync="impDialogVisible"
title="批量新增用户"
:close-on-click-modal="false"
>
<el-form
ref="Form"
label-width="80px"
label-position="right"
>
<el-form-item label="下载模板" prop="path">
<a :href="downloadUrl">点击下载模板</a>
</el-form-item>
<el-form-item label="导入文件" prop="file">
<el-upload
ref="upload"
:action="upUrl"
:on-success="handleUpSuccess"
:on-remove="handleRemove"
:on-preview="handlePreview"
:headers="upHeaders"
:file-list="fileList"
:limit="1"
accept=".doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip">
<el-button size="small" type="primary">上传文件</el-button>
</el-upload>
</el-form-item>
</el-form>
<div style="text-align: right">
<el-button type="danger" @click="close_dialog">取消</el-button>
<el-button type="primary" @click="submitUpload" :disabled="saveLoading">确认</el-button>
</div>
</el-dialog>
</el-card>
</div>
<div style="margin-top: 10px">
<el-button type="primary" icon="el-icon-plus" @click="handleAddUser"
@ -161,7 +196,6 @@
</template>
</el-table-column>
</el-table>
<pagination
v-show="userList.count > 0"
:total="userList.count"
@ -172,67 +206,6 @@
</el-card>
</el-col>
</el-row>
<el-dialog
:visible.sync="dialogVisible"
:title="dialogType === 'edit' ? '编辑用户' : '新增用户'"
>
<el-form
ref="Form"
:model="user"
label-width="80px"
label-position="right"
:rules="rule1"
>
<el-form-item label="姓名" prop="name">
<el-input v-model="user.name" placeholder="姓名" />
</el-form-item>
<el-form-item label="账户" prop="username">
<el-input v-model="user.username" placeholder="账户" />
</el-form-item>
<el-form-item label="所属部门" prop="dept">
<treeselect
v-model="user.dept"
:multiple="false"
:options="orgData"
placeholder="所属部门"
/>
</el-form-item>
<el-form-item label="角色" prop="roles">
<el-select
v-model="user.roles"
multiple
placeholder="请选择"
style="width: 100%"
>
<el-option
v-for="item in roles"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="头像" prop="dept">
<el-upload
class="avatar-uploader"
:action="upUrl"
accept="image/jpeg, image/gif, image/png, image/bmp"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
:headers="upHeaders"
>
<img v-if="user.avatar" :src="user.avatar" class="avatar" />
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
</el-form-item>
</el-form>
<div style="text-align: right">
<el-button type="danger" @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="confirm('Form')">确认</el-button>
</div>
</el-dialog>
</div>
</template>
<style>
@ -271,6 +244,7 @@ import {
import { getSubOrgList } from "@/api/org";
import { getRoleList } from "@/api/role";
import { genTree } from "@/utils";
import {impData} from "@/api/userexam";
import checkPermission from "@/utils/permission";
import { upUrl, upHeaders } from "@/api/file";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
@ -293,7 +267,11 @@ export default {
upUrl: upUrl(),
userList: { count: 0 },
roles: [],
saveLoading:false,
fileList: [],
impDialogVisible: false,
listLoading: true,
downloadUrl: process.env.VUE_APP_BASE_API,
listQuery: {
page: 1,
page_size: 20,
@ -339,6 +317,29 @@ export default {
},
methods: {
checkPermission,
submitUpload() {
this.$refs.upload.submit();
this.impDialogVisible = false;
this.saveLoading = true;
impData(this.impForm).then(res=>{
console.log(this.impForm)
if(res.code>=200){
this.saveLoading = false;
this.$message.success("提交成功");
this.getList();
}else{
this.$message.error(res.message);
this.saveLoading = false;
}
})
},
handleImport(){
this.impDialogVisible = true;
let file_url = '';
file_url = "media/default/用户表.xlsx";
let base_url = this.downloadUrl.substr(0, this.downloadUrl.length - 3);
this.downloadUrl = base_url+file_url;
},
handleAvatarSuccess(res, file) {
if (res.code >= 200) {
this.user.avatar = res.data.path;
@ -346,6 +347,26 @@ export default {
this.$message.error("头像上传失败!");
}
},
close_dialog(){
this.impDialogVisible = false;
this.fileList = [];
this.impForm.file = '';
},
handleUpSuccess(res, file, filelist) {
this.Content.file = res.data.id;
this.impForm.file = res.data.path;
},
handleRemove(file, filelist) {
this.Content.file = null;
this.impForm.file = '';
},
handlePreview(file) {
if ("url" in file) {
window.open(file.url);
} else {
window.open(file.response.data.path);
}
},
beforeAvatarUpload(file) {
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {

View File

@ -90,8 +90,8 @@ class Exam(CommonAModel):
paper = models.ForeignKey(Paper, verbose_name='使用的试卷', on_delete=models.CASCADE, null=True, blank=True)
certificate = models.BooleanField('是否生成证书', default=False)
course_name = models.ManyToManyField(Course, blank=True)
participant_dep = models.ManyToManyField(Organization, verbose_name='考试公司', related_name='exam_dep')
participant_user = models.ManyToManyField(User, verbose_name='考试人员', related_name='exam_user')
participant_dep = models.ManyToManyField(Organization, verbose_name='考试公司', related_name='exam_dep',null=True, blank=True)
participant_user = models.ManyToManyField(User, verbose_name='考试人员', related_name='exam_user', null=True, blank=True)
is_open = models.BooleanField('是否公开', default=True)
def __str__(self):

View File

@ -303,14 +303,10 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
participants_ids = [i.id for i in participants]
dep = exam.participant_dep.all()
dep_ids = [i.id for i in dep]
# print(participants_id, 'participants_id')
# print(request.user.id, request.user.dept.id, "request.user.dept")
if request.user.id in participants_ids or request.user.dept in dep_ids:
pass
else:
raise ParseError('不在考试人员范围内')
dep = exam.participant_dep.all()
print(participants, "participants")
now = timezone.now()
if now < exam.open_time or now > exam.close_time:
raise ParseError('不在考试时间范围')
@ -445,8 +441,6 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
now_data = datetime.now()
course = exam.course_name.all()
courese_ids = [i.id for i in course]
print(courese_ids, "----------course")
print("------------",request.user.dept.name)
current_date = now_data.strftime('%Y-%m-%d')
data_dict = {
'姓名': request.user.name,
@ -456,7 +450,6 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
'发证日期': current_date,
'课程列表': courese_ids,
}
print('-----------------data_dict', data_dict)
serializer = CertificateSerializer(data=data_dict)
serializer.is_valid(raise_exception=True)
serializer.save()