浏览代码

v-combobox组件封装完善优化

lifanagju_citu 9 月之前
父节点
当前提交
4b377a8c6e

+ 21 - 10
src/views/recruit/personal/remuse/components/educationExp.vue

@@ -63,13 +63,15 @@ const CtFormRef = ref()
 const dictItemsObj = reactive({})
 
 // 学校下拉列表
-const getSchoolListData = async (name, init = '') => {
+const getSchoolListData = async (name) => {
   const item = formItems.value.options.find(e => e.key === 'schoolId')
   if (!item) return
   item[item.itemTextName] = name
-  if (!init) item.value = null
-  const data = await schoolSearchByName({ name })
-  item.items = data
+  if (name === null || name === '') { item.items = [] }
+  else {
+    const data = await schoolSearchByName({ name })
+    item.items = data
+  }
 }
 const debouncedCallbackSchool = debounce(newValue => {
   if (!newValue) return
@@ -77,13 +79,18 @@ const debouncedCallbackSchool = debounce(newValue => {
 }, 500)
 
 // 专业下拉列表
-const getMajorListData = async (name, init = '') => {
-  if (name === '') return // 此接口不支持传空值
+const getMajorListData = async (name) => {
+  if (name === '') { // 此接口不支持传空值
+    item.items = []
+    return
+  }
   const item = formItems.value.options.find(e => e.key === 'majorId')
   item[item.itemTextName] = name
-  if (!init) item.value = null
-  const data = await schoolMajorByName({ name })
-  item.items = data
+  if (name === null || name === '') { item.items = [] }
+  else {
+    const data = await schoolMajorByName({ name })
+    item.items = data
+  }
 }
 const debouncedCallbackMajor = debounce(newValue => {
   getMajorListData(newValue)
@@ -219,7 +226,11 @@ const handle = (item) => {
     })
   } else { // 新增
     editId.value = null
-    formItems.value.options.forEach(e => e.value = e.default || null)
+    formItems.value.options.forEach(e => {
+      e.value = e.default || null
+      if (e.key === 'schoolId') e.items = []
+      if (e.key === 'majorId') e.items = []
+    })
   }
   nextTick(() => {
     isEdit.value = true

+ 10 - 10
src/views/recruit/personal/remuse/components/workExperience.vue

@@ -80,22 +80,21 @@ const dictItemsObj = reactive({})
 dictItemsObj.educationSystemType = [{ label: '全日制', value: '0' }, { label: '非全日制', value: '1' }]
 
 // 企业名称下拉列表
-const getSchoolListData = async (name, init = '') => {
+const getEnterpriseData = async (name) => {
   const item = formItems.value.options.find(e => e.key === 'enterpriseId')
   if (!item) return
-  if (!init) item.value = null
   item[item.itemTextName] = name
-  const data = await enterpriseSearchByName({ name })
-  item.items = data
+  if (name === null || name === '') { item.items = [] }
+  else {
+    const data = await enterpriseSearchByName({ name })
+    item.items = data
+  }
 }
-// const debouncedCallbackSchool = debounce(newValue => {
-//   getSchoolListData(newValue)
-// }, 500)
 
-const positionSearch = (name, init = '') => {
+const positionSearch = (name) => {
   const item = formItems.value.options.find(e => e.key === 'positionId')
   if (!item) return
-  if (!init) item.value = ''
+  // if (name && name !==0 && !edit) item.value = null
   item[item.itemTextName] = name
 }
 
@@ -126,7 +125,7 @@ const formItems = ref({
       itemText: 'value',
       itemValue: 'key',
       rules: [v => !!v || '请选择企业名称'],
-      search: getSchoolListData,
+      search: getEnterpriseData,
       items: []
     },
     {
@@ -227,6 +226,7 @@ const handle = (item) => {
       e.disabled = false
       if (e.soFar) e.soFar = false
       if (e.key === 'endTime') e.rules = [v => !!v || '请选择结束时间']
+      if (e.key === 'enterpriseId') e.items = []
     })
   }
   nextTick(() => {