Object in array is undefined in vue - vue.js

I need help as the array “items1” works when “console.log(this.items1)”
However, it is undefined when “console.log(this.items1[0])”. How can I solve this? I really have no idea what is going. Ultimately, I want to gather item.text whenever user selects the tab from v-tabs. Using item.text, I am able to filter the data in db. Is there a way to gather the user input whenever user selects tab?
<template>
<v-layout>
<v-container flat grid-list-lg>
<v-layout row wrap class="flex_box feature_products">
<v-flex xs12>
<h2 class="text-xs-center feature_products_title">Check Our <span>Delicious Menu</span></h2>
</v-flex>
<v-flex xs12>
<v-card>
<v-toolbar flat>
<template v-slot:extension>
<v-tabs v-model="model" centered slider-color="yellow">
<v-tab v-for="(item, index) in items1" :key="index" :href="`#tab-${index}`">
{{ item.text }}
</v-tab>
</v-tabs>
</template>
</v-toolbar>
<v-tabs-items v-model="model">
<v-tab-item v-for="(item, index) in items1" :key="index" :value="`tab-${index}`">
<!-- your this code displays the product information, but there is no way to filter the product by category -->
<v-layout row wrap class="flex_box feature_products">
<v-flex xs12 sm3 md3 lg3 xl2 class="flex_item" v-for="(product,index) in products" :key="index">
<v-card flat v-if="product.category_name == item.text">
<v-card class="overlay_container flex_wrap pa-2">
<v-img :src="product.image" contain></v-img>
<div style="width:100%;" class="flex_bottom text-xs-center pb-2">
<h3 class="headline text-xs-center grey--text text--darken-3">{{product.item_name}}</h3>
<h4 class="grey--text text--darken-3">{{currency}}{{product.price}}</h4>
</div>
<v-card class="overlay">
<h2 style="vertical-align:middle;">{{product.item_name}}</h2>
<v-list class="details">
<v-list-tile-action>
<v-btn style="width:100%" :to="'/product/' + product.id">Details</v-btn>
</v-list-tile-action>
<v-list-tile-action>
<v-btn style="width:100%" class="main_color white--text" #click="addToCart(product)">Add To Cart</v-btn>
</v-list-tile-action>
</v-list>
</v-card>
</v-card>
</v-card>
<v-card v-else>
</v-card>
</v-flex>
</v-layout>
</v-tab-item>
</v-tabs-items>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-layout>
</template>
<script>
import Vue from 'vue'
import firebase from "firebase";
import moment from 'moment'
import db, {functions} from '#/firebase/init'
import MenuNavbar from '#/components/shop/navbar/MenuNavbar'
export default {
data(){
// Show All Categories
let ref = db.collection("item_categories");
ref.onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
if (change.type == "added") {
let doc = change.doc;
this.items1.push({
icon: doc.data().category_icon,
text: doc.data().category_name,
link:'CatProduct',
category:doc.data().category_name,
text1: 'Category Name: ' + doc.data().category_name
});
}
});
});
return{
model:'tab-2', // select your default tab here
currency:null,
products:[],
cart:this.$store.getters.cart,
items1:[],
}
},
components: {
MenuNavbar
},
methods: {
productInCart(product) {
const cartItems = this.cart
for (let i = 0; i < cartItems.length; i++) {
if (cartItems[i].product.id === product.id) {
return i
}
}
return null
},
addToCart(product, quantity){
const index = this.productInCart(product)
const productQuantity = (!quantity || quantity < 1) ? 1 : parseInt(quantity)
if (index === null) {
var items = {
product: product,
quantity: productQuantity
}
//this.$store.commit('catalog/updateCart', items)
this.$store.commit('updateCart', items)
}else {
if(!quantity){
// If item is already into the cart then add++ quantity
this.$store.commit('increaseQuantity', index)
}else{
// When quantity updated manually
}
}
},
removeCart(index){
this.$store.commit('removeCart', index)
},
},
computed:{
counter(){
return this.$store.getters.counter
},
},
getTabText(text){
return text
},
created(){
var db = firebase.firestore();
// Current Currency
db.collection("settings").doc('config').onSnapshot(doc =>{
this.currency = doc.data().currency
})
console.log(this.items1[0])
// Show All Items
let cref = db.collection('items').orderBy('timestamp', 'desc').where("featured", "==", true)
cref.onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
if(change.type == 'added'){
let doc = change.doc
this.products.push({
id:doc.id,
item_name:doc.data().item_name,
image:doc.data().image,
category_name:doc.data().item_category,
price:doc.data().price,
quantity:doc.data().quantity,
timestamp:moment(doc.data().timestamp).fromNow('lll')
})
}
})
})
}
}
</script>

