| | |
| | | <script lang="ts" setup> |
| | | import type { NumberDictDataType } from '@vben/hooks'; |
| | | |
| | | import { ref, watch } from 'vue'; |
| | | import { computed, ref, watch } from 'vue'; |
| | | |
| | | import { DICT_TYPE, WlsStockTakingParamTypeEnum } from '@vben/constants'; |
| | | import { getDictOptions } from '@vben/hooks'; |
| | |
| | | defineProps<{ |
| | | modelValue?: number; |
| | | type?: number; |
| | | value?: number; |
| | | valueCode?: string; |
| | | }>(), |
| | | { |
| | | modelValue: undefined, |
| | | type: undefined, |
| | | value: undefined, |
| | | valueCode: undefined, |
| | | }, |
| | | ); |
| | | const emit = defineEmits<{ |
| | | 'update:modelValue': [value?: number]; |
| | | 'update:value': [value?: number]; |
| | | valueChange: [ |
| | | payload: { valueCode?: string; valueId?: number; valueName?: string }, |
| | | ]; |
| | |
| | | 'number', |
| | | ) as NumberDictDataType[]; |
| | | |
| | | /** 兼容 VbenForm 默认 v-model prop ('value') 和 Vue 3 标准 ('modelValue') */ |
| | | const effectiveValue = computed(() => props.value ?? props.modelValue); |
| | | |
| | | const locationWarehouseId = ref<number>(); // 库区选择器临时数据:选仓库后传给库区选择器 |
| | | const areaWarehouseId = ref<number>(); // 库位选择器临时数据:选仓库后传给库区选择器 |
| | | const areaLocationId = ref<number>(); // 库位选择器临时数据:选库区后传给库位选择器 |
| | |
| | | /** 通用选择器变化:回填条件值编码、名称 */ |
| | | function handleSelectorChange(item?: any) { |
| | | emit('update:modelValue', item?.id); |
| | | emit('update:value', item?.id); |
| | | emit('valueChange', { |
| | | valueId: item?.id, |
| | | valueCode: item?.code || '', |
| | |
| | | /** 批次选择器变化 */ |
| | | function handleBatchChange(batch?: any) { |
| | | emit('update:modelValue', batch?.id); |
| | | emit('update:value', batch?.id); |
| | | emit('valueChange', { |
| | | valueId: batch?.id, |
| | | valueCode: batch?.code || '', |
| | |
| | | qualityStatusValue.value = value; |
| | | const selected = qualityStatusOptions.find((item) => item.value === value); |
| | | emit('update:modelValue', undefined); |
| | | emit('update:value', undefined); |
| | | emit('valueChange', { |
| | | valueId: undefined, |
| | | valueCode: value === null ? '' : String(value), |
| | |
| | | /** 库区仓库选择回调:清空库区 */ |
| | | function handleLocationWarehouseChange() { |
| | | emit('update:modelValue', undefined); |
| | | emit('update:value', undefined); |
| | | emit('valueChange', { valueId: undefined, valueCode: '', valueName: '' }); |
| | | } |
| | | |
| | |
| | | function handleAreaWarehouseChange() { |
| | | areaLocationId.value = undefined; |
| | | emit('update:modelValue', undefined); |
| | | emit('update:value', undefined); |
| | | emit('valueChange', { valueId: undefined, valueCode: '', valueName: '' }); |
| | | } |
| | | |
| | | /** 库位库区选择回调:清空库位 */ |
| | | function handleAreaLocationChange() { |
| | | emit('update:modelValue', undefined); |
| | | emit('update:value', undefined); |
| | | emit('valueChange', { valueId: undefined, valueCode: '', valueName: '' }); |
| | | } |
| | | |
| | |
| | | : undefined; |
| | | return; |
| | | } |
| | | if (!props.modelValue) { |
| | | if (!effectiveValue.value) { |
| | | return; |
| | | } |
| | | if (props.type === WlsStockTakingParamTypeEnum.LOCATION) { |
| | | const location = await getWarehouseLocation(props.modelValue); |
| | | const location = await getWarehouseLocation(effectiveValue.value); |
| | | locationWarehouseId.value = location?.warehouseId; |
| | | } else if (props.type === WlsStockTakingParamTypeEnum.AREA) { |
| | | const area = await getWarehouseArea(props.modelValue); |
| | | const area = await getWarehouseArea(effectiveValue.value); |
| | | areaWarehouseId.value = area?.warehouseId; |
| | | areaLocationId.value = area?.locationId; |
| | | } |
| | |
| | | <template> |
| | | <WmWarehouseSelect |
| | | v-if="type === WlsStockTakingParamTypeEnum.WAREHOUSE" |
| | | :model-value="modelValue" |
| | | :model-value="effectiveValue" |
| | | @change="handleSelectorChange" |
| | | /> |
| | | <div |
| | |
| | | /> |
| | | <WmWarehouseLocationSelect |
| | | v-if="locationWarehouseId" |
| | | :model-value="modelValue" |
| | | :model-value="effectiveValue" |
| | | :warehouse-id="locationWarehouseId" |
| | | placeholder="请选择库区" |
| | | @change="handleSelectorChange" |
| | |
| | | /> |
| | | <WmWarehouseAreaSelect |
| | | v-if="areaLocationId" |
| | | :model-value="modelValue" |
| | | :model-value="effectiveValue" |
| | | :location-id="areaLocationId" |
| | | placeholder="请选择库位" |
| | | @change="handleSelectorChange" |
| | |
| | | </div> |
| | | <MdItemSelect |
| | | v-else-if="type === WlsStockTakingParamTypeEnum.ITEM" |
| | | :model-value="modelValue" |
| | | :model-value="effectiveValue" |
| | | @change="handleSelectorChange" |
| | | /> |
| | | <WmBatchSelect |
| | | v-else-if="type === WlsStockTakingParamTypeEnum.BATCH" |
| | | :model-value="modelValue" |
| | | :model-value="effectiveValue" |
| | | @change="handleBatchChange" |
| | | /> |
| | | <Select |