2022-09-06 18:32:13 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
definePageMeta({
|
2022-09-09 22:46:53 +00:00
|
|
|
layout: "home",
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const api = useUserApi();
|
|
|
|
const toast = useNotifier();
|
|
|
|
|
|
|
|
const itemId = computed<string>(() => route.params.id as string);
|
|
|
|
const preferences = useViewPreferences();
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
const { data: item, refresh } = useAsyncData(itemId.value, async () => {
|
2022-09-06 18:32:13 +00:00
|
|
|
const { data, error } = await api.items.get(itemId.value);
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Failed to load item");
|
|
|
|
navigateTo("/home");
|
2022-09-06 18:32:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
// Trigger Refresh on navigate
|
|
|
|
onMounted(() => {
|
|
|
|
refresh();
|
|
|
|
});
|
|
|
|
|
2022-09-06 18:32:13 +00:00
|
|
|
const itemSummary = computed(() => {
|
|
|
|
return {
|
2022-09-09 22:46:53 +00:00
|
|
|
Description: item.value?.description || "",
|
|
|
|
"Serial Number": item.value?.serialNumber || "",
|
|
|
|
"Model Number": item.value?.modelNumber || "",
|
|
|
|
Manufacturer: item.value?.manufacturer || "",
|
|
|
|
Notes: item.value?.notes || "",
|
2022-09-12 22:47:27 +00:00
|
|
|
Insured: item.value?.insured ? "Yes" : "No",
|
2022-09-09 22:46:53 +00:00
|
|
|
Attachments: "", // TODO: Attachments
|
2022-09-06 18:32:13 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-09-09 18:20:38 +00:00
|
|
|
const showWarranty = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
return validDate(item.value?.warrantyExpires);
|
2022-09-09 18:20:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const warrantyDetails = computed(() => {
|
2022-09-12 22:47:27 +00:00
|
|
|
const payload = {
|
|
|
|
"Lifetime Warranty": item.value?.lifetimeWarranty ? "Yes" : "No",
|
|
|
|
};
|
2022-09-09 18:20:38 +00:00
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
if (showWarranty.value) {
|
2022-09-09 22:46:53 +00:00
|
|
|
payload["Warranty Expires"] = item.value?.warrantyExpires || "";
|
2022-09-09 18:20:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
payload["Warranty Details"] = item.value?.warrantyDetails || "";
|
2022-09-09 18:20:38 +00:00
|
|
|
|
|
|
|
return payload;
|
|
|
|
});
|
|
|
|
|
2022-09-06 18:32:13 +00:00
|
|
|
const showPurchase = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return item.value?.purchaseFrom || item.value?.purchasePrice;
|
|
|
|
});
|
|
|
|
|
|
|
|
const purchaseDetails = computed(() => {
|
|
|
|
return {
|
2022-09-09 22:46:53 +00:00
|
|
|
"Purchased From": item.value?.purchaseFrom || "",
|
2022-09-12 22:47:27 +00:00
|
|
|
"Purchased Price": item.value?.purchasePrice ? fmtCurrency(item.value.purchasePrice) : "",
|
2022-09-09 22:46:53 +00:00
|
|
|
"Purchased At": item.value?.purchaseTime || "",
|
2022-09-06 18:32:13 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const showSold = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item.value?.soldTo || item.value?.soldPrice;
|
|
|
|
});
|
|
|
|
|
|
|
|
const soldDetails = computed(() => {
|
|
|
|
return {
|
2022-09-09 22:46:53 +00:00
|
|
|
"Sold To": item.value?.soldTo || "",
|
2022-09-12 22:47:27 +00:00
|
|
|
"Sold Price": item.value?.soldPrice ? fmtCurrency(item.value.soldPrice) : "",
|
2022-09-09 22:46:53 +00:00
|
|
|
"Sold At": item.value?.soldTime || "",
|
2022-09-06 18:32:13 +00:00
|
|
|
};
|
|
|
|
});
|
2022-09-09 06:05:23 +00:00
|
|
|
|
|
|
|
const confirm = useConfirm();
|
|
|
|
|
|
|
|
async function deleteItem() {
|
2022-09-09 22:46:53 +00:00
|
|
|
const confirmed = await confirm.reveal("Are you sure you want to delete this item?");
|
2022-09-09 06:05:23 +00:00
|
|
|
|
|
|
|
if (!confirmed.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { error } = await api.items.delete(itemId.value);
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Failed to delete item");
|
2022-09-09 06:05:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.success("Item deleted");
|
|
|
|
navigateTo("/home");
|
2022-09-09 06:05:23 +00:00
|
|
|
}
|
2022-09-06 18:32:13 +00:00
|
|
|
</script>
|
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
<template>
|
2022-09-12 22:47:27 +00:00
|
|
|
<BaseContainer v-if="item" class="pb-8">
|
2022-09-09 06:05:23 +00:00
|
|
|
<section class="px-3">
|
|
|
|
<div class="flex justify-between items-center">
|
|
|
|
<div class="form-control"></div>
|
|
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 gap-3">
|
|
|
|
<BaseDetails :details="itemSummary">
|
|
|
|
<template #title>
|
|
|
|
<BaseSectionHeader v-if="item" class="pb-0">
|
|
|
|
<Icon name="mdi-package-variant" class="-mt-1 mr-2 text-gray-600" />
|
|
|
|
<span class="text-gray-600">
|
|
|
|
{{ item.name }}
|
|
|
|
</span>
|
2022-09-12 22:47:27 +00:00
|
|
|
<p class="text-sm text-gray-600 font-bold pb-0 mb-0">
|
|
|
|
{{ item.location.name }} - Quantity {{ item.quantity }}
|
|
|
|
</p>
|
2022-09-09 06:05:23 +00:00
|
|
|
<template #after>
|
2022-09-12 22:47:27 +00:00
|
|
|
<div v-if="item.labels && item.labels.length > 0" class="flex flex-wrap gap-3 mt-3">
|
2022-09-09 22:46:53 +00:00
|
|
|
<LabelChip v-for="label in item.labels" :key="label.id" class="badge-primary" :label="label" />
|
2022-09-09 06:05:23 +00:00
|
|
|
</div>
|
2022-09-12 22:47:27 +00:00
|
|
|
<div class="modal-action mt-3">
|
2022-09-09 06:05:23 +00:00
|
|
|
<label class="label cursor-pointer mr-auto">
|
2022-09-09 22:46:53 +00:00
|
|
|
<input v-model="preferences.showEmpty" type="checkbox" class="toggle toggle-primary" />
|
2022-09-09 06:05:23 +00:00
|
|
|
<span class="label-text ml-4"> Show Empty </span>
|
|
|
|
</label>
|
|
|
|
<BaseButton size="sm" :to="`/item/${itemId}/edit`">
|
|
|
|
<template #icon>
|
|
|
|
<Icon name="mdi-pencil" />
|
|
|
|
</template>
|
|
|
|
Edit
|
|
|
|
</BaseButton>
|
|
|
|
<BaseButton size="sm" @click="deleteItem">
|
|
|
|
<template #icon>
|
|
|
|
<Icon name="mdi-delete" />
|
|
|
|
</template>
|
|
|
|
Delete
|
|
|
|
</BaseButton>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</BaseSectionHeader>
|
|
|
|
</template>
|
|
|
|
<template #Attachments>
|
|
|
|
<ul role="list" class="divide-y divide-gray-400 rounded-md border border-gray-400">
|
|
|
|
<li class="flex items-center justify-between py-3 pl-3 pr-4 text-sm">
|
|
|
|
<div class="flex w-0 flex-1 items-center">
|
|
|
|
<Icon name="mdi-paperclip" class="h-5 w-5 flex-shrink-0 text-gray-400" aria-hidden="true" />
|
|
|
|
<span class="ml-2 w-0 flex-1 truncate">User Guide.pdf</span>
|
|
|
|
</div>
|
|
|
|
<div class="ml-4 flex-shrink-0">
|
|
|
|
<a href="#" class="font-medium">Download</a>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li class="flex items-center justify-between py-3 pl-3 pr-4 text-sm">
|
|
|
|
<div class="flex w-0 flex-1 items-center">
|
|
|
|
<Icon name="mdi-paperclip" class="h-5 w-5 flex-shrink-0 text-gray-400" aria-hidden="true" />
|
|
|
|
<span class="ml-2 w-0 flex-1 truncate">Purchase Receipts.pdf</span>
|
|
|
|
</div>
|
|
|
|
<div class="ml-4 flex-shrink-0">
|
|
|
|
<a href="#" class="font-medium">Download</a>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
</BaseDetails>
|
2022-09-09 22:46:53 +00:00
|
|
|
<BaseDetails v-if="showPurchase" :details="purchaseDetails">
|
2022-09-09 06:05:23 +00:00
|
|
|
<template #title> Purchase Details </template>
|
2022-09-12 22:47:27 +00:00
|
|
|
<template #PurchasedAt>
|
|
|
|
<DateTime :date="item.purchaseTime" />
|
|
|
|
</template>
|
2022-09-09 06:05:23 +00:00
|
|
|
</BaseDetails>
|
2022-09-09 22:46:53 +00:00
|
|
|
<BaseDetails v-if="showWarranty" :details="warrantyDetails">
|
2022-09-09 18:20:38 +00:00
|
|
|
<template #title> Warranty </template>
|
2022-09-12 22:47:27 +00:00
|
|
|
<template #WarrantyExpires>
|
|
|
|
<DateTime :date="item.warrantyExpires" />
|
|
|
|
</template>
|
2022-09-09 18:20:38 +00:00
|
|
|
</BaseDetails>
|
2022-09-09 22:46:53 +00:00
|
|
|
<BaseDetails v-if="showSold" :details="soldDetails">
|
2022-09-09 18:20:38 +00:00
|
|
|
<template #title> Sold </template>
|
2022-09-12 22:47:27 +00:00
|
|
|
<template #SoldAt>
|
|
|
|
<DateTime :date="item.soldTime" />
|
|
|
|
</template>
|
2022-09-09 06:05:23 +00:00
|
|
|
</BaseDetails>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</BaseContainer>
|
|
|
|
</template>
|