zhou zhou
昨天 1553782fd262f97a336fecc8b38f8f309fc08ae6
rsf-design/src/views/basic-info/warehouse-areas/index.vue
@@ -12,7 +12,7 @@
      <ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
        <template #left>
          <ElSpace wrap>
            <ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增库区</ElButton>
            <ElButton v-auth="'add'" @click="openWarehouseAreasDialog('add')" v-ripple>新增库区</ElButton>
            <ElButton
              v-auth="'delete'"
              type="danger"
@@ -102,6 +102,8 @@
  const shipperOptions = ref([])
  const supplierOptions = ref([])
  const typeOptions = ref([])
  const companyOptionsLoaded = ref(false)
  const companyOptionsLoading = ref(null)
  let handleDeleteAction = null
  const searchItems = computed(() => [
@@ -182,6 +184,7 @@
  async function openEditDialog(row) {
    try {
      await ensureCompanyOptions()
      const detail = await guardRequestWithMessage(fetchWarehouseAreasDetail(row.id), {}, {
        timeoutMessage: '库区详情加载超时,已停止等待'
      })
@@ -189,6 +192,11 @@
    } catch (error) {
      ElMessage.error(error?.message || '获取库区详情失败')
    }
  }
  async function openWarehouseAreasDialog(type, record) {
    await ensureCompanyOptions()
    showDialog(type, record)
  }
  const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData, refreshCreate, refreshUpdate, refreshRemove } =
@@ -251,6 +259,43 @@
    resetSearchParams()
  }
  async function ensureCompanyOptions() {
    if (companyOptionsLoaded.value) {
      return
    }
    if (companyOptionsLoading.value) {
      await companyOptionsLoading.value
      return
    }
    companyOptionsLoading.value = (async () => {
      const records = await guardRequestWithMessage(fetchCompanysList(), [], {
        timeoutMessage: '往来企业选项加载超时,已停止等待'
      })
      const normalizedRecords = defaultResponseAdapter(records).records
      shipperOptions.value = normalizedRecords
        .filter((item) => item.type === 'shipper')
        .map((item) => ({
          label: item.name || item.code || `货主 ${item.id}`,
          value: item.id
        }))
      supplierOptions.value = normalizedRecords
        .filter((item) => item.type === 'supplier')
        .map((item) => ({
          label: item.name || item.code || `供应商 ${item.id}`,
          value: item.id
        }))
      companyOptionsLoaded.value = true
    })()
    try {
      await companyOptionsLoading.value
    } finally {
      companyOptionsLoading.value = null
    }
  }
  async function loadWarehouseOptions() {
    const records = await guardRequestWithMessage(fetchWarehouseList(), [], {
      timeoutMessage: '仓库选项加载超时,已停止等待'
@@ -259,25 +304,6 @@
      label: item.name || item.code || `仓库 ${item.id}`,
      value: item.id
    }))
  }
  async function loadCompanyOptions() {
    const records = await guardRequestWithMessage(fetchCompanysList(), [], {
      timeoutMessage: '往来企业选项加载超时,已停止等待'
    })
    const normalizedRecords = defaultResponseAdapter(records).records
    shipperOptions.value = normalizedRecords
      .filter((item) => item.type === 'shipper')
      .map((item) => ({
        label: item.name || item.code || `货主 ${item.id}`,
        value: item.id
      }))
    supplierOptions.value = normalizedRecords
      .filter((item) => item.type === 'supplier')
      .map((item) => ({
        label: item.name || item.code || `供应商 ${item.id}`,
        value: item.id
      }))
  }
  async function loadTypeOptions() {
@@ -298,6 +324,6 @@
  }
  onMounted(async () => {
    await Promise.all([loadWarehouseOptions(), loadCompanyOptions(), loadTypeOptions(), getData()])
    await Promise.all([loadWarehouseOptions(), loadTypeOptions(), getData()])
  })
</script>