supplier-component.vue 2.8 KB

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