index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div :class="ui" class="hc-report-tasks-user-box">
  3. <div class="tag-user-list" @click="userShowModal">
  4. <template v-for="(item, index) in userData" :key="index">
  5. <el-tag>{{ item.userName }}</el-tag>
  6. <hc-icon v-if="(userData.length - 1) > index" name="arrow-right" ui="arrow-icon-tag" />
  7. </template>
  8. <div v-if="userData.length <= 0" class="tasks-placeholder">点击这里选择任务人</div>
  9. </div>
  10. <!-- 选择任务人 -->
  11. <HcUserModal v-model="isUserModalShow" :data="userData" :datas="dataInfo" @finish="fixedUserFinish" />
  12. </div>
  13. </template>
  14. <script setup>
  15. import { ref, watch } from 'vue'
  16. import { arrToKey, deepClone, getObjValue } from 'js-fast-way'
  17. import HcUserModal from './user-modal.vue'
  18. //参数
  19. const props = defineProps({
  20. ui: {
  21. type: String,
  22. default: '',
  23. },
  24. data: {
  25. type: Object,
  26. default: () => ({}),
  27. },
  28. userData: {
  29. type: Array,
  30. default: () => ([]),
  31. },
  32. })
  33. //事件
  34. const emit = defineEmits(['change', 'finish'])
  35. //选择完成
  36. const userData = ref(props.userData)
  37. //监听
  38. watch(() => [
  39. props.userData,
  40. ], ([users]) => {
  41. userData.value = users
  42. })
  43. //监听基础数据
  44. const dataInfo = ref(props.data)
  45. watch(() => props.data, (data) => {
  46. dataInfo.value = getObjValue(data)
  47. }, { deep: true, immediate: true })
  48. //展开弹窗
  49. const isUserModalShow = ref(false)
  50. const userShowModal = () => {
  51. isUserModalShow.value = true
  52. }
  53. const fixedUserFinish = (data) => {
  54. const res = deepClone(data)
  55. userData.value = res
  56. const userIds = arrToKey(res, 'userId', ',')
  57. emit('finish', userIds, res)
  58. }
  59. </script>
  60. <style lang="scss">
  61. @import './index.scss';
  62. </style>