Related

How do I capture the value of the prop in the text field?

I have a prop and currently am able to get the data of the prop, Am trying a way to capture the item of the prop when saving the form.
Is there a way where i can take the value and pass if in a hidden text-area and bind the data to the vmodel?
Any help I appreciate.
<v-dialog v-model="dialog" persistent max-width="800">
<template v-slot:activator="{ on }">
<v-btn dark v-on="on" color="primary" round> Make payment </v-btn>
</template>
<v-card>
<v-card-title class="headline primary">
<span class="white--text">Add a new Doctor Payment Record {{ queueId }}</span>
<v-btn icon dark #click.native="dialog = false" absolute right>
<v-icon>mdi-close</v-icon>
</v-btn>
</v-card-title>
<v-card-text>
<users-search
:leave-selected="true"
idOnly
label="Select Doctor"
#results="setDoctor"
>
</users-search>
<div class="row px-3">
<v-autocomplete
class="px-3 col-sm-8"
v-model="expense.bank"
v-if="banks.data"
:items="banks.data"
outline
chips
label="Select bank"
item-text="name"
item-value="id"
>
</v-autocomplete>
<v-text-field
class="px-3 col-sm-8"
outline
flat
v-model="expense.amount"
type="number"
#input="expense.percentage()"
required
label="Amount *"
persistent-hint
/>
</div>
<v-text-field
class="px-3"
outline
flat
v-model="expense.total_paid"
required
label="amount paid"
persistent-hint
/>
<v-text-field
class="px-3"
outline
flat
:value="setQueue"
v-model="expense.queueId"
required
:label=queueId
persistent-hint
/>
<v-alert :value="true" type="error" v-if="errors.any()">
<div v-html="errors.display()"></div>
</v-alert>
<v-layout row wrap>
<v-flex xs12>
<v-btn
color="success"
:loading="saveLoader"
#click="recordExpense()"
>save</v-btn
>
</v-flex>
</v-layout>
</v-card-text>
</v-card>
</v-dialog>
</template>
<script>
import NewUser from "#finance/libs/users/NewUser";
import {mapActions, mapGetters} from "vuex";
export default {
props: [
'queueId'
],
data: () => ({
dialog: false,
expense: new NewUser(),
saveLoader: false,
}),
computed: {
...mapGetters({
banks: "getBanks",
}),
balance: function () {
return parseFloat(10);
},
submitted() {
return this.expense.form.submitted;
},
contaminated() {
return this.expense.form.errorDetected;
},
errors() {
return this.expense.form.errors;
},
},
watch: {
submitted(v) {
if (v) {
this.saveLoader = false;
}
},
contaminated() {
this.saveLoader = false;
},
},
methods: {
...mapActions({
fetchBanks: "setBanks",
}),
setDoctor(user) {
this.expense.doctor_id = user.id;
},
setQueue(){
console.log(this.queueId);
this.expense.queueId = this.queueId;
},
async recordExpense() {
this.saveLoader = true;
let response = await this.expense.saveExpense();
this.saveLoader = false;
if (response) {
this.dialog = false;
this.$emit("expenseCreated");
}
},
},
mounted() {
this.fetchBanks();
}
};
</script>
The prop queueId i also want to store it along with the user information from the form.
Try this one, it should work:
<template>
<textarea v-model="hiddenValue" :style="{ display: 'none' }"></textarea>
</template>
<script>
export default {
props: [ 'queueId' ],
data() {
return {
hiddenValue: this.queueId
}
}
}
</script>
In case you will no need the prop to be modified, please bind the texarea value to the prop directly:
<textarea hidden v-model="queueId" :style="{ display: 'none' }></textarea>

How to show an icon only when certain tab is selected?

