doc-components.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div>
  3. <el-select
  4. v-model="value"
  5. ref="select"
  6. placeholder="请选择"
  7. clearable
  8. filterable
  9. remote
  10. multiple
  11. :disabled="disabled"
  12. :remote-method="remoteMethod"
  13. @change="onChange"
  14. @focus="cancelReadOnly"
  15. @hook:mounted="cancelReadOnly"
  16. @visible-change="cancelReadOnly">
  17. <el-option
  18. v-for="item in options"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value">
  22. </el-option>
  23. <el-option v-if="noMore" label="加载更多" disabled style="font-style: italic; color: #8a979e" value="undefined" @click.native="handleClick()"></el-option>
  24. </el-select>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'doc-components',
  30. props: {
  31. docIds: {
  32. type: Array,
  33. default: () => []
  34. },
  35. disabled: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. data () {
  41. return {
  42. value: [],
  43. current: 1,
  44. size: 10,
  45. name: '',
  46. options: [],
  47. loading: false,
  48. noMore: false
  49. }
  50. },
  51. watch: {
  52. docIds (value) {
  53. this.value = value
  54. }
  55. },
  56. mounted () {
  57. this.init()
  58. },
  59. methods: {
  60. async init () {
  61. this.getList()
  62. },
  63. remoteMethod (query) {
  64. this.options = []
  65. this.current = 1
  66. this.name = query
  67. this.getList()
  68. },
  69. getList () {
  70. this.$http({
  71. url: this.$http.adornUrl(`/file-service/document-ctl/list`),
  72. method: 'get',
  73. params: this.$http.adornParams({
  74. 'current': this.current,
  75. 'size': this.size,
  76. 'fileName': this.name
  77. })
  78. }).then(({data}) => {
  79. if (data && data.code === '200') {
  80. if (this.current > data.data.pages) {
  81. return
  82. }
  83. this.noMore = data.data.records.length >= 10
  84. data.data.records.forEach(item => {
  85. this.options.push({
  86. label: item.fileName,
  87. value: item.docId,
  88. fileType: item.fileType,
  89. url: item.url
  90. })
  91. })
  92. } else {
  93. this.options = []
  94. }
  95. })
  96. },
  97. handleClick () {
  98. this.loadMore()
  99. },
  100. loadMore () {
  101. this.current ++
  102. this.getList()
  103. },
  104. onChange (item) {
  105. this.$emit('change', item)
  106. },
  107. cancelReadOnly (onOff) {
  108. this.$nextTick(() => {
  109. if (!onOff) {
  110. const input = this.$refs.select.$el.querySelector('.el-input__inner')
  111. const timer = setTimeout(() => {
  112. input.removeAttribute('readonly')
  113. clearTimeout(timer)
  114. }, 200)
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .el-select{
  123. width: 100%;
  124. }
  125. </style>