chooseWarehouse.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { queryAuthWarehouse, warehouseAllList } from '@/api/warehouse'
  2. const warehouse = {
  3. template: `
  4. <a-select
  5. :placeholder="placeholder"
  6. :id="id"
  7. :allowClear="allowClear"
  8. :value="defaultVal"
  9. :showSearch="true"
  10. :disabled="disabled"
  11. :mode="modeType"
  12. @change="handleChange"
  13. :filter-option="filterOption">
  14. <a-select-option v-for="item in warehouseData" :key="item.warehouseSn" :value="item.warehouseSn">{{ item.name }}</a-select-option>
  15. </a-select>
  16. `,
  17. props: {
  18. value: {
  19. type: [String, Array],
  20. defatut: ''
  21. },
  22. isPermission: {// false无权限 true有权限
  23. type: Boolean,
  24. default: false
  25. },
  26. allowClear:{
  27. type: Boolean,
  28. default: true
  29. },
  30. id: {
  31. type: String,
  32. default: ''
  33. },
  34. placeholder: {
  35. type: String,
  36. default: '请选择仓库'
  37. },
  38. disabled: {
  39. type: Boolean,
  40. default: false
  41. },
  42. modeType: {
  43. type: String,
  44. default: 'default'
  45. }
  46. },
  47. data () {
  48. return {
  49. defaultVal: this.value,
  50. warehouseData: [],
  51. pageNo: 1,
  52. pageSize: 1000
  53. }
  54. },
  55. mounted () {
  56. this.$store.state.app.defWarehouse = null
  57. this.$store.state.app.isWarehouse = false
  58. this.getWarehouse()
  59. },
  60. watch: {
  61. value (newValue, oldValue) {
  62. this.defaultVal = newValue
  63. }
  64. },
  65. methods: {
  66. filterOption (input, option) {
  67. return (
  68. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  69. )
  70. },
  71. handleChange (value) {
  72. this.defaultVal = value
  73. this.$emit('input', value)
  74. this.$emit('change', value)
  75. },
  76. // 获取仓库列表
  77. getWarehouse () {
  78. const ajaxName = this.isPermission ? queryAuthWarehouse : warehouseAllList
  79. ajaxName({}).then(res => {
  80. if (res.status == 200) {
  81. this.$store.state.app.isWarehouse = res.data && res.data.length > 1
  82. const defWarehouse = res.data.find(item => item.defaultFlag == 1)
  83. this.$store.state.app.defWarehouse = this.isPermission ? res.data && res.data[0] : defWarehouse
  84. this.warehouseData = res.data || []
  85. } else {
  86. this.$store.state.app.isWarehouse = false
  87. this.$store.state.app.defWarehouse = null
  88. this.warehouseData = []
  89. }
  90. })
  91. },
  92. clearData () {
  93. this.handleChange([])
  94. }
  95. }
  96. }
  97. export default warehouse