user-component.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div>
  3. <el-select
  4. v-model="value"
  5. ref="select"
  6. placeholder="请输入姓名"
  7. clearable
  8. filterable
  9. remote
  10. :remote-method="remoteMethod"
  11. @change = "onChange">
  12. <el-option
  13. v-for="item in options"
  14. :key="item.value"
  15. :label="item.label"
  16. :value="item.value">
  17. </el-option>
  18. <el-option v-if="options.length > 0" label="加载更多" style="font-style: italic; color: #8a979e" value="undefined" @click.native="handleClick()"></el-option>
  19. </el-select>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'user-component',
  25. props: {
  26. userId: {
  27. type: String,
  28. default: ''
  29. }
  30. },
  31. model: {
  32. prop: 'userId',
  33. event: 'userSelected'
  34. },
  35. data () {
  36. return {
  37. value: '',
  38. current: 1,
  39. size: 10,
  40. name: '',
  41. options: [],
  42. loading: false,
  43. noMore: false
  44. }
  45. },
  46. mounted () {
  47. this.init()
  48. },
  49. methods: {
  50. async init () {
  51. this.getList()
  52. },
  53. remoteMethod (query) {
  54. this.options = []
  55. this.current = 1
  56. this.name = query
  57. this.getList()
  58. },
  59. getList () {
  60. this.$http({
  61. url: this.$http.adornUrl(`/user-service/user/list`),
  62. method: 'get',
  63. params: this.$http.adornParams({
  64. 'current': this.current,
  65. 'size': this.size,
  66. 'name': this.name
  67. })
  68. }).then(({data}) => {
  69. if (data && data.code === '200') {
  70. if (this.current > data.data.pages) {
  71. return
  72. }
  73. data.data.records.forEach(item => {
  74. this.options.push({
  75. label: item.name + ' (' + item.orgName + ')',
  76. value: item.userId
  77. })
  78. })
  79. } else {
  80. this.options = []
  81. }
  82. })
  83. },
  84. handleClick () {
  85. this.loadMore()
  86. },
  87. loadMore () {
  88. this.current ++
  89. this.getList()
  90. },
  91. onChange (item) {
  92. if (item === 'undefined') {
  93. this.value = null
  94. }
  95. this.$emit('userSelected', item)
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. </style>