index.vue 2.3 KB

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