2018-08-27 04:42:45 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="marketplace-page"
|
|
|
|
:data-page-name="page_name"
|
|
|
|
v-if="init || item"
|
|
|
|
>
|
|
|
|
|
|
|
|
<detail-view
|
|
|
|
:title="title"
|
|
|
|
:image="image"
|
|
|
|
:sections="sections"
|
|
|
|
:menu_items="menu_items"
|
|
|
|
:show_skeleton="init"
|
|
|
|
>
|
2018-08-27 05:19:42 +00:00
|
|
|
<detail-header-item slot="detail-header-item"
|
2018-08-27 04:42:45 +00:00
|
|
|
:value="item_subtitle"
|
|
|
|
></detail-header-item>
|
2018-08-27 05:19:42 +00:00
|
|
|
<detail-header-item slot="detail-header-item"
|
2018-08-27 04:42:45 +00:00
|
|
|
:value="item_views_and_ratings"
|
|
|
|
></detail-header-item>
|
2018-08-27 05:19:42 +00:00
|
|
|
|
|
|
|
<button slot="detail-header-item"
|
2018-08-27 14:21:36 +00:00
|
|
|
class="btn btn-primary btn-sm margin-top"
|
2018-08-27 05:19:42 +00:00
|
|
|
@click="primary_action.action"
|
|
|
|
>
|
|
|
|
{{ primary_action.label }}
|
|
|
|
</button>
|
|
|
|
|
2018-08-27 04:42:45 +00:00
|
|
|
</detail-view>
|
2018-08-27 05:19:42 +00:00
|
|
|
|
2018-08-30 10:51:26 +00:00
|
|
|
<review-area :hub_item_name="hub_item_name"></review-area>
|
2018-08-27 04:42:45 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-08-27 05:19:42 +00:00
|
|
|
import ReviewArea from '../components/ReviewArea.vue';
|
2018-08-27 04:42:45 +00:00
|
|
|
import { get_rating_html } from '../components/reviews';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'item-page',
|
2018-08-27 05:19:42 +00:00
|
|
|
components: {
|
|
|
|
ReviewArea
|
|
|
|
},
|
2018-08-27 04:42:45 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
page_name: frappe.get_route()[1],
|
2018-08-27 14:21:36 +00:00
|
|
|
hub_item_name: frappe.get_route()[2],
|
2018-08-27 04:42:45 +00:00
|
|
|
|
|
|
|
init: true,
|
|
|
|
|
|
|
|
item: null,
|
|
|
|
title: null,
|
|
|
|
image: null,
|
|
|
|
sections: [],
|
|
|
|
|
|
|
|
menu_items: [
|
2018-08-28 11:54:31 +00:00
|
|
|
{
|
|
|
|
label: __('Save Item'),
|
|
|
|
condition: !this.is_own_item,
|
|
|
|
action: this.add_to_saved_items
|
|
|
|
},
|
2018-08-27 04:42:45 +00:00
|
|
|
{
|
2018-08-30 10:05:06 +00:00
|
|
|
label: __('Report this Item'),
|
2018-08-27 04:42:45 +00:00
|
|
|
condition: !this.is_own_item,
|
|
|
|
action: this.report_item
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __('Edit Details'),
|
|
|
|
condition: this.is_own_item,
|
2018-08-30 10:38:52 +00:00
|
|
|
action: this.edit_details
|
2018-08-27 04:42:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-08-30 10:05:06 +00:00
|
|
|
label: __('Unpublish Item'),
|
2018-08-27 04:42:45 +00:00
|
|
|
condition: this.is_own_item,
|
2018-08-30 10:38:52 +00:00
|
|
|
action: this.unpublish_item
|
2018-08-27 04:42:45 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
is_own_item() {
|
|
|
|
let is_own_item = false;
|
|
|
|
if(this.item) {
|
|
|
|
if(this.item.hub_seller === hub.setting.company_email) {
|
|
|
|
is_own_item = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return is_own_item;
|
|
|
|
},
|
|
|
|
|
|
|
|
item_subtitle() {
|
|
|
|
if(!this.item) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
const dot_spacer = '<span aria-hidden="true"> · </span>';
|
|
|
|
let subtitle_items = [comment_when(this.item.creation)];
|
|
|
|
const rating = this.item.average_rating;
|
|
|
|
|
|
|
|
if (rating > 0) {
|
|
|
|
subtitle_items.push(rating + `<i class='fa fa-fw fa-star-o'></i>`)
|
|
|
|
}
|
|
|
|
|
|
|
|
subtitle_items.push(this.item.company);
|
|
|
|
|
|
|
|
return subtitle_items;
|
|
|
|
},
|
|
|
|
|
|
|
|
item_views_and_ratings() {
|
|
|
|
if(!this.item) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
let stats = __('No views yet');
|
|
|
|
if(this.item.view_count) {
|
|
|
|
const views_message = __(`${this.item.view_count} Views`);
|
|
|
|
|
|
|
|
const rating_html = get_rating_html(this.item.average_rating);
|
|
|
|
const rating_count = this.item.no_of_ratings > 0 ? `${this.item.no_of_ratings} reviews` : __('No reviews yet');
|
|
|
|
|
|
|
|
stats = [views_message, rating_html, rating_count];
|
|
|
|
}
|
|
|
|
|
|
|
|
return stats;
|
2018-08-27 05:19:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
primary_action() {
|
|
|
|
return {
|
|
|
|
label: __('Contact Seller'),
|
|
|
|
action: this.contact_seller.bind(this)
|
|
|
|
}
|
2018-08-27 04:42:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2018-08-28 11:54:31 +00:00
|
|
|
this.get_item_details();
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// To record a single view per session, (later)
|
|
|
|
// erpnext.hub.item_view_cache = erpnext.hub.item_view_cache || [];
|
|
|
|
// if (erpnext.hub.item_view_cache.includes(this.hub_item_name)) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
this.item_received.then(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
hub.call('add_item_view', {
|
|
|
|
hub_item_name: this.hub_item_name
|
|
|
|
})
|
|
|
|
// .then(() => {
|
|
|
|
// erpnext.hub.item_view_cache.push(this.hub_item_name);
|
|
|
|
// });
|
|
|
|
}, 5000);
|
|
|
|
});
|
2018-08-27 04:42:45 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2018-08-28 11:54:31 +00:00
|
|
|
get_item_details() {
|
|
|
|
this.item_received = hub.call('get_item_details', { hub_item_name: this.hub_item_name })
|
2018-08-27 04:42:45 +00:00
|
|
|
.then(item => {
|
|
|
|
this.init = false;
|
|
|
|
this.item = item;
|
|
|
|
|
|
|
|
this.build_data();
|
2018-08-30 10:38:52 +00:00
|
|
|
this.make_dialogs();
|
2018-08-27 04:42:45 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
build_data() {
|
|
|
|
this.title = this.item.item_name || this.item.name;
|
|
|
|
this.image = this.item.image;
|
|
|
|
|
|
|
|
this.sections = [
|
|
|
|
{
|
2018-08-30 10:05:06 +00:00
|
|
|
title: __('Item Description'),
|
2018-08-27 04:42:45 +00:00
|
|
|
content: this.item.description
|
|
|
|
? __(this.item.description)
|
|
|
|
: __('No description')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __('Seller Information'),
|
2018-08-30 10:51:26 +00:00
|
|
|
content: this.item.seller_description
|
|
|
|
? __(this.item.seller_description)
|
|
|
|
: __('No description')
|
2018-08-27 04:42:45 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:38:52 +00:00
|
|
|
make_dialogs() {
|
|
|
|
this.make_contact_seller_dialog();
|
2018-08-30 10:41:41 +00:00
|
|
|
this.make_report_item_dialog();
|
2018-08-27 05:19:42 +00:00
|
|
|
},
|
|
|
|
|
2018-08-28 11:54:31 +00:00
|
|
|
add_to_saved_items() {
|
2018-09-02 20:55:41 +00:00
|
|
|
hub.call('add_item_to_user_saved_items', {
|
2018-08-28 11:54:31 +00:00
|
|
|
hub_item_name: this.hub_item_name,
|
2018-09-02 20:55:41 +00:00
|
|
|
hub_user: frappe.session.user
|
2018-08-28 11:54:31 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2018-08-30 10:05:06 +00:00
|
|
|
const saved_items_link = `<b><a href="#marketplace/saved-items">${__('Saved')}</a></b>`
|
2018-08-28 11:54:31 +00:00
|
|
|
frappe.show_alert(saved_items_link);
|
|
|
|
erpnext.hub.trigger('action:item_save');
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:38:52 +00:00
|
|
|
make_contact_seller_dialog() {
|
|
|
|
this.contact_seller_dialog = new frappe.ui.Dialog({
|
2018-08-27 05:19:42 +00:00
|
|
|
title: __('Send a message'),
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
fieldname: 'to',
|
|
|
|
fieldtype: 'Read Only',
|
|
|
|
label: __('To'),
|
|
|
|
default: this.item.company
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldtype: 'Text',
|
|
|
|
fieldname: 'message',
|
|
|
|
label: __('Message')
|
|
|
|
}
|
|
|
|
],
|
|
|
|
primary_action: ({ message }) => {
|
|
|
|
if (!message) return;
|
|
|
|
|
|
|
|
hub.call('send_message', {
|
|
|
|
from_seller: hub.settings.company_email,
|
|
|
|
to_seller: this.item.hub_seller,
|
2018-08-27 14:21:36 +00:00
|
|
|
hub_item: this.item.name,
|
2018-08-27 05:19:42 +00:00
|
|
|
message
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
d.hide();
|
2018-08-27 14:21:36 +00:00
|
|
|
frappe.set_route('marketplace', 'buying', this.item.name);
|
2018-08-27 05:19:42 +00:00
|
|
|
erpnext.hub.trigger('action:send_message')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-08-30 10:38:52 +00:00
|
|
|
},
|
|
|
|
|
2018-08-30 10:41:41 +00:00
|
|
|
make_report_item_dialog() {
|
|
|
|
this.report_item_dialog = new frappe.ui.Dialog({
|
|
|
|
title: __('Report Item'),
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
label: __('Why do think this Item should be removed?'),
|
|
|
|
fieldtype: 'Text',
|
|
|
|
fieldname: 'message'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
primary_action: ({ message }) => {
|
|
|
|
hub.call('add_reported_item', { hub_item_name: this.item.name, message })
|
|
|
|
.then(() => {
|
|
|
|
d.hide();
|
|
|
|
frappe.show_alert(__('Item Reported'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:38:52 +00:00
|
|
|
contact_seller() {
|
|
|
|
this.contact_seller_dialog.show();
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:41:41 +00:00
|
|
|
report_item() {
|
|
|
|
this.report_item_dialog.show();
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:38:52 +00:00
|
|
|
edit_details() {
|
|
|
|
//
|
|
|
|
},
|
2018-08-27 05:19:42 +00:00
|
|
|
|
2018-08-30 10:38:52 +00:00
|
|
|
unpublish_item() {
|
|
|
|
//
|
2018-08-27 04:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped></style>
|