Переглянути джерело

feat(课程搜索): 根据用户类型动态显示学员名单字段并添加计划ID

修改课程搜索组件,根据用户类型决定是否显示学员名单字段。同时将计划ID加入搜索参数,以便后端处理。
在plan.hook中新增getUserType和planId的返回,用于控制字段显示和传递计划ID。
zhanghaijun 10 місяців тому
батько
коміт
222332258d

+ 12 - 3
src/views/train/course/list/plan.hook.ts

@@ -1,6 +1,7 @@
 import request from '@/api'
 import { CascaderOption } from 'element-plus'
 import { usePlanStore } from '@/store/modules/plan.store'
+import { useUserStore } from '@/store/modules/user'
 
 export interface OptionItem {
   value: string
@@ -23,6 +24,8 @@ export interface StudentItem {
 }
 
 export const usePlanOptions = () => {
+  const { getUserType } = toRefs(useUserStore())
+  const planStore = usePlanStore()
   // 培训计划选项
   const planActive = ref<string[]>([])
   const planDate = ref<PlanItem[]>([])
@@ -51,9 +54,13 @@ export const usePlanOptions = () => {
       children: item.PlanInfo?.map((plan) => ({ value: plan.JXJHID || '', label: plan.KMMC || '' })) || []
     }))
   })
+  const planId = computed(() => {
+    if (planActive.value.length < 2) return ''
+    return planActive.value[1] || ''
+  })
 
-  // // 学员列表
-  const studentActive = ref<string>('')
+  // 学员列表
+  const studentActive = ref<string>(getUserType.value === 2 ? '' : '1001')
   const studentData = ref<StudentItem[]>([])
   const getStudentOptions = async () => {
     console.log(planActive.value)
@@ -75,7 +82,7 @@ export const usePlanOptions = () => {
     }))
   })
   // 监听培训计划选项变化,更新学员列表
-  const planStore = usePlanStore()
+
   watch(planActive, (newVal) => {
     if (newVal.length > 1) {
       planStore.updatePlan(newVal[1], '', newVal[0])
@@ -91,8 +98,10 @@ export const usePlanOptions = () => {
   })
 
   return {
+    getUserType,
     planActive,
     planOptions,
+    planId,
     studentActive,
     studentOptions
   }

+ 5 - 3
src/views/train/course/list/search.vue

@@ -16,7 +16,7 @@
   import { useDictStore } from '@/store/modules/dict'
   import { usePlanOptions } from './plan.hook'
 
-  const { planActive, planOptions, studentActive, studentOptions } = usePlanOptions()
+  const { planId, getUserType, planActive, planOptions, studentActive, studentOptions } = usePlanOptions()
   const dictStore = useDictStore()
 
   // courseID 非必须,其他字段必须
@@ -58,12 +58,14 @@
       options: [],
       rules: [{ required: true, message: '请选择培训计划', trigger: ['change'] }]
     },
-    { label: '* 学员名单', key: 'XYEMPID', type: 'input', placeholder: '请选择学员', clearable: true, options: [], rules: [{ required: true, message: '请选择学员', trigger: ['change'] }] }
+    ...(getUserType.value === 2
+      ? []
+      : [{ label: '* 学员名单', key: 'XYEMPID', type: 'input', placeholder: '请选择学员', clearable: true, options: [], rules: [{ required: true, message: '请选择学员', trigger: ['change'] }] }])
   ])
 
   const courseSearchHandle = async () => {
     await courseSearchRef.value.validate()
-    emit('search', courseFormData)
+    emit('search', { ...courseFormData, PXSSID: planId.value })
   }
 
   // interface OptionItem {