zhangwencui
4 小时以前 5f3dea3fd930afde720677fba10b6bfb2e836a18
src/views/wls/warehouse/components/area-select.vue
@@ -3,7 +3,7 @@
import { computed, ref, useAttrs, watch, watchEffect } from 'vue';
import { Select, SelectOption, Tag, Tooltip } from 'ant-design-vue';
import { Select, SelectOption, Tooltip } from 'ant-design-vue';
import { getWarehouseAreaSimpleList } from '#/api/mes/wm/warehouse/area';
@@ -73,11 +73,21 @@
  },
);
/** 库区变更或初始化时重新加载库位列表 */
/** 库区变更时清空已选库位并重新加载列表 */
watchEffect(async () => {
  if (!props.locationId) {
    allList.value = [];
    return;
  }
  allList.value = await getWarehouseAreaSimpleList(props.locationId);
  if (props.modelValue !== null) {
    selectedItem.value = allList.value.find((o) => o.id === props.modelValue);
  // 库区变更时清空已选的库位
  if (props.modelValue !== null && props.modelValue !== undefined) {
    const stillExists = allList.value.find((o) => o.id === props.modelValue);
    if (!stillExists) {
      selectedItem.value = undefined;
      emit('update:modelValue', undefined);
      emit('change', undefined);
    }
  }
});
</script>
@@ -100,14 +110,12 @@
      :disabled="disabled"
      :filter-option="filterOption"
      :placeholder="placeholder"
      :popup-match-select-width="false"
      show-search
      @change="handleChange"
    >
      <SelectOption v-for="item in allList" :key="item.id" :value="item.id">
        <div class="flex items-center gap-2">
          <span>{{ item.name }}</span>
          <Tag v-if="item.code" color="blue">编号: {{ item.code }}</Tag>
        </div>
        {{ item.name }}
      </SelectOption>
    </Select>
  </Tooltip>