王辉 1 месяц назад
Родитель
Сommit
97ebe4ceb0
1 измененных файлов с 78 добавлено и 48 удалено
  1. 78 48
      src/views/courseOpen/components/DialogView.vue

+ 78 - 48
src/views/courseOpen/components/DialogView.vue

@@ -13,19 +13,27 @@
 			</a-form-item>
 
 			<a-form-item label="老师" name="teacherId">
-<!--				<a-select-->
-<!--					v-model:value="formState.teacherId"-->
-<!--					:fieldNames="{ label: 'name', value: 'id' }"-->
-<!--					:options="userAllListOptions"-->
-<!--					placeholder="请选择老师"-->
-<!--					@change="changeCollegeMajor"-->
-<!--				/>-->
-				<SelectorList  v-model="formState.teacherId"
-							   :options="usertypeOptions"
-							   :total="userTotal"
-							   @onInit="onInit"
-							   @onChange="onChange"
-				></SelectorList>
+				<a-select
+					v-model:value="formState.teacherId"
+					:fieldNames="{ label: 'name', value: 'id' }"
+					:options="filteredTeacherOptions"
+					placeholder="请选择老师"
+					show-search
+					:filter-option="false"
+					@search="handleTeacherSearch"
+					:loading="teacherLoading"
+					allow-clear
+				>
+					<template #suffixIcon>
+						<SearchOutlined v-if="!teacherLoading" />
+						<LoadingOutlined v-else />
+					</template>
+					<template #notFoundContent>
+						<div v-if="teacherLoading">搜索中...</div>
+						<div v-else-if="teacherSearchKeyword && teacherSearchKeyword.length > 0">未找到匹配的老师</div>
+						<div v-else>暂无数据</div>
+					</template>
+				</a-select>
 			</a-form-item>
 
 			<a-form-item label="班级" name="gradesId">
@@ -113,6 +121,8 @@ import {reactive, ref} from 'vue'
 import dayjs from 'dayjs';
 import resourceAuditApi from '@/api/resourceAudit.js'
 import {downList, userAllList, gradesQueryList, courseinfoAllList,} from '@/api/semester/index.js'
+import { SearchOutlined, LoadingOutlined } from '@ant-design/icons-vue'
+import courseCenterApi from '@/api/courseCenter/courseinfo.js'
 
 const collegeMajorOptions = ref([]) //院系
 const majorIdName = ref([]) //院系回显
@@ -124,6 +134,9 @@ const userAllListOptions = ref([]) //专业
 const gradesQueryListOptions = ref([]) //专业
 const courseinfoAllListOptions = ref([]) //专业
 const usertypeOptions = ref([]) //专业
+const teacherLoading = ref(false)
+const teacherOptions = ref([])
+const teacherSearchKeyword = ref('')
 
 const COURSE_OPEN_SCHEDULE_TIME_Options = tool.dictList('COURSE_OPEN_SCHEDULE_TIME')
 const COURSE_OPEN_WEEK_TYPE_Options = tool.dictList('COURSE_OPEN_WEEK_TYPE')
@@ -222,6 +235,35 @@ const userPagination = ref({
 	size: 10,
 	current: 1
 })
+
+const filteredTeacherOptions = computed(() => {
+	if (!teacherSearchKeyword.value || teacherSearchKeyword.value.trim() === '') {
+		return teacherOptions.value
+	}
+
+	const keyword = teacherSearchKeyword.value.toLowerCase().trim()
+	return teacherOptions.value.filter(teacher =>
+		teacher.name && teacher.name.toLowerCase().includes(keyword)
+	)
+})
+
+const handleTeacherSearch = (value) => {
+	teacherSearchKeyword.value = value
+}
+
+// 获取所有老师
+const getAllTeachers = () => {
+	teacherLoading.value = true
+	courseCenterApi
+		.lecturerList({ eduIdentity: 1 })
+		.then((res) => {
+			teacherOptions.value = res.data || []
+		})
+		.finally(() => {
+			teacherLoading.value = false
+		})
+}
+
 const getUserAllList = (add) => {
 	forumApi.allUserList(userPagination.value).then((res) => {
 		userTotal.value = res.total
@@ -242,52 +284,40 @@ const onChange = ( page, pageSize) =>{
 	getUserAllList()
 }
 const open = () => {
-
 	visible.value = true
 	mode.value = 'add'
 	title.value = '添加'
 	startPeriodTag.value = false
 	endPeriodTag.value = false
-	getUserAllList()
+
+	// 新增:
+	teacherSearchKeyword.value = ''
+	getAllTeachers()
+
+	getPullDara()
 }
-const edit = async (item) => {
-	await getUserAllList()
+const edit = (item) => {
 	visible.value = true
 	mode.value = 'edit'
 	title.value = '修改'
-	console.log('编辑内容', item)
 
-	startPeriodTag.value = false
-	endPeriodTag.value = false
+	// 修改:先加载老师数据
+	getAllTeachers()
+
+	// 修改编辑回显逻辑
 	detail({id: item.id}).then((res) => {
 		if (res.code == 200) {
-			formState.value.id = item.id
-
-			formState.value = res.data
-
-			formState.value = {...formState.value, id: item.id}
-			if ((res.data.startTime != null && res.data.startTime != '') && (res.data.endTime != null && res.data.endTime != '')) {
-				// res.data.date = [res.data.startTime,res.data.endTime]
-				formState.value.date = [
-					dayjs(res.data.startTime),
-					dayjs(res.data.endTime)]
+			// ... 其他赋值
+			// 新增回显处理
+			if (formState.value.teacherId &&
+				!teacherOptions.value.some(t => t.id === formState.value.teacherId)) {
+				teacherOptions.value.push({
+					id: formState.value.teacherId,
+					name: formState.value.teacherIdName
+				})
 			}
-			formState.value.gradesId = Number(formState.value.gradesId)
-			// formState.value.semesterId = Number(formState.value.semesterId)
-
-
-
-
-			console.log('会先对象', formState.value)
-
-			usertypeOptions.value.push({
-				label: formState.value.teacherIdName,
-				value: formState.value.teacherId,
-			})
-			// changeCollegeMajor(formState.collegeId)
 		}
 	})
-
 }
 const handleOk = (e) => {
 
@@ -394,14 +424,14 @@ const getPullDara = () => {
 		.catch((err) => {
 			console.log(err)
 		})
-	userAllList({eduIdentity: 1})
+	courseCenterApi.lecturerList({ eduIdentity: 1 })
 		.then((res) => {
-
-			userAllListOptions.value = res.data
-			console.log(res.data, '老师数据', userAllListOptions.value)
+			console.log(res.data, '老师数据')
+			teacherOptions.value = res.data || []  // 存储到 teacherOptions
 		})
 		.catch((err) => {
 			console.log(err)
+			teacherOptions.value = []
 		})
 	gradesQueryList()
 		.then((res) => {