zhou zhou
5 小时以前 450c9d39c6eb3765642f977512202e3240ac9b03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
  <div class="delivery-item-page art-full-height">
    <ElCard v-if="activeSourceSummary" class="mb-3">
      <div class="flex items-center justify-between gap-3">
        <div class="flex items-center gap-2 text-sm text-[var(--art-text-gray-600)]">
          <span class="font-medium text-[var(--art-text-gray-900)]">{{
            t('pages.orders.deliveryItem.sourceTitle')
          }}</span>
          <span>{{
            t('pages.orders.deliveryItem.sourceLabel', { id: activeSourceSummary.deliveryId })
          }}</span>
        </div>
        <ElButton link type="primary" @click="handleClearSourceFilter">{{
          t('common.actions.viewAll')
        }}</ElButton>
      </div>
    </ElCard>
 
    <DeliveryItemManagePanel
      :delivery-id="searchForm.deliveryId"
      :can-add="hasAuth('add')"
      :can-edit="hasAuth('update')"
      :can-delete="hasAuth('delete')"
    />
  </div>
</template>
 
<script setup>
  import { computed, onMounted, ref, watch } from 'vue'
  import { useI18n } from 'vue-i18n'
  import { ElButton } from 'element-plus'
  import { useRoute, useRouter } from 'vue-router'
  import { useAuth } from '@/hooks/core/useAuth'
  import DeliveryItemManagePanel from './modules/delivery-item-manage-panel.vue'
  import { createDeliveryItemSearchState } from './deliveryItemPage.helpers.js'
 
  defineOptions({ name: 'DeliveryItem' })
 
  const { t } = useI18n()
  const { hasAuth } = useAuth()
  const route = useRoute()
  const router = useRouter()
  const searchForm = ref(createDeliveryItemSearchState())
 
  const activeSourceSummary = computed(() => {
    if (
      searchForm.value.deliveryId === '' ||
      searchForm.value.deliveryId === undefined ||
      searchForm.value.deliveryId === null
    ) {
      return null
    }
    return {
      deliveryId: searchForm.value.deliveryId
    }
  })
 
  function applyRouteSearch() {
    const deliveryId = route.query.deliveryId
    if (deliveryId === undefined || deliveryId === null || deliveryId === '') {
      return
    }
    searchForm.value.deliveryId = Number.isFinite(Number(deliveryId))
      ? Number(deliveryId)
      : searchForm.value.deliveryId
  }
 
  function handleClearSourceFilter() {
    searchForm.value.deliveryId = ''
    router.replace({
      path: route.path,
      query: {
        ...route.query,
        deliveryId: undefined
      }
    })
  }
 
  watch(
    () => route.query.deliveryId,
    (value) => {
      if (value === undefined || value === null || value === '') {
        return
      }
      applyRouteSearch()
    }
  )
 
  onMounted(() => {
    applyRouteSearch()
  })
</script>