/
home
/
henzagold
/
oldsite
/
mixin
/
File Upload :
llllll
Current File: /home/henzagold/oldsite/mixin/product.js
import _ from 'lodash'; import axios from "~/plugins/axios"; export default { props: { product: { type: Object, required: false, default: () => {return {}}, }, list: { type: Boolean, default: false, }, model: { required: false, type: Boolean, default: false } }, model: { prop: 'model', event: 'change' }, data() { return { item : this.product, indexSelectVarint: 0, } }, methods: { addToCart() { this.$store.dispatch('cart/add', { product: this.item, pid: this.id, vid: this.selectVariant.id, qty: 1, promotion_id: this.promotions?this.promotions.id:null }); this.$vs.notify({ title: '', text: 'محصول به سبد خرید اضافه شد', color: 'var(--secondary-color)', position: 'bottom-left' }); }, pin() { if (this.isLogin) { if (this.isInWishList) { this.removeFromWishList() } else { this.addToWishList() } } else { this.$emit('change', true) } }, async addToWishList() { await axios({ method: 'post', url: 'https://henzagold.com/oapi/cu/fav', data: {product_id: this.id}, headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('accessToken') } }) .then(() => { this.$store.dispatch("wishlist/add", this.id); }) .catch(error => { this.$vs.notify({ color: 'danger', title: 'خطا', text: error, time: 3000 }) }) .finally(() => { this.$vs.notify({ color: 'var(--secondary-color)', text: 'محصول به لیست علاقه مندی ها اضافه شد', time: 3000 }) }) }, async removeFromWishList() { await axios({ method: 'delete', url: `https://henzagold.com/oapi/cu/fav/${this.id}`, data: {}, headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('accessToken') } }).then(() => { this.$store.dispatch("wishlist/remove", this.id); }) .catch(error => { this.$vs.notify({ color: 'danger', title: 'خطا', text: error, time: 3000 }) }) .finally(() => { this.$vs.notify({ color: 'var(--secondary-color)', text: 'محصول از لیست علاقه مندی ها حذف شد', time: 3000 }) }) }, }, computed: { promotions(){ return this.item.promotion }, secendrayImage() { if (this.item.gallery && this.item.gallery.length > 0) { return this.item.gallery[0].image; } return null; }, thumb() { return _.get(this.item, 'image.image', '/img/no-image.png'); }, title() { return _.get(this.item, 'title', ''); }, link() { return `/product/${this.$witheSpaceToDash(this.title)}/${this.id}`; }, price() { const mainPrice = _.get(this.variants, `[${this.indexSelectVarint}].price`) const discountPrice = _.get(this.variants, `[${this.indexSelectVarint}].price_with_discount`) if (mainPrice === discountPrice) { return mainPrice } else { return discountPrice } }, mainPrice() { return _.get(this.variants, `[${this.indexSelectVarint}].price`) }, discountedPrice() { return _.get(this.variants, `[${this.indexSelectVarint}].price_with_discount`) }, showBeforePrice() { const mainPrice = _.get(this.variants, `[${this.indexSelectVarint}].price`) const discountPrice = _.get(this.variants, `[${this.indexSelectVarint}].price_with_discount`) return !(mainPrice === discountPrice) }, discountPrice() { return _.get(this.variants, `[${this.indexSelectVarint}].price_with_discount`) }, brand() { return _.get(this.item, 'brand.val'); }, wishList() { return this.$store.state.wishlist.itemsId }, isLogin() { return this.$store.state.wishlist.isLogin }, isInWishList() { if (this.wishList.includes(this.id)) { return true } else { return false } }, // single id(){ return this.item.id || this.$route.params.id }, variants() { return _.get(this.item, `variants`, []); }, file() { return _.get(this.item, `file`, undefined); }, goldPrice() { return _.get(this.item, `goldPrice`, undefined); }, desk_note() { return _.get(this.item, `desk_note`, undefined); }, collects() { let collect = _.get(this.item, `collect`, []); return collect.filter((item, index) => { return collect.findIndex((x) => x && x.collection && item && item.collection && (x.collection.title === item.collection.title)) == index; }) }, tags() { return _.get(this.item, `tags`, []); }, related() { return _.get(this.item, `related`, []); }, selectVariant() { return _.get(this.variants, `[${this.indexSelectVarint}]`, {}); }, color() { let x = _.get(this.selectVariant, 'color_str', '').split('/'); return { name: x[0][0] !== '#' ? x[0] : x[1], color: x[0][0] == '#' ? x[0] : x[1] } }, /*gallery() { let temp = []; const image = _.get(this.item, `image`, undefined); if (image) temp.push(image) const gallery = _.get(this.item, `gallery`, undefined); if (gallery) temp.push(...gallery); return temp/!*.filter((item, index) => { return temp.findIndex((x) => x.collection && item.collection && (x.collection.title === item.collection.title)) == index; })*!/ },*/ gallery() { let temp = _.get(this.item, `gallery`, []) const image = _.get(this.item, `image`, undefined) if (image) temp.splice(0,0,image); temp = temp.filter((item, index) => { return temp.findIndex((x) => x.id === item.id) == index; }) return temp || []; }, fullLink() { return `${process.env.baseUrl}product/${this.$witheSpaceToDash(this.title)}/${this.id}`; }, // single }, }
Copyright ©2k19 -
Hexid
|
Tex7ure