supplier-component.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 'supplierState': 1
  77. })
  78. }).then(({data}) => {
  79. if (data && data.code === '200') {
  80. if (this.current > data.data.pages) {
  81. return
  82. }
  83. data.data.records.forEach(item => {
  84. this.options.push({
  85. label: item.supplierName,
  86. value: item.supplierId
  87. })
  88. })
  89. } else {
  90. this.options = []
  91. }
  92. })
  93. },
  94. handleClick () {
  95. this.loadMore()
  96. },
  97. loadMore () {
  98. this.current ++
  99. this.getList()
  100. },
  101. onChange (item) {
  102. if (item === 'undefined') {
  103. this.value = null
  104. }
  105. this.$emit('supplierSelected', 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. </style>