position.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="d-flex font-size-14 flex-wrap">
  3. <div v-for="val in items" :key="val.id" class="mr-5 cursor-pointer mb-3" :class="{'active': val.active}" @click="handleFirst(val)">{{ val.nameCn }}</div>
  4. </div>
  5. <div class="mt-3 font-size-14 mb-3">
  6. <span
  7. v-for="k in children"
  8. :key="k.id"
  9. class="d-inline-block mr-10 cursor-pointer color-666 mb-2"
  10. :class="{'active': select.findIndex(e => e.id === k.id) !== -1}"
  11. @click="handleSecond(k)"
  12. >{{ k.nameCn }}</span>
  13. </div>
  14. </template>
  15. <script setup>
  16. defineOptions({ name: 'search-screen-industry'})
  17. import { ref, watch } from 'vue'
  18. import { getDict } from '@/hooks/web/useDictionaries'
  19. const emit = defineEmits(['select', 'clear'])
  20. const props = defineProps({
  21. selectData: {
  22. type: Array,
  23. default: () => []
  24. },
  25. isClear: Boolean
  26. })
  27. const items = ref([])
  28. const select = ref([])
  29. const children = ref([])
  30. getDict('positionTreeData', {}, 'positionTreeData').then(({ data }) => {
  31. if (!data) return
  32. items.value = data.map(e => {
  33. e.active = false
  34. return e
  35. })
  36. })
  37. watch(
  38. () => props.selectData,
  39. (val) => {
  40. select.value = val
  41. },
  42. { deep: true }
  43. )
  44. const handleFirst = (val) => {
  45. items.value.forEach(e => e.active = false)
  46. val.active = !val.active
  47. children.value = val.children || []
  48. }
  49. const handleSecond = (val) => {
  50. const index = select.value.findIndex(e => e.id === val.id)
  51. if (index !== -1) {
  52. select.value.splice(index, 1)
  53. } else select.value.push(val)
  54. emit('select', select.value)
  55. }
  56. watch(
  57. () => props.isClear,
  58. (val) => {
  59. if (!val) return
  60. select.value = []
  61. children.value = []
  62. items.value.forEach(e => e.active = false)
  63. emit('clear')
  64. }
  65. )
  66. </script>
  67. <style scoped lang="scss">
  68. .active {
  69. color: var(--v-primary-base);
  70. font-family: 'MiSans-Bold';
  71. }
  72. </style>