| 1 | <template> |
| 2 | <div class="soc-assets-list"> |
| 3 | <n-spin :show="loadingAssets" class="min-h-14"> |
| 4 | <div class="flex flex-col gap-2 px-7 py-4 pb-0"> |
| 5 | <div v-if="assetsState" class="box"> |
| 6 | State: |
| 7 | <code>{{ assetsState.object_state }}</code> |
| 8 | </div> |
| 9 | <div v-if="assetsState" class="box"> |
| 10 | Last update: |
| 11 | <code>{{ formatDateTime(assetsState.object_last_update) }}</code> |
| 12 | </div> |
| 13 | </div> |
| 14 | <div v-if="assetsList?.length" class="flex flex-col gap-2 p-7"> |
| 15 | <SocCaseAssetsItem v-for="asset of assetsList" :key="asset.asset_id" :asset /> |
| 16 | </div> |
| 17 | <template v-else> |
| 18 | <n-empty v-if="!loadingAssets" description="No items found" class="h-48 justify-center" /> |
| 19 | </template> |
| 20 | </n-spin> |
| 21 | </div> |
| 22 | </template> |
| 23 | |
| 24 | <script setup lang="ts"> |
| 25 | import type { SocCaseAsset, SocCaseAssetsState } from "@/types/soc/asset.d" |
| 26 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 27 | import { onBeforeMount, ref } from "vue" |
| 28 | import Api from "@/api" |
| 29 | import { useSettingsStore } from "@/stores/settings" |
| 30 | import dayjs from "@/utils/dayjs" |
| 31 | import SocCaseAssetsItem from "./SocCaseAssetsItem.vue" |
| 32 | |
| 33 | const { caseId } = defineProps<{ caseId: string | number }>() |
| 34 | |
| 35 | const loadingAssets = ref(false) |
| 36 | const message = useMessage() |
| 37 | |
| 38 | const assetsList = ref<SocCaseAsset[] | null>(null) |
| 39 | const assetsState = ref<SocCaseAssetsState | null>(null) |
| 40 | |
| 41 | const dFormats = useSettingsStore().dateFormat |
| 42 | |
| 43 | function formatDateTime(timestamp: string | number | Date, utc: boolean = true): string { |
| 44 | return dayjs(timestamp).utc(utc).format(dFormats.datetimesec) |
| 45 | } |
| 46 | |
| 47 | function getAssets() { |
| 48 | loadingAssets.value = true |
| 49 | |
| 50 | Api.soc |
| 51 | .getAssetsByCase(caseId.toString()) |
| 52 | .then(res => { |
| 53 | if (res.data.success) { |
| 54 | assetsList.value = res.data?.assets || null |
| 55 | assetsState.value = res.data?.state || null |
| 56 | } else { |
| 57 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 58 | } |
| 59 | }) |
| 60 | .catch(err => { |
| 61 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 62 | }) |
| 63 | .finally(() => { |
| 64 | loadingAssets.value = false |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | onBeforeMount(() => { |
| 69 | getAssets() |
| 70 | }) |
| 71 | </script> |