index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <template v-if="printRead">
  3. <label>{{ name }}</label>
  4. </template>
  5. <template v-else>
  6. <el-input placeholder="请选择" readonly :clearable="clearable" :disabled="disabled" style="line-hight: 40px"
  7. v-model="name">
  8. <template #append>
  9. <el-button :disabled="disabled" :readonly="readonly" @click="showUserSelect" icon="search"></el-button>
  10. </template>
  11. </el-input>
  12. <user-select ref="userSelect" @doSubmit="selectUsersToInput" :tenantId="tenantId" :limit="limit"></user-select>
  13. </template>
  14. </template>
  15. <script>
  16. import userSelect from "./UserSelectDialog";
  17. import userService from "@/api/sys/userService";
  18. export default {
  19. data() {
  20. return {
  21. name: "",
  22. selectData: [],
  23. };
  24. },
  25. props: {
  26. limit: Number,
  27. modelValue: { type: String, default: "" },
  28. tenantId: { type: String, default: null },
  29. printRead: {
  30. type: Boolean,
  31. default: () => {
  32. return false;
  33. },
  34. },
  35. clearable: {
  36. type: Boolean,
  37. default: () => {
  38. return true;
  39. },
  40. },
  41. readonly: {
  42. type: Boolean,
  43. default: () => {
  44. return false;
  45. },
  46. },
  47. disabled: {
  48. type: Boolean,
  49. default: () => {
  50. return false;
  51. },
  52. },
  53. },
  54. components: {
  55. userSelect,
  56. },
  57. watch: {
  58. modelValue: {
  59. handler(newVal) {
  60. this.selectData = [];
  61. if (newVal) {
  62. newVal.split(",").forEach((id) => {
  63. userService.queryByLoginName(id).then((data) => {
  64. if (data && data.id !== "") {
  65. this.selectData.push(data);
  66. this.name = this.selectData
  67. .map((user) => {
  68. return user.name;
  69. })
  70. .join(",");
  71. }
  72. });
  73. });
  74. } else {
  75. this.name = "";
  76. }
  77. },
  78. immediate: true,
  79. deep: false,
  80. },
  81. },
  82. methods: {
  83. selectUsersToInput(users) {
  84. let selectIds = users
  85. .map((user) => {
  86. return user.id;
  87. })
  88. .join(",");
  89. this.$emit("update:modelValue", selectIds);
  90. },
  91. showUserSelect() {
  92. this.$refs.userSelect.open(this.selectData);
  93. },
  94. },
  95. };
  96. </script>
  97. <style>
  98. .el-form-item__content .el-input-group {
  99. vertical-align: middle;
  100. }
  101. .el-tag+.el-tag {
  102. margin-left: 5px;
  103. margin-bottom: 5px;
  104. }
  105. </style>