chooseWarehouse.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. isDefault: { // 是否有默认值
  47. type: Boolean,
  48. default: undefined
  49. }
  50. },
  51. data () {
  52. return {
  53. defaultVal: this.value,
  54. warehouseData: [],
  55. pageNo: 1,
  56. pageSize: 1000
  57. }
  58. },
  59. mounted () {
  60. if (this.isPermission) {
  61. this.$store.state.app.defWarehouse = null
  62. this.$store.state.app.isWarehouse = false
  63. }
  64. this.getWarehouse()
  65. },
  66. watch: {
  67. value (newValue, oldValue) {
  68. this.defaultVal = newValue
  69. }
  70. },
  71. methods: {
  72. filterOption (input, option) {
  73. return (
  74. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  75. )
  76. },
  77. handleChange (value) {
  78. this.defaultVal = value
  79. this.$emit('input', value)
  80. this.$emit('change', value)
  81. },
  82. // 获取仓库列表
  83. getWarehouse () {
  84. const ajaxName = this.isPermission ? queryAuthWarehouse : warehouseAllList
  85. ajaxName({}).then(res => {
  86. if (res.status == 200) {
  87. // 有权限控制的
  88. if (this.isPermission) {
  89. this.$store.state.app.isWarehouse = res.data && res.data.length > 1
  90. this.$store.state.app.defWarehouse = res.data && res.data[0]
  91. }
  92. this.warehouseData = res.data || []
  93. let defaultWarehouseVal = {}
  94. if (this.isDefault) {
  95. defaultWarehouseVal = res.data.find(con => {
  96. return con.defaultFlag == 1 ? con.warehouseSn : ''
  97. })
  98. this.defaultVal = defaultWarehouseVal.warehouseSn
  99. this.$emit('load', defaultWarehouseVal.warehouseSn)
  100. } else {
  101. this.$emit('load')
  102. }
  103. } else {
  104. if (this.isPermission) {
  105. this.$store.state.app.isWarehouse = false
  106. this.$store.state.app.defWarehouse = null
  107. }
  108. this.warehouseData = []
  109. }
  110. })
  111. },
  112. clearData () {
  113. this.handleChange([])
  114. }
  115. }
  116. }
  117. export default warehouse