add: sidebar anchor for similar items

v0.7
rrr-marble 3 years ago
parent 66aaa11b25
commit c7dd8b7935

@ -38,14 +38,14 @@
<va-card id="map" class="content-container map-container"> <va-card id="map" class="content-container map-container">
<item-map-component v-if="detailsLoaded" :internal_id="this.itemDetails.internal_id" <item-map-component v-if="detailsLoaded" :internal_id="this.itemDetails.internal_id"
:x_coord="this.itemDetails.x_coord" :y_coord="this.itemDetails.y_coord" /> :x_coord="this.xComputed" :y_coord="this.yComputed" />
<h3 v-else>Карта загружается</h3> <h3 v-else>Карта загружается</h3>
</va-card> </va-card>
<va-card id="similar" class="content-container" v-show="settleFinishedComputed"> <va-card id="similar" class="content-container" v-if="detailsLoaded">
<va-scroll-container vertical> <va-scroll-container vertical>
<va-card-title>Похожие образцы</va-card-title> <va-card-title>Похожие образцы</va-card-title>
<va-data-table :items="filteredSimilarItems" :columns="filteredColumns" :hoverable="true" <va-data-table :items="filteredSimilarItems" :columns="filteredColumns" :hoverable="true"
:clickable="true" @row:click="(e) => $router.push(`/items/${e.item.id}`)" :clickable="true" select-mode="single" @row:click="(e) => handleClick(e)"
class="similar-items-table" /> class="similar-items-table" />
</va-scroll-container> </va-scroll-container>
</va-card> </va-card>
@ -84,7 +84,6 @@ export default {
"category", "category",
], ],
similarItems: [], similarItems: [],
settleFinished: false,
}; };
}, },
methods: { methods: {
@ -92,7 +91,6 @@ export default {
fetch(`/api/v1/item/${this.$route.params.id}`) fetch(`/api/v1/item/${this.$route.params.id}`)
.then(res => res.json()) .then(res => res.json())
.then(data => this.itemDetails = data) .then(data => this.itemDetails = data)
.then(() => this.detailsLoaded = true)
.catch((e) => console.log(e)); .catch((e) => console.log(e));
}, },
async fetchColumnHeaders() { async fetchColumnHeaders() {
@ -126,12 +124,33 @@ export default {
{ method: 'POST', body: JSON.stringify({ fadr: this.itemDetails.fadr }), headers: { 'Content-Type': 'application/json' } }) { method: 'POST', body: JSON.stringify({ fadr: this.itemDetails.fadr }), headers: { 'Content-Type': 'application/json' } })
.then(res => res.json()) .then(res => res.json())
.then(data => this.similarItems = data) .then(data => this.similarItems = data)
.then(() => this.detailsLoaded = true)
.catch((e) => console.log(e)); .catch((e) => console.log(e));
} },
handleClick(e) {
if (e.event.ctrlKey) {
let routeData = this.$router.resolve({ name: 'item-details' });
window.open(routeData.href, '_blank');
} else {
this.detailsLoaded = false;
this.$router.replace(`/items/${e.item.id}`).then(a => {
this.fetchItemDetails();
});
}
},
}, },
created() { mounted() {
this.fetchItemDetails();
this.fetchColumnHeaders(); this.fetchColumnHeaders();
this.fetchItemDetails().then(
this.fetchSimilarItems()
);
},
watch: {
'itemDetails': function (_oldval, _newval) {
this.fetchSimilarItems()
}
}, },
computed: { computed: {
slotPreviewPath() { slotPreviewPath() {
@ -167,16 +186,20 @@ export default {
forceSimilarItemsReload() { forceSimilarItemsReload() {
// https://stackoverflow.com/questions/48641295/async-computed-in-components-vuejs // https://stackoverflow.com/questions/48641295/async-computed-in-components-vuejs
this.fetchSimilarItems(); this.fetchSimilarItems();
return this.itemDetails.fadr; for (let _i in this.itemDetails) {
return this.itemDetails.fadr;
}
return false;
}, },
filteredSimilarItems() { filteredSimilarItems() {
return [...this.similarItems].filter(item => item.internal_id !== this.itemDetails.internal_id) return [...this.similarItems].filter(item => item.internal_id !== this.itemDetails.internal_id)
}, },
settleFinishedComputed() { xComputed() {
let result = this.settleFinished ? this.settleFinished : Boolean(this.filteredSimilarItems.length); return this.itemDetails.x_coord ? this.itemDetails.x_coord : 55.75
this.settleFinished = true; },
return result yComputed() {
} return this.itemDetails.y_coord ? this.itemDetails.y_coord : 37.62
},
}, },
components: { ItemMapComponent } components: { ItemMapComponent }
} }
@ -197,6 +220,7 @@ export default {
.similar-items-table { .similar-items-table {
width: 45rem; width: 45rem;
overflow-x: hidden;
} }
.item-description { .item-description {

@ -8,7 +8,7 @@
<item-details /> <item-details />
</div> </div>
</div> </div>
<login-modal :showModal="showModal" @closeModal="showModal=false" /> <login-modal :showModal="showModal" @closeModal="showModal = false" />
</template> </template>
@ -47,6 +47,12 @@ export default {
route: "item-details", route: "item-details",
hash: "#map", hash: "#map",
}, },
{
title: "Похожие образцы",
icon: "view_list",
route: "item-details",
hash: "#similar",
},
{ {
title: "Связь с представителем", title: "Связь с представителем",
icon: "contact_page", icon: "contact_page",

Loading…
Cancel
Save