welfareLabel.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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="primary"
  10. >
  11. {{ item }}
  12. <v-icon size="18" color="primary" 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="orange"><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="primary"
  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 customTag = ref(false)
  49. const limitNum = ref(10)
  50. let chosen = ref([])
  51. // 删除
  52. const closeClick = (item) => {
  53. Confirm('系统提示', '是否确认删除?').then(async () => {
  54. chosen.value = chosen.value.filter(e => e !== item)
  55. handleSave('删除')
  56. })
  57. }
  58. // 从推荐标签添加
  59. const choseClick = (item) => {
  60. if (chosen.value?.length >= limitNum.value) return Snackbar.warning('最多可加10个标签')
  61. chosen.value.push(item)
  62. handleSave('添加')
  63. }
  64. // 保存自定义
  65. const appendInnerClick = (value) => {
  66. if (chosen.value?.length >= limitNum.value) return Snackbar.warning('最多可加10个标签')
  67. if (!value) return Snackbar.warning(t('common.pleaseEnter')+t('enterprise.infoSetting.welfareLabel'))
  68. const index = chosen.value.findIndex(e => e === value)
  69. if (index !== -1) return Snackbar.warning(t('common.alreadyExists'))
  70. chosen.value.push(value)
  71. handleSave('保存')
  72. }
  73. // 保存
  74. const handleSave = async (type) => {
  75. const appAdminEnterpriseWelfareReqVO = { welfareList: chosen.value }
  76. await updateEnterpriseWelfare(appAdminEnterpriseWelfareReqVO)
  77. customTag.value = false
  78. Snackbar.success(`${type}成功`)
  79. setTimeout(() => { // 马上获取数据数据会不同步故setTimeout
  80. getData()
  81. }, 5000)
  82. }
  83. // 推荐标签
  84. const chipList = ref([])
  85. // 根据类型获取标签信息
  86. const getTagTreeData = async () => { // type: 标签类型-> 0人员画像标签 1职位标签 2招聘职位标签 3企业福利标签 4企业标签
  87. const data = await getTagTreeDataApi({ type: 3 })
  88. chipList.value = data || []
  89. }
  90. getTagTreeData()
  91. // 获取数据
  92. const getData = async () => {
  93. const data = await getEnterpriseBaseInfo()
  94. chosen.value = data?.welfareList || []
  95. }
  96. getData()
  97. const textItem = ref({
  98. type: 'text',
  99. width: 250,
  100. hideDetails: true,
  101. autofocus: true, // 聚焦。
  102. value: '',
  103. label: '请输入自定义标签',
  104. // appendInnerIcon: 'mdi-content-save-outline',
  105. appendInnerIcon: 'mdi-checkbox-marked-circle',
  106. appendInnerClick: appendInnerClick,
  107. })
  108. </script>
  109. <style lang="scss" scoped>
  110. .chip {
  111. cursor: pointer;
  112. }
  113. </style>