welfareLabel.vue 4.2 KB

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