For this website I have two login tabs as seen in the image below, and right now it's hard to understand which login tab is selected.
I'm trying to display an icon next to the selected tab, but currently it shows the icon for both tabs. So overall I'm trying to show the icon only for the tab that is selected and if I change the tab, it hides it from the previously selected tab and shows it to the current one.
This is the whole code that I have -
<template>
<v-main id="login">
<v-container fill-height fluid>
<v-layout align-center justify-center>
<v-flex md4 sm8 xs12>
<v-card class="elevation-12">
<v-toolbar color="primary" dark>
<v-toolbar-title>
<v-icon left> mdi-login-variant </v-icon>
{{ $t("welcome") }}
</v-toolbar-title>
</v-toolbar>
<v-divider />
<v-tabs v-model="selectedTab" grow hide-slider>
<v-tab
v-for="(tab, i) in tabs"
:key="i"
:class="{
'primary white--text': tab == selectedTab,
caption: tab != selectedTab,
}"
:href="`#${tab}`"
class="pa-0"
>
{{ tab }}
//This is the icon line that I added
<v-icon right >mdi-check-circle-outline</v-icon>
</v-tab>
<v-tab-item
v-for="(tab, i) in tabs"
:key="i"
:value="tab"
reverse-transition="scale-transition"
transition="scale-transition"
>
<v-divider />
<v-card-text>
<v-form #submit.prevent="login">
<v-text-field
v-model.lazy="username"
:label="$t('username')"
:prepend-inner-icon="
tab === 'Windows' ? 'mdi-windows' : 'mdi-account'
"
:rules="[username !== null || required]"
name="username"
outlined
placeholder=" "
type="text"
/>
<v-text-field
v-model.lazy="password"
:label="$t('password')"
:rules="[password !== null || required]"
name="password"
outlined
placeholder=" "
prepend-inner-icon="mdi-lock"
type="password"
/>
<!-- If error, rended error component -->
<error-view
v-if="error"
:error="error"
:is-login="true"
class="pa-0"
/>
<v-card-actions class="pa-0">
<v-spacer />
<v-btn :loading="loading" color="primary" type="submit">
{{ $t("submit") }}
</v-btn>
</v-card-actions>
</v-form>
</v-card-text>
</v-tab-item>
</v-tabs>
<div id="version-div">
<app-version />
</div>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-main>
</template>
<script>
import AppVersion from "#/components/version";
const errorView = () => import("#/components/errorView");
export default {
name: "Login",
components: {
errorView,
AppVersion,
},
data() {
return {
tabs: ["Windows", "Standard"],
selectedTab: "Standard",
username: null,
password: null,
loading: false,
error: null,
required: (value) => !!value || this.$t("req"),
};
},
methods: {
resetForm(value) {
this.username = this.password = value;
},
login() {
if (!this.username || !this.password) {
this.error = this.$t("warn");
this.resetForm(null);
} else {
this.loading = true;
const encodedPass = window.btoa(
unescape(encodeURIComponent(this.password))
);
this.$store
.dispatch("retrieveUser", {
username: this.username,
password: encodedPass,
outside: this.selectedTab === "Windows" ? false : true,
})
.then(() => {
this.$router.push({ name: "home" });
this.error = null;
})
.catch((error) => {
this.error = error;
})
.finally(() => {
this.resetForm("");
this.loading = false;
});
}
},
},
};
</script>
Thank you in advance!
You've actually already implemented the solution in a different part of your code.
Apply the same conditioning as you do to the class binding on 'primary white--text'. The v-icon can be conditionally rendered based on the tab selected.
<v-icon v-if="tab === selectedTab" right >mdi-check-circle-outline</v-icon>

whoe to solve this proplem :updating a chiled component in vuejs update all the other childeren?

