Explorar o código

企业基本信息编辑

Xiao_123 hai 11 meses
pai
achega
a6eeb99693

+ 8 - 5
src/components/industryTypeCard/index.vue

@@ -61,7 +61,6 @@ const props = defineProps({
 let items = ref()
 let idChecked = ref([])
 let currentSelect = ref([])
-
 // 回显
 if (props.currentData.length) currentSelect.value = props.currentData
 if (props.select.length) idChecked.value = props.select.map(e => e + '') // 数据中的id是字符串
@@ -74,12 +73,16 @@ getDict('industryTreeData', null, 'industryTreeData').then(({ data }) => {
 // 设置选中ids
 const handleClick = (val) => {
   const isExist = idChecked.value.includes(val.id)
-  console.log(isExist, 'isExist', idChecked.value)
   if (!isExist) {
     // 添加
-    if (props.limit === idChecked.value.length) return Snackbar.warning(`最多可选${props.limit}个行业`)
-    currentSelect.value.push(val)
-    idChecked.value.push(val.id)
+    if (props.limit === 1) {
+      currentSelect.value = [val]
+      idChecked.value = [val.id]
+    } else {
+      if (props.limit === idChecked.value.length) return Snackbar.warning(`最多可选${props.limit}个行业`)
+      currentSelect.value.push(val)
+      idChecked.value.push(val.id)
+    }
   } else {
     // 删除
     currentSelect.value = currentSelect.value.filter(e => e.id !== val.id)

+ 49 - 32
src/views/enterprise/informationManagement/informationSettingsComponents/basicInfo.vue

@@ -18,7 +18,7 @@
               v-bind="props"
             ></TextInput>
           </template>
-          <industryTypeCard :limit="1" :select="query.industryIdList" :currentData="currentSelect" @handleClickIndustry="handleIndustry"></industryTypeCard>
+          <industryTypeCard :limit="1" :select="[query.industryId].filter(Boolean)" @handleClickIndustry="handleIndustry"></industryTypeCard>
         </v-menu>
       </template>
     </CtForm>
@@ -30,21 +30,23 @@
 
 <script setup>
 defineOptions({name: 'informationSettingsComponents-basicInfo'})
-import { inject, ref, reactive } from 'vue'
-// import { getEnterpriseBaseInfo } from '@/api/enterprise'
+import { ref, reactive } from 'vue'
+import { getEnterpriseBaseInfo, updateEnterpriseBaseInfo } from '@/api/enterprise'
+import { getDict } from '@/hooks/web/useDictionaries'
 import industryTypeCard from '@/components/industryTypeCard'
+import Snackbar from '@/plugins/snackbar'
 
+const CtFormRef = ref()
 const query = reactive({})
-const infoData = JSON.parse(inject('infoData'))
 const formItems = ref({
   options: [
     {
       type: 'text',
       key: 'name',
       value: '',
-      label: '企业称 *',
+      label: '企业称 *',
       slotName: 'name',
-      rules: [v => !!v || '请输入企业称']
+      rules: [v => !!v || '请输入企业称']
     },
     {
       type: 'text',
@@ -80,16 +82,16 @@ const formItems = ref({
     {
       slotName: 'industryId',
       key: 'industryId',
-      value: '',
+      value: null,
       label: '所在行业 *',
       outlined: true,
       clearable: false,
       itemText: 'label',
       itemValue: 'value',
       col: 6,
+      noParam: true,
       flexStyle: 'mr-3',
-      rules: [v => !!v || '请选择所在行业'],
-      items: []
+      rules: [v => !!v || '请选择所在行业']
     },
     {
       type: 'autocomplete',
@@ -127,55 +129,70 @@ const formItems = ref({
       col: 6,
       class: 'mb-3',
       label: '上班时间(示例:上午09:00 - 下午17:00) *',
-      rules: [v => !!v || '请选择上班时间']
+      rules: [v => !!v || '请填写上班时间']
     },
     {
       type: 'textarea',
       key: 'introduce',
       value: null,
       counter: 2000,
+      rows: 6,
       label: '企业介绍 *',
       outlined: true,
       rules: [v => !!v || '请输入企业介绍']
     },
   ]
 })
-formItems.value.options.forEach(e => { if (infoData[e.key]) e.value = infoData[e.key] })
 
 const setValue = (key, value) => {
   formItems.value.options.find(e => e.key === key).value = value
 }
 
+// 行业列表
+const industryList = ref([])
+getDict('menduner_industry_type', {}, 'industryList').then(({ data }) => {
+  data = data?.length && data || []
+  industryList.value = data
+})
+
 // 获取基本信息
-// const getBaseInfo = async () => {
-//   const data = await getEnterpriseBaseInfo()
-//   console.log(data, 'info')
-// }
-// getBaseInfo()
+const getBaseInfo = async () => {
+  const data = await getEnterpriseBaseInfo()
+  if (!data) return
+  query.id = data.id
+  formItems.value.options.forEach(item => {
+    if (item.dictTypeName) {
+      getDict(item.dictTypeName).then(({ data }) => {
+        data = data?.length && data || []
+        item.items = data
+      })
+    }
+    query.industryId = data.industryId
+    if (item.key === 'industryId') {
+      item.value = industryList.value.find(e => e.id === data[item.key]).nameCn
+    } else item.value = data[item.key]
+  })
+}
+getBaseInfo()
 
-// 行业类型
-let currentSelect = reactive([])
+// 所在行业
 const handleIndustry = (list, arr) => {
-  console.log(list, arr, 'in')
   if (!list.length) return
-  query.industryId = list
-  currentSelect = arr
+  query.industryId = list[0]
   const str = arr.map(e => e.nameCn).join('、')
   setValue('industryId', str)
 }
 
 const handleSave = async () => {
-  // const { valid } = await formPageRef.value.formRef.validate()
-  // if (!valid) return
-  // items.value.options.forEach(e => {
-  //   if (arr.includes(e.key)) query[e.key] = e.value 
-  // })
-  // if (editId.value) query.id = editId.value
-  // await saveResumeJobInterested(query)
-  // Snackbar.success('保存成功')
-  // isAdd.value = false
-  // resetForm()
-  // getJobInterested()
+  const { valid } = await CtFormRef.value.formRef.validate()
+  if (!valid) return
+  formItems.value.options.forEach(e => {
+    if (e.noParam) return
+    query[e.key] = e.value
+  })
+  await updateEnterpriseBaseInfo(query)
+  Snackbar.success('编辑成功')
+  getBaseInfo()
 }
 </script>
 <style lang="scss" scoped>