|
| 1 | +<template> |
| 2 | + <!-- eslint-disable max-len --> |
| 3 | + <div v-bind:class="{ |
| 4 | + 'card': true, |
| 5 | + 'flex w-full': true, |
| 6 | + 'ml-1': true, |
| 7 | + 'flex-col': true, |
| 8 | + 'justify-end items-start': true, |
| 9 | + 'shadow-inner': true, |
| 10 | + 'recommendation-card': true, |
| 11 | + 'rounded-md': true, |
| 12 | + 'mb-2': true, |
| 13 | + 'ml-2': index % 2 === 0}" |
| 14 | + v-bind:style="{ |
| 15 | + 'background-repeat': 'no-repeat', |
| 16 | + 'background-position': 'center center', |
| 17 | + 'background-size' :'cover', |
| 18 | + 'background-image': 'url(' + getPrimaryImage() + ')'}"> |
| 19 | + <div class="p-8 text-white"> |
| 20 | + <div class="flex items-center"> |
| 21 | + <img v-if="this.recommendation.is_online" class="w-3 h-3" src="../../../assets/recommendations/online.png"> |
| 22 | + <img v-else class="w-3 h-3" src="../../../assets/recommendations/offline.png"> |
| 23 | + <h1 v-if="this.recommendation.is_online" class="text-lg ml-2 leading-none">online</h1> |
| 24 | + <h1 v-else class="text-lg ml-2 leading-none">offline</h1> |
| 25 | + </div> |
| 26 | + <div class="flex items-end my-2"> |
| 27 | + <h1 class="text-4xl font-bold leading-none">{{this.recommendation.first_name}}</h1> |
| 28 | + <h1 class="text-2xl ml-2 leading-none mb-1">24</h1> |
| 29 | + </div> |
| 30 | + <h1 class="text-lg">{{getDistance()}}km away</h1> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script> |
| 36 | +/* eslint-disable no-else-return */ |
| 37 | +
|
| 38 | +export default { |
| 39 | + props: ['recommendation', 'index'], |
| 40 | + methods: { |
| 41 | + getPrimaryImage() { |
| 42 | + const userImages = this.recommendation.images; |
| 43 | + let imageForShowcase; |
| 44 | + for (let i = 0; i < userImages.length; i += 1) { |
| 45 | + if (userImages[i].is_primary) { |
| 46 | + imageForShowcase = userImages[i].link; |
| 47 | + } else if (!userImages[i].is_primary && !imageForShowcase) { |
| 48 | + imageForShowcase = userImages[i].link; |
| 49 | + } |
| 50 | + } |
| 51 | + console.log(imageForShowcase); |
| 52 | + if (imageForShowcase) { |
| 53 | + return imageForShowcase; |
| 54 | + } |
| 55 | + if (this.recommendation.gender === 'male') { |
| 56 | + const number = Math.floor(Math.random() * 11); |
| 57 | + if (number % 2 === 0) { |
| 58 | + return '../../../assets/recommendations/avatars/man1.png'; |
| 59 | + } |
| 60 | + return '../../../assets/recommendations/avatars/man2.png'; |
| 61 | + } else if (this.recommendation.gender === 'female') { |
| 62 | + const number = Math.floor(Math.random() * 11); |
| 63 | + if (number % 2 === 0) { |
| 64 | + return '../../../assets/recommendations/avatars/woman1.png'; |
| 65 | + } |
| 66 | + return '../../../assets/recommendations/avatars/woman2.png'; |
| 67 | + } |
| 68 | + return '../../../assets/recommendations/avatars/other.png'; |
| 69 | + }, |
| 70 | + getDistance() { |
| 71 | + return Math.floor(this.recommendation.distance); |
| 72 | + }, |
| 73 | + }, |
| 74 | + created() { |
| 75 | + console.log(this.index); |
| 76 | + }, |
| 77 | +}; |
| 78 | +</script> |
| 79 | + |
| 80 | +<style scoped> |
| 81 | +.recommendation-card { |
| 82 | + /*width: 24rem;*/ |
| 83 | + height: 32rem; |
| 84 | + box-shadow: inset 0 -8rem 1rem rgba(0, 0, 0, 0.3); |
| 85 | +} |
| 86 | +@screen md { |
| 87 | + .card { |
| 88 | + width: 48%; |
| 89 | + } |
| 90 | +} |
| 91 | +</style> |
0 commit comments