I want to update the likes for the specific comment
this is the parent component Commnet.vue
<template>
<v-list class="list" color="white" three-line>
<template v-for="cmnt in comments" class="mb-2">
<v-card color="transparent" class=" text-no-wrap" :key="cmnt._id">
<v-list-item class="item" :key="cmnt._id">
<v-list-item-avatar>
<v-img :src="cmnt.author.image"></v-img>
</v-list-item-avatar>
<v-list-item-content class="black--text">
<v-list-item-title>{{
cmnt.author.first_name + " " + cmnt.author.last_name
}}</v-list-item-title>
<v-list-item-subtitle class="black--text" v-html="cmnt.comment">
{{ cmnt.comment }}
</v-list-item-subtitle>
</v-list-item-content>
<v-card class="like-count">
<v-icon color="blue">mdi-thumb-up </v-icon>
<Likes :_id="cmnt._id"/>
</v-card>
</v-list-item>
</v-card>
<v-card
:key="cmnt._id"
outlined="true"
color="transparent"
class="ml-6"
>
</template>
and this is the child component inside comment component it has it is own state completely separated form the parent.
Like.vue
<template>
<div>
<v-card >
</v-card>
{{likes.length}}
</div>
</template>
<script>
import axios from "axios";
import io from "socket.io-client";
export default {
name:"Likes",
created:async function(){
axios.get(`comment/${this._id}`)
.then(results=>{
if (results.data){
this.likes =results.data;
}
})
.catch(err=> console.log(err));
let url = "";
if (process.env.NODE_ENV === "production") {
url = "/";
} else {
url = "http://localhost:5000";
}
this.socket = io(url);
this.socket.on("receive-like",async (data)=>{
console.log(data)
this.new_like= data;
console.log(this.new_like)
const el = this.likes.find(el => el._id === this.new_like._id)
if (el){
const index = this.likes.indexOf(el);
this.$forceUpdate()
return this.likes.splice(index,1)
}else{
this.likes.push(this.new_like);
console.log(this.likes)
this.$forceUpdate()
}
})
},
mounted:async function(){
},
props:{
_id:{
type: String
}
},
data:()=>({
user:{},
likes:[],
new_like:{}
}),
computed:{
},
}
</script>
so when clicking like the new like object get pushed to the array of likes for the concerned comment but likes for all comments get updated at ones.
in case somebody is wondering I just made adding the new like object conditional
if(data.comment._id === this._id)

Vue components data and methods disappear on one item when rendered with v-for as Vuetify's cards

I have Vue component that renders a list of Vuetify cards:
<restaurant-item
v-for="card in userRestaurantCards"
:key="card['.key']"
:card="card"
>
</restaurant-item>
The card displays info obtained from props, Vuex, as well as info defined in the restaurant-item card itself:
<v-card>
<v-img
class="white--text"
height="200px"
:src="photo"
>
<v-container fill-height fluid class="card-edit">
<v-layout fill-height>
<v-flex xs12 align-end flexbox>
<v-menu bottom right>
<v-btn slot="activator" dark icon>
<v-icon>more_vert</v-icon>
</v-btn>
<v-list>
<edit-restaurant-dialog :card="card" :previousComment="comment"></edit-restaurant-dialog>
<v-list-tile >
<v-list-tile-title>Delete</v-list-tile-title>
</v-list-tile>
</v-list>
</v-menu>
</v-flex>
</v-layout>
</v-container>
</v-img>
<v-card-title>
<div>
<span class="grey--text">Friends rating: {{ card.rating }}</span><br>
<h3>{{ card.name }}</h3><br>
<span>{{ card.location }}</span>
</div>
</v-card-title>
<v-card-actions>
<v-btn flat color="purple">Comments</v-btn>
<v-spacer></v-spacer>
<v-btn icon #click="show = !show">
<v-icon>{{ show ? 'keyboard_arrow_down' : 'keyboard_arrow_up' }}</v-icon>
</v-btn>
</v-card-actions>
<v-slide-y-transition>
<v-card-text v-show="show">
<div> {{ comment.content }} </div>
</v-card-text>
</v-slide-y-transition>
</v-card>
The script is:
import { find, isEmpty } from 'lodash-es'
import { mapGetters } from 'vuex'
import EditRestaurantDialog from '#/components/dashboard/EditRestaurantDialog'
export default {
name: 'restaurant-item',
components: {
EditRestaurantDialog
},
props: {
card: Object
},
data() {
return {
show: false,
name: this.card.name,
location: this.card.location,
rating: this.card.rating,
link: this.card.link,
photo: this.getPhotoUrl()
}
},
computed: {
comment() {
// Grab the content of the comment that the current user wrote for the current restaurant
if (isEmpty(this.card.comments)) {
return { content: 'You have no opinions of this place so far' }
} else {
const userComment = find(this.card.comments, o => o.uid === this.currentUser)
return userComment
}
},
...mapGetters(['currentUser'])
},
methods: {
getPhotoUrl() {
const cardsDefault = find(this.card.photos, o => o.default).url
if (isEmpty(cardsDefault)) {
return 'https://via.placeholder.com/500x200.png?text=No+pics+here+...yet!'
} else {
return cardsDefault
}
}
}
}
Here is the kicker: when I have 2 objects in the data, the first card component renders correctly... while the second doesn't have any of the methods or data defined right there in the script.
Here's a link to a screenshot of the Vue Devtools inspecting the first card:
https://drive.google.com/file/d/1LL4GQEj0S_CJv55KRgJPHsCmvh8X3UWP/view?usp=sharing
Here's a link of the second card:
https://drive.google.com/open?id=13MdfmUIMHCB_xy3syeKz6-Bt9R2Yy4Xe
Notice how the second one has no Data except for the route?
Also, note that both components loaded props, vuex bindings and computed properties just as expected. Only the Data is empty on the second one...
I've been scratching my head for a while over this. Any ideas would be more than welcome.
I got it to work after I moved the method getPhotoUrl method to a computed property:
computed: {
comment() {
// Grab the content of the comment that the current user wrote for the current restaurant
if (isEmpty(this.card.comments)) {
return { content: 'You have no opinions of this place so far' }
} else {
const userComment = find(this.card.comments, o => o.uid === this.currentUser)
return userComment
}
},
photoUrl() {
const cardsDefault = find(this.card.photos, o => o.default)
if (isEmpty(cardsDefault)) {
return 'https://via.placeholder.com/500x200.png?text=No+pics+here+...yet!'
} else {
return cardsDefault.url
}
},
...mapGetters(['currentUser'])
}

