1
This commit is contained in:
@@ -104,11 +104,29 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="校门" prop="schoolDoor">
|
||||
<el-select
|
||||
v-model="form.schoolDoor"
|
||||
placeholder="请选择校门"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in schoolDoorList"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24" class="mb20">
|
||||
<el-form-item label="请假事由" prop="reason">
|
||||
<el-input
|
||||
v-model="form.reason"
|
||||
type="textarea"
|
||||
<el-input
|
||||
v-model="form.reason"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入请假事由" />
|
||||
</el-form-item>
|
||||
@@ -139,8 +157,9 @@ import { ref, reactive, nextTick, onMounted } from 'vue'
|
||||
import { useMessage } from '/@/hooks/message'
|
||||
import { addObj } from '/@/api/stuwork/stutemleaveapply'
|
||||
import { getDeptListByLevelTwo } from '/@/api/basic/basicdept'
|
||||
import { list as getClassList } from '/@/api/basic/basicclass'
|
||||
import { queryStudentListByClass } from '/@/api/basic/basicstudent'
|
||||
import { getClassListByRole } from '/@/api/basic/basicclass'
|
||||
import { queryStudentListByClass, queryAllStudentByClassCode } from '/@/api/basic/basicstudent'
|
||||
import { listAll as getSchoolDoorList } from '/@/api/safety/clouddeviceposition'
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
@@ -149,8 +168,10 @@ const dataFormRef = ref()
|
||||
const visible = ref(false)
|
||||
const loading = ref(false)
|
||||
const deptList = ref<any[]>([])
|
||||
const classList = ref<any[]>([])
|
||||
const allClassList = ref<any[]>([]) // 保存所有班级数据
|
||||
const classList = ref<any[]>([]) // 显示的班级数据(筛选后)
|
||||
const studentList = ref<any[]>([])
|
||||
const schoolDoorList = ref<any[]>([])
|
||||
|
||||
// 提交表单数据
|
||||
const form = reactive({
|
||||
@@ -160,6 +181,7 @@ const form = reactive({
|
||||
realName: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
schoolDoor: '',
|
||||
reason: '',
|
||||
remarks: ''
|
||||
})
|
||||
@@ -203,9 +225,12 @@ const resetForm = () => {
|
||||
form.realName = ''
|
||||
form.startTime = ''
|
||||
form.endTime = ''
|
||||
form.schoolDoor = ''
|
||||
form.reason = ''
|
||||
form.remarks = ''
|
||||
studentList.value = []
|
||||
// 重置班级列表为全部
|
||||
classList.value = allClassList.value
|
||||
}
|
||||
|
||||
// 系部变化
|
||||
@@ -216,9 +241,9 @@ const handleDeptChange = () => {
|
||||
studentList.value = []
|
||||
// 根据系部筛选班级
|
||||
if (form.deptCode) {
|
||||
classList.value = classList.value.filter((item: any) => item.deptCode === form.deptCode)
|
||||
classList.value = allClassList.value.filter((item: any) => item.deptCode === form.deptCode)
|
||||
} else {
|
||||
getClassListData()
|
||||
classList.value = allClassList.value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +292,7 @@ const onSubmit = async () => {
|
||||
stuNo: form.stuNo,
|
||||
startTime: form.startTime,
|
||||
endTime: form.endTime,
|
||||
schoolDoor: form.schoolDoor,
|
||||
reason: form.reason,
|
||||
remarks: form.remarks
|
||||
})
|
||||
@@ -296,37 +322,70 @@ const getDeptListData = async () => {
|
||||
// 获取班级列表
|
||||
const getClassListData = async () => {
|
||||
try {
|
||||
const res = await getClassList()
|
||||
const res = await getClassListByRole()
|
||||
if (res.data) {
|
||||
classList.value = Array.isArray(res.data) ? res.data : []
|
||||
const list = Array.isArray(res.data) ? res.data : []
|
||||
allClassList.value = list
|
||||
classList.value = list
|
||||
}
|
||||
} catch (err) {
|
||||
allClassList.value = []
|
||||
classList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 获取学生列表(接口文档:GET 仅 classCode,返回 data 为数组)
|
||||
// 获取学生列表
|
||||
const getStudentListData = async () => {
|
||||
if (!form.classCode) return
|
||||
try {
|
||||
const res = await queryStudentListByClass({ classCode: form.classCode })
|
||||
const data = res?.data
|
||||
// 先尝试 queryStudentListByClass 接口
|
||||
let res = await queryStudentListByClass({ classCode: form.classCode })
|
||||
let data = res?.data
|
||||
|
||||
// 如果数据为空或不是数组,尝试 queryAllStudentByClassCode 接口
|
||||
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||
res = await queryAllStudentByClassCode(form.classCode)
|
||||
data = res?.data
|
||||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
studentList.value = data
|
||||
} else if (data?.records && Array.isArray(data.records)) {
|
||||
studentList.value = data.records
|
||||
} else if (data && typeof data === 'object') {
|
||||
// 可能返回的是单个对象或包装对象
|
||||
studentList.value = [data]
|
||||
} else {
|
||||
studentList.value = []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取学生列表失败', err)
|
||||
studentList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 获取校门列表
|
||||
const getSchoolDoorData = async () => {
|
||||
try {
|
||||
const res = await getSchoolDoorList()
|
||||
if (res.data) {
|
||||
schoolDoorList.value = Array.isArray(res.data)
|
||||
? res.data.map((item: any) => ({
|
||||
label: item.positionName || item.name,
|
||||
value: item.id || item.positionCode
|
||||
}))
|
||||
: []
|
||||
}
|
||||
} catch (err) {
|
||||
schoolDoorList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getDeptListData()
|
||||
getClassListData()
|
||||
getSchoolDoorData()
|
||||
})
|
||||
|
||||
// 暴露方法
|
||||
|
||||
Reference in New Issue
Block a user