enterpriseLabel.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!-- 企业标签 -->
  2. <template>
  3. <div>
  4. <span style="font-size: 16px;" class="mr-1">已选择标签</span>
  5. <span style="font-size: 14px; color: var(--color-666);">(最多10个标签)</span>
  6. <div class="mb-15">
  7. <v-chip
  8. v-for="(item, index) in chosen" :key="index"
  9. class="chip mx-2 mt-4"
  10. label color="primary"
  11. >
  12. {{ item }}
  13. <v-icon size="18" color="primary" style="margin-left: 6px;" @click="closeClick(item)">mdi-close-circle</v-icon>
  14. </v-chip>
  15. <div>
  16. <div v-if="customTag" class="d-flex align-center mx-2 mt-4">
  17. <TextUI class="mr-2" :item="textItem" @appendInnerClick.stop="appendInnerClick"></TextUI>
  18. <v-icon size="22" color="#ccc" style="cursor: pointer;" @click="customTag = false">mdi-close</v-icon>
  19. </div>
  20. <div v-else @click="customTag = true">
  21. <v-chip class="chip mx-2 mt-4" label color="#fd7b4ee6"><v-icon icon="mdi-plus" start></v-icon>自定义标签</v-chip>
  22. </div>
  23. </div>
  24. </div>
  25. <div v-for="(val, index) in chipList" :key="'enterpriseLabel' + index" class="mb-8">
  26. <span style="font-size: 16px;">{{ val?.nameCn || '--' }}</span>
  27. <div v-if="val?.children?.length">
  28. <v-chip
  29. v-for="(item, index) in val.children" :key="index"
  30. class="chip mx-2 mt-4"
  31. label color="primary"
  32. :disabled="chosen.includes(item?.nameCn )"
  33. @click="choseClick(item?.nameCn )"
  34. >
  35. <v-icon icon="mdi-plus" start></v-icon>
  36. {{ item?.nameCn || '--' }}
  37. </v-chip>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup>
  43. import TextUI from '@/components/FormUI/TextInput'
  44. import Snackbar from '@/plugins/snackbar'
  45. import Confirm from '@/plugins/confirm'
  46. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  47. import { getEnterpriseBaseInfo, updateEnterpriseTag, getTagTreeDataApi } from '@/api/enterprise'
  48. import { ref } from 'vue';
  49. defineOptions({name: 'informationSettingsComponents-enterpriseLabel'})
  50. const emit = defineEmits(['complete', 'preview'])
  51. const customTag = ref(false)
  52. const limitNum = ref(10)
  53. let chosen = ref([])
  54. // 删除
  55. const closeClick = (item) => {
  56. Confirm('系统提示', '是否确认删除?').then(async () => {
  57. chosen.value = chosen.value.filter(e => e !== item)
  58. handleSave('删除')
  59. })
  60. }
  61. // 从推荐标签添加
  62. const choseClick = (item) => {
  63. if (chosen.value?.length >= limitNum.value) return Snackbar.warning('最多可加10个标签')
  64. chosen.value.push(item)
  65. handleSave('添加')
  66. }
  67. // 保存自定义
  68. const appendInnerClick = (value) => {
  69. if (chosen.value?.length >= limitNum.value) return Snackbar.warning('最多可加10个标签')
  70. if (!value) return Snackbar.warning(t('common.pleaseEnter')+t('enterprise.infoSetting.enterpriseLabel'))
  71. const index = chosen.value.findIndex(e => e === value)
  72. if (index !== -1) return Snackbar.warning(t('common.alreadyExists'))
  73. chosen.value.push(value)
  74. handleSave('保存') // 保存自定义
  75. }
  76. // 保存
  77. const handleSave = async (type) => {
  78. try {
  79. const appAdminEnterpriseWelfareReqVO = { tagList: chosen.value }
  80. await updateEnterpriseTag(appAdminEnterpriseWelfareReqVO)
  81. customTag.value = false
  82. Snackbar.success(`${type}成功`)
  83. }
  84. finally {
  85. setTimeout(() => { // 马上获取数据数据会不同步故setTimeout
  86. getData()
  87. }, 2000)
  88. }
  89. }
  90. // 推荐标签
  91. const chipList = ref([])
  92. // 根据类型获取标签信息
  93. const getTagTreeData = async () => { // type: 标签类型-> 0人员画像标签 1职位标签 2招聘职位标签 3企业福利标签 4企业标签
  94. const data = await getTagTreeDataApi({ type: 4 })
  95. chipList.value = data || []
  96. }
  97. getTagTreeData()
  98. // 获取数据
  99. const getData = async () => {
  100. const data = await getEnterpriseBaseInfo()
  101. chosen.value = data?.tagList || []
  102. // 完成度展示
  103. emit('complete', {
  104. totalCount: 10,
  105. completeCount: chosen.value?.length ? 10 : 0,
  106. id: 'enterpriseLabel'
  107. })
  108. }
  109. getData()
  110. const textItem = ref({
  111. type: 'text',
  112. width: 250,
  113. hideDetails: true,
  114. autofocus: true, // 聚焦。
  115. value: '',
  116. label: '请输入自定义标签',
  117. // appendInnerIcon: 'mdi-content-save-outline',
  118. appendInnerIcon: 'mdi-checkbox-marked-circle',
  119. appendInnerClick: appendInnerClick,
  120. })
  121. </script>
  122. <style lang="scss" scoped>
  123. .chip {
  124. cursor: pointer;
  125. }
  126. </style>