gaoluyang
2026-08-07 a3057955f855b8a266c017df00645845e7471410
src/views/wls/stocktaking/plan/components/condition-value-input.vue
@@ -1,7 +1,7 @@
<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';
@@ -24,16 +24,19 @@
  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 },
  ];
@@ -44,6 +47,9 @@
  '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>(); // 库位选择器临时数据:选库区后传给库位选择器
@@ -53,6 +59,7 @@
/** 通用选择器变化:回填条件值编码、名称 */
function handleSelectorChange(item?: any) {
  emit('update:modelValue', item?.id);
  emit('update:value', item?.id);
  emit('valueChange', {
    valueId: item?.id,
    valueCode: item?.code || '',
@@ -63,6 +70,7 @@
/** 批次选择器变化 */
function handleBatchChange(batch?: any) {
  emit('update:modelValue', batch?.id);
  emit('update:value', batch?.id);
  emit('valueChange', {
    valueId: batch?.id,
    valueCode: batch?.code || '',
@@ -75,6 +83,7 @@
  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),
@@ -85,6 +94,7 @@
/** 库区仓库选择回调:清空库区 */
function handleLocationWarehouseChange() {
  emit('update:modelValue', undefined);
  emit('update:value', undefined);
  emit('valueChange', { valueId: undefined, valueCode: '', valueName: '' });
}
@@ -92,12 +102,14 @@
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: '' });
}
@@ -109,14 +121,14 @@
      : 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;
  }
@@ -139,7 +151,7 @@
<template>
  <WmWarehouseSelect
    v-if="type === WlsStockTakingParamTypeEnum.WAREHOUSE"
    :model-value="modelValue"
    :model-value="effectiveValue"
    @change="handleSelectorChange"
  />
  <div
@@ -153,7 +165,7 @@
    />
    <WmWarehouseLocationSelect
      v-if="locationWarehouseId"
      :model-value="modelValue"
      :model-value="effectiveValue"
      :warehouse-id="locationWarehouseId"
      placeholder="请选择库区"
      @change="handleSelectorChange"
@@ -177,7 +189,7 @@
    />
    <WmWarehouseAreaSelect
      v-if="areaLocationId"
      :model-value="modelValue"
      :model-value="effectiveValue"
      :location-id="areaLocationId"
      placeholder="请选择库位"
      @change="handleSelectorChange"
@@ -185,12 +197,12 @@
  </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