Newer
Older
<new-rent v-if="confirm" :newRentBox="pushItem"> </new-rent>
<div v-if="noPicture" class="md:grid md:place-items-center md:h-screen">
<img
:src="require('@/assets/default-product.png')"
alt="No image found"
/>
<ImageCarousel :images="pictures"></ImageCarousel>
</div>
<!-- Product info -->
<div
class="max-w-2xl mx-auto pt-10 pb-16 px-4 sm:px-6 lg:max-w-7xl lg:pt-16 lg:pb-24 lg:px-8 lg:grid lg:grid-cols-3 lg:grid-rows-[auto,auto,1fr] lg:gap-x-8"
>
<div class="lg:col-span-2 lg:border-r lg:border-gray-200 lg:pr-8">
<h1
class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl"
>
{{ item.title }}
</h1>
</div>
<!-- TODO make this component render elements differently depending on screen size -->
<div
class="py-10 lg:pt-6 lg:pb-16 lg:col-start-1 lg:col-span-2 lg:border-r lg:border-gray-200 lg:pr-8"
>
<!-- Description and details -->
<h3 class="text-base font-semibold text-gray-900">Pris per dag</h3>
<div class="space-y-6">
<p class="text-2xl font-medium text-gray-900">
{{ item.pricePerDay }} kr
</p>
</div>
</div>
<div>
<div class="mt-4 space-y-6">
<p class="text-sm text-gray-600">{{ item.description }}</p>
</div>
</div>
<div>
<div class="mt-4 space-y-6">
<p class="text-base font-semibold text-gray-900">
{{ item.address }}
</p>
</div>
</div>
<UserListItemCard
:buttons="['chat']"
:user="userForId"
></UserListItemCard>
</div>

Håkon Eilertsen Røskaft
committed
<h3 class="text-base font-base text-gray-900">Tidspunkter</h3>
<div>
<p class="text-sm text-gray-900">
<DatepickerRange
@value="setDate"
:messageOnDisplay="dateMessage"
</p>
</div>
</div>
<div class="mt-2 space-y-2">
<p class="text-xl font-semibold text-gray-900">
Total pris: {{ totPrice }} kr
class="px-4 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-200 transform bg-gray-500 rounded-md focus:outline-none focus:ring focus:ring-opacity-80"

Håkon Eilertsen Røskaft
committed
v-bind:class="{ colorChange: allowForRent }"
<!-- This button should send you to the rent page -->
</button>
</div>
</div>
</div>
</div>
</template>
<script>
import NewRent from "@/components/RentingComponents/NewRent.vue";
import {
getItem,
getItemPictures,
getAvailableTimesForListing,
} from "@/utils/apiutil";
import ImageCarousel from "@/components/RentingComponents/ImageCarousel.vue";
import UserListItemCard from "@/components/UserProfileComponents/UserListItemCard.vue";
import DatepickerRange from "@/components/TimepickerComponents/DatepickerRange/DatepickerRange.vue";
export default {
name: "ItemInfo",
data() {
return {
item: {
listingID: 0,
title: "",
description: "",
pricePerDay: 0,
address: "",
userID: 0,
categoryNames: [],
communityIDs: [],
listingID: 157,
title: "Heii",
price: 56,
fromTime: "",
toTime: "",
},
images: [
{
listingID: 0,
picture: "",
],
pictures: [],
noPicture: true,
rentingEndDate: null,
totPrice: 0,
dateMessage: "Venligst velg dato for leieperioden",

Håkon Eilertsen Røskaft
committed
allowForRent: false,
};
},
components: {
ImageCarousel,
UserListItemCard,
DatepickerRange,
},
methods: {
this.pushItem.listingID = this.item.listingID;
this.pushItem.fromTime = this.rentingStartDate;
this.pushItem.toTime = this.rentingEndDate;
this.pushItem.title = this.item.title;
this.pushItem.price = this.totPrice;
this.pushItem.renterId = this.item.userID;
async getItem() {
let id = this.$router.currentRoute.value.params.id;
this.item = await getItem(id);
this.totPrice = this.item.pricePerDay;
async getItemPictures() {
let id = this.$router.currentRoute.value.params.id;
this.images = await getItemPictures(id);
this.noPicture = false;
for (let i = 0; i < this.images.length; i++) {
let oneImage = {
src: this.images[i].picture,
//How do i make this accurate to the image?
alt: "An image",
};
this.pictures.push(oneImage);
//TODO fixs so each image get a correct alt text.
this.userForId = await UserService.getUserFromId(userId);
async getAvailableTimesForListing() {
let datesTakenInMilliseconds = await getAvailableTimesForListing(
this.item.listingID
);
for (var i = 0; i < datesTakenInMilliseconds.length; i++) {
let oneArray = datesTakenInMilliseconds[i];
let bigArray = [];
let startDate = new Date(oneArray[0]);
let endDate = new Date(oneArray[1]);
bigArray.push(startDate);
bigArray.push(endDate);
}
},
setDate(dateOfsomthing) {
if (dateOfsomthing.startDate == null || dateOfsomthing.endDate == null) {

Håkon Eilertsen Røskaft
committed
this.totPrice = this.item.pricePerDay;
this.allowForRent = false;
} else {
this.rentingStartDate = dateOfsomthing.startDate;
this.rentingEndDate = dateOfsomthing.endDate;
this.calculateTotPrice();
this.allowForRent = true;
}
},
calculateTotPrice() {
let amountOfDays = this.rentingEndDate - this.rentingStartDate;
amountOfDays = amountOfDays / 86400000;
this.totPrice = this.item.pricePerDay * amountOfDays;

Håkon Eilertsen Røskaft
committed
},
},
async beforeMount() {
await this.getItemPictures();
await this.getItem();
await this.getUser(this.item.userID);
};
</script>

Håkon Eilertsen Røskaft
committed
<style>
.colorChange {
background-color: #004aad;
}
.colorChange:hover {

Håkon Eilertsen Røskaft
committed
}
</style>