Vuejs dynamic data names

Is there a way to dynamically change data names based on other data names? Here is my example.
Say I have these data elements.
export default {
data: function() {
return {
speed: "Standard",
speed_enabled: false,
flex_enabled: false,
};
},
While the user interacts with the front end, I pull in additional speed data, in the form of different names. ex. Priority, Expedited etc.
When I do this I want to change the names of the other data elements. Something like this:
export default {
data: function() {
return {
speed: "Standard",
{{this.speed}}_speed_enabled: false,
flex_enabled: false,
};
},
Something along those lines.. so speed_enabled becomes expedited_speed_enabled and priority_speed_enabled etc. etc.
Is this possible?
EDIT: here is all my code.. maybe someone can figure out how to pass different data to the same component.
Here is my parent component speeds.vue:
<template>
<v-app>
<v-container fill-height>
<v-layout row wrap align-center>
<v-flex xs8 class="mx-auto">
<h1 class="display-1 mont bold fix-title-height pb-3">FBA Shipping Settings</h1>
<v-tabs icons-and-text centered color="purple darken-3" dark class="elevation-12">
<v-tabs-slider color="green lighten-1"></v-tabs-slider>
<v-tab :key="speed" #click="setStandard">
Standard
</v-tab>
<v-tab :key="speed" #click="setExpedited">
Expedited
</v-tab>
<v-tab :key="speed" #click="setPriority">
Priority
</v-tab>
<v-tab-item :key="standard" >
<speed_details></speed_details>
</v-tab-item>
<v-tab-item :key="expedited">
<speed_details></speed_details>
</v-tab-item>
<v-tab-item :key="priority">
<speed_details></speed_details>
</v-tab-item>
</v-tabs>
</v-flex>
</v-layout>
</v-container>
</v-app>
</template>
<script>
import speed_details from '../components/speed_details.vue';
import {dataShare} from '../packs/application.js';
import axios from 'axios';
export default {
data: function() {
return {
speed: "Standard"
};
},
components: {
speed_details
},
created() {
console.log("this should get hit at the beginning and what's speed? " + this.speed);
dataShare.$emit('speed', this.speed);
},
methods: {
getSpeedInfo() {
axios.get('https://bc-ship-trimakas.c9users.io/return_speed_info', {params: {speed: this.speed}}).then(response => {
const speed_info = {
speed_enabled: true,
fixed_rate_amount: response.data.fixed_amount,
// this.fixed_enabled = response.data.fixed;
// this.flex_enabled = response.data.flex;
// this.flex_above_or_below_amount = response.data.flex_amount;
// this.percent_or_dollar = response.data.flex_dollar_or_percent;
free_enabled: response.data.free,
free_shipping_amount: response.data.free_shipping_amount
};
dataShare.$emit('speed_info', speed_info);
});
},
setStandard() {
this.speed = "Standard";
dataShare.$emit('speed', this.speed);
},
setExpedited() {
this.speed = "Expedited";
dataShare.$emit('speed', this.speed);
},
setPriority() {
this.speed = "Priority";
dataShare.$emit('speed', this.speed);
},
}
};
</script>
<style>
</style>
And then my child component speed_details.vue that is the same across all three tabs:
<template>
<v-card flat class="lightblue" :resize="moveIcon">
<v-form ref="form" v-model="valid" lazy-validation>
<v-layout row wrap>
<v-flex xs7>
<v-switch
:label="'Enable ' + speed + ' Shipping'"
:v-model="speed_enabled"
color="purple darken-3"
#change="enableAndDisable"
></v-switch>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs7>
<v-switch
label="Enable Flex Rate Shipping?"
:disabled="flex_switch_disabled"
v-model="flex_enabled"
color="purple darken-3"
#change="killFixed, removeFlexAmount"
></v-switch>
</v-flex>
<v-flex>
<v-tooltip top>
<v-icon slot="activator" color="purple darken-3" class="fix_icon">info</v-icon>
<span class="body-2">You can enable fixed or flex rate shipping but not both</span>
</v-tooltip>
</v-flex>
</v-layout>
<v-layout row wrap class="move-up">
<v-flex xs1>
<v-select
:disabled="!flex_enabled"
append-icon=""
color="purple darken-3"
:items="fee_type"
v-model="percent_or_dollar"
label="$ or %"
single-line
auto
hide-details
></v-select>
</v-flex>
<v-flex xs8>
<v-text-field
:disabled="!flex_enabled"
type="number"
color="purple darken-3"
label="Shipping Amount Above or Below FBA Fees"
v-model="flex_above_or_below_amount"
class="push-right"
></v-text-field>
</v-flex>
<v-flex xs1 v-bind="icon_adjust" class="push_down">
<v-tooltip top>
<v-icon slot="activator" color="purple darken-3" class="fix_icon">info</v-icon>
<span class="body-2">This amount will either increase or decrease(-) the fulfillment amount from Amazon.
</span>
</v-tooltip>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs7>
<v-switch
label="Enable Fixed Rate Shipping?"
:disabled="fixed_switch_disabled"
v-model="fixed_enabled"
color="purple darken-3"
#change="killFlex, removeFixedAmount"
></v-switch>
</v-flex>
<v-flex xs1>
<v-tooltip top>
<v-icon slot="activator" color="purple darken-3" class="fix_icon_less">info</v-icon>
<span class="body-2">This amount will be displayed to your customer and Amazon fees will be ignored.
</span>
</v-tooltip>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs4>
<v-text-field
:disabled="!fixed_enabled"
type="number"
color="purple darken-3"
label="Fixed Rate Amount"
v-model="fixed_rate_amount"
prefix="$"
class="move-up"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs7>
<v-switch label="Enable Free Shipping?" :disabled="!speed_enabled" v-model="free_enabled" color="purple darken-3"></v-switch>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs8>
<v-text-field
:disabled="!free_enabled"
type="number"
color="purple darken-3"
label="Order Amount to Qualify for Free Shipping"
v-model="free_shipping_amount"
class="move-up"
prefix="$"
#change="removeFreeAmount"
></v-text-field>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs11>
<v-btn
medium
dark
:disabled="!speed_enabled"
color="green lighten-1"
#click="sendShipping()"
>Save {{ speed }} Settings</v-btn>
<v-btn
medium
outline
:disabled="!speed_enabled"
color="purple darken-3"
#click="deleteShipping"
>Delete {{ speed }} Settings</v-btn>
</v-flex>
</v-layout>
</v-form>
</v-card>
</template>
<script>
import {dataShare} from '../packs/application.js';
import axios from 'axios';
export default {
data: function() {
return {
speed: "Standard",
icon_adjust: {'offset-xs1': false},
icon_push_right: {'push-right': false},
// [`${this.speed}_speed_enabled`]: false,
speed_enabled: false,
flex_enabled: false,
fixed_enabled: false,
free_enabled: false,
flex_switch_disabled: true,
fixed_switch_disabled: true,
fixed_rate_amount: "",
free_shipping_amount: "",
flex_above_or_below_amount: "",
valid: true,
percent_or_dollar: "",
fee_type: ["$", "%"]
};
},
created() {
dataShare.$on('speed', (speed) => {
this.speed = speed;
});
axios.get('https://bc-ship-trimakas.c9users.io/return_speed_info', {params: {speed: this.speed}}).then(response => {
// this.speed = response.data.shipping_speed;
this.speed_enabled = true;
// this.[`${this.speed}_speed_enabled`] = true;
this.fixed_rate_amount = response.data.fixed_amount;
this.fixed_enabled = response.data.fixed;
this.flex_enabled = response.data.flex;
this.flex_above_or_below_amount = response.data.flex_amount;
this.percent_or_dollar = response.data.flex_dollar_or_percent;
this.free_enabled = response.data.free;
this.free_shipping_amount = response.data.free_shipping_amount;
});
},
computed: {
removeFlexAmount(){
if(this.flex_enabled == false){
this.flex_above_or_below_amount = "";
this.percent_or_dollar = "";
}
},
removeFixedAmount(){
if(this.fixed_enabled == false){
this.fixed_rate_amount = "";
}
},
removeFreeAmount(){
if(this.free_enabled == false){
this.free_shipping_amount = "";
}
},
pushIconRight() {
if(this.$vuetify.breakpoint.mdAndDown){
this.icon_push_right['push-right'] = true;
}
else{
this.icon_push_right['push-right'] = false;
}
},
moveIcon() {
console.log(this.$vuetify.breakpoint.name);
if(this.$vuetify.breakpoint.mdAndDown){
this.icon_adjust['offset-xs1'] = true;
}
else{
this.icon_adjust['offset-xs1'] = false;
}
},
enableAndDisable(){
if(this.speed_enabled == true){
this.flex_switch_disabled = false;
this.fixed_switch_disabled = false;
}
else{
this.flex_switch_disabled = true;
this.fixed_switch_disabled = true;
}
},
killFixed(){
if(this.flex_enabled == true){
this.fixed_switch_disabled = true;
this.fixed_rate_amount = "";
}
if(this.speed_enabled == true && this.flex_enabled == true){
this.fixed_switch_disabled = true;
this.fixed_enabled = false;
this.fixed_rate_amount = "";
}
if(this.speed_enabled == true && this.flex_enabled == false){
this.fixed_switch_disabled = false;
}
},
killFlex(){
if(this.fixed_enabled == true){
this.flex_switch_disabled = true;
this.above_or_below_amount = "";
}
if(this.speed_enabled == true && this.fixed_enabled == true){
this.flex_switch_disabled = true;
this.flex_enabled = false;
this.above_or_below_amount = "";
this.percent_or_dollar = "";
}
if(this.speed_enabled == true && this.fixed_enabled == false){
this.flex_switch_disabled = false;
}
}
},
methods: {
sendShipping() {
const shipping = {
speed_type: this.speed,
speed_enabled: this.speed_enabled,
flex_enabled: this.flex_enabled,
fixed_enabled: this.fixed_enabled,
free_enabled: this.free_enabled,
fixed_rate_amount: this.fixed_rate_amount,
free_shipping_amount: this.free_shipping_amount,
standard_flex_above_or_below_amount: this.above_or_below_amount,
percent_or_dollar: this.percent_or_dollar
};
let self = this;
let speed_info = {bytestand_rate_info: shipping};
axios.post('https://bc-ship-trimakas.c9users.io/save_shipping_info', speed_info).then(response => {
console.log(this.response);
});
},
deleteShipping() {
const deleteSpeed = {
speed_type: this.speed
};
let self = this;
let delete_speed = {bytestand_rate_info: deleteSpeed};
axios.post('https://bc-ship-trimakas.c9users.io/delete_speed', delete_speed).then(response => {
console.log(this.response);
});
}
}
};
</script>
<style>
.push_down {
margin-top: 18px;
}
.fix_icon_less {
margin-top: 5px;
margin-left: -70px;
}
.fix_icon {
margin-top: 5px;
margin-left: -80px;
}
.move-up {
margin-top: -18px;
}
.move-left {
margin-left: -20px;
}
.push-right {
margin-left: 10px;
}
</style>