chooseWarehouse.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if(this.isPermission){
  57. this.$store.state.app.defWarehouse = null
  58. this.$store.state.app.isWarehouse = false
  59. }
  60. this.getWarehouse()
  61. },
  62. watch: {
  63. value (newValue, oldValue) {
  64. this.defaultVal = newValue
  65. }
  66. },
  67. methods: {
  68. filterOption (input, option) {
  69. return (
  70. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  71. )
  72. },
  73. handleChange (value) {
  74. this.defaultVal = value
  75. this.$emit('input', value)
  76. this.$emit('change', value)
  77. },
  78. // 获取仓库列表
  79. getWarehouse () {
  80. const ajaxName = this.isPermission ? queryAuthWarehouse : warehouseAllList
  81. ajaxName({}).then(res => {
  82. if (res.status == 200) {
  83. // 有权限控制的
  84. if(this.isPermission){
  85. this.$store.state.app.isWarehouse = res.data && res.data.length > 1
  86. this.$store.state.app.defWarehouse = res.data && res.data[0]
  87. }
  88. this.warehouseData = res.data || []
  89. } else {
  90. if(this.isPermission){
  91. this.$store.state.app.isWarehouse = false
  92. this.$store.state.app.defWarehouse = null
  93. }
  94. this.warehouseData = []
  95. }
  96. this.$emit('load')
  97. })
  98. },
  99. clearData () {
  100. this.handleChange([])
  101. }
  102. }
  103. }
  104. export default warehouse