index.vue 2.2 KB

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