gaoluyang
2 天以前 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
src/views/wls/warehouse/components/location-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 { getWarehouseLocationSimpleList } from '#/api/mes/wm/warehouse/location';
@@ -73,11 +73,21 @@
  },
);
/** 仓库变更或初始化时重新加载库区列表 */
/** 仓库变更时清空已选库区并重新加载列表 */
watchEffect(async () => {
  if (!props.warehouseId) {
    allList.value = [];
    return;
  }
  allList.value = await getWarehouseLocationSimpleList(props.warehouseId);
  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>
@@ -99,14 +109,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>