index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div>
  3. <el-input placeholder="请选择" :size="size" :disabled="disabled" :readonly="readonly" style="line-hight:40px" v-model="name" class="input-with-select">
  4. <el-button slot="append" :disabled="disabled" :readonly="readonly" @click="showUserSelect" icon="el-icon-search"></el-button>
  5. </el-input>
  6. <user-select ref="userSelect" @doSubmit="selectUsersToInput" :limit="limit" :selectData="selectData"></user-select>
  7. </div>
  8. </template>
  9. <script>
  10. import userSelect from './UserSelectDialog'
  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. size: String,
  23. readonly: {
  24. type: Boolean,
  25. default: () => { return false }
  26. },
  27. disabled: {
  28. type: Boolean,
  29. default: () => { return false }
  30. }
  31. },
  32. components: {
  33. userSelect
  34. },
  35. created () {
  36. },
  37. watch: {
  38. value: {
  39. handler (newVal) {
  40. this.selectData = []
  41. if (newVal) {
  42. newVal.split(',').forEach((id) => {
  43. this.$http.get(`/sys/user/queryById?id=${id}`).then(({data}) => {
  44. if (data.user && data.user.id !== '') {
  45. this.selectData.push(data.user)
  46. }
  47. })
  48. })
  49. }
  50. },
  51. immediate: true,
  52. deep: false
  53. },
  54. selectData: {
  55. handler (newVal) {
  56. this.name = newVal.map(user => { return user.name }).join(',')
  57. },
  58. immediate: true,
  59. deep: false
  60. }
  61. },
  62. methods: {
  63. selectUsersToInput (users) {
  64. this.selectData = users
  65. this.labelValue = users.map(user => { return user.id }).join(',')
  66. this.name = users.map(user => { return user.name }).join(',')
  67. this.$emit('getValue', this.labelValue, this.name)
  68. },
  69. showUserSelect () {
  70. this.$refs.userSelect.init()
  71. }
  72. }
  73. }
  74. </script>
  75. <style>
  76. .el-form-item__content .el-input-group {
  77. vertical-align: middle;
  78. }
  79. .el-tag + .el-tag {
  80. margin-left: 5px;
  81. margin-bottom: 5px;
  82. }
  83. </style>