warehouse-select.vue 2.5 KB

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