personnelSearch.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script lang="ts" setup>
  2. import { ref, reactive, onMounted, inject, watchEffect, computed } from 'vue';
  3. import { storeToRefs } from 'pinia';
  4. import { Emits, optionsType } from './type';
  5. import { useStore } from '@/store/index'
  6. import { generateUniqueId } from '@/utils/tools'
  7. import { post, get, uploadFile } from "@/utils/request";
  8. const props = defineProps({
  9. modelValue: { type: [String, Number, Array, Object, Boolean], required: true },
  10. multiple: { type: Boolean, required: false, default: false },
  11. size: { type: String as () => assemblySize, required: true, default: () => 'small' },
  12. placeholder: { type: String, required: false, default: () => '请填写' },
  13. disabled: { type: Boolean, required: false, default: false },
  14. options: { type: Array as () => optionsType, required: false, default: () => [] },
  15. });
  16. const emit = defineEmits<Emits>();
  17. const { userInfo } = storeToRefs(useStore());
  18. const timeRef = generateUniqueId()
  19. const controlTranslation = reactive({
  20. visibleFlag: false
  21. })
  22. const selectedValue = ref(props.modelValue); // 响应式绑定 v-model 的值
  23. // function getUserList(keyword: string = '', flag: boolean = true) {
  24. // post(`/user/getEmployeeList`, {
  25. // keyword,
  26. // status: 3,
  27. // matchingType: 0,
  28. // })
  29. // }
  30. function visibleChange(visible: boolean) { // 下拉框出现/隐藏时触发
  31. console.log(visible, '<==== visible')
  32. controlTranslation.visibleFlag = visible
  33. }
  34. function updateValue(val: any) { // 值改变的时候触发
  35. emit('update:modelValue', selectedValue.value)
  36. emit('change', val)
  37. }
  38. console.log(props, userInfo, '<==== 看看数据')
  39. </script>
  40. <template>
  41. <el-select v-model="selectedValue" :ref="`selectRef${timeRef}`" :multiple="multiple" :size="size"
  42. :placeholder="placeholder" :disabled="disabled" clearable collapse-tags @change="updateValue"
  43. @visible-change="visibleChange">
  44. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  45. </el-select>
  46. </template>
  47. <style lang="scss" scoped></style>