import { queryAuthWarehouse, warehouseAllList } from '@/api/warehouse' const warehouse = { template: ` {{ item.name }} `, props: { value: { type: [String, Array], defatut: '' }, isPermission: {// false无权限 true有权限 type: Boolean, default: false }, allowClear:{ type: Boolean, default: true }, id: { type: String, default: '' }, placeholder: { type: String, default: '请选择仓库' }, disabled: { type: Boolean, default: false }, modeType: { type: String, default: 'default' } }, data () { return { defaultVal: this.value, warehouseData: [], pageNo: 1, pageSize: 1000 } }, mounted () { if(this.isPermission){ this.$store.state.app.defWarehouse = null this.$store.state.app.isWarehouse = false } this.getWarehouse() }, watch: { value (newValue, oldValue) { this.defaultVal = newValue } }, methods: { filterOption (input, option) { return ( option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 ) }, handleChange (value) { this.defaultVal = value this.$emit('input', value) this.$emit('change', value) }, // 获取仓库列表 getWarehouse () { const ajaxName = this.isPermission ? queryAuthWarehouse : warehouseAllList ajaxName({}).then(res => { if (res.status == 200) { if(this.isPermission){ this.$store.state.app.isWarehouse = res.data && res.data.length > 1 const defWarehouse = res.data.find(item => item.defaultFlag == 1) this.$store.state.app.defWarehouse = this.isPermission ? res.data && res.data[0] : defWarehouse } this.warehouseData = res.data || [] } else { if(this.isPermission){ this.$store.state.app.isWarehouse = false this.$store.state.app.defWarehouse = null } this.warehouseData = [] } this.$emit('load') }) }, clearData () { this.handleChange([]) } } } export default warehouse