|
@@ -1,88 +1,143 @@
|
|
|
<template>
|
|
|
<div id="distributor-form">
|
|
|
- <b-form @submit="onSubmit" @reset="onReset" v-if="show">
|
|
|
- <b-form-group label="Title:"
|
|
|
+ <b-form @submit="onSubmit">
|
|
|
+ <!-- Title Field -->
|
|
|
+ <b-form-group :label="labels.title"
|
|
|
label-for="distributor_title">
|
|
|
<b-form-input id="distributor_title"
|
|
|
type="email"
|
|
|
- v-model="distributor(id).title"
|
|
|
+ v-model="distributor.title"
|
|
|
required
|
|
|
- placeholder="Enter title">
|
|
|
+ :placeholder="labels.titlePlaceholder">
|
|
|
</b-form-input>
|
|
|
</b-form-group>
|
|
|
- <b-form-group label="Notes:"
|
|
|
+ <!-- Notes Field -->
|
|
|
+ <b-form-group :label="labels.notes"
|
|
|
label-for="distributor_notes">
|
|
|
<b-form-textarea id="distributor_notes"
|
|
|
- v-model="distributor(id).notes"
|
|
|
- placeholder="Enter something"
|
|
|
+ v-model="distributor.notes"
|
|
|
+ :placeholder="labels.notesPlaceholder"
|
|
|
:rows="3"
|
|
|
:max-rows="6">
|
|
|
</b-form-textarea>
|
|
|
</b-form-group>
|
|
|
- <b-form-group>
|
|
|
- <b-table :items="contacts(id)" :fields="names(id)">
|
|
|
+ <!-- Contacts Fields -->
|
|
|
+ <b-form-group :label="labels.contacts">
|
|
|
+ <!-- If there are any contacts -->
|
|
|
+ <b-table v-if="names" :items="contacts" :fields="names">
|
|
|
<template slot="actions" slot-scope="row">
|
|
|
- <!-- we use @click.stop here to prevent emitting of a 'row-clicked' event -->
|
|
|
<b-button size="sm" @click.stop="onDelete(row.item)" class="mr-1">
|
|
|
- delete
|
|
|
+ {{labels.delete}}
|
|
|
</b-button>
|
|
|
</template>
|
|
|
</b-table>
|
|
|
+ <!-- Inline contacts form -->
|
|
|
+ <b-form inline v-for="(contact, key) in distributor.contacts" :key="contact.id">
|
|
|
+ <b-input class="mb-3 mr-sm-3"
|
|
|
+ v-model="contact.name"
|
|
|
+ :placeholder="labels.name" />
|
|
|
+
|
|
|
+ <b-input class="mb-3 mr-sm-3"
|
|
|
+ v-model="contact.email"
|
|
|
+ :placeholder="labels.email" />
|
|
|
+
|
|
|
+ <b-input class="mb-3 mr-sm-3"
|
|
|
+ v-model="contact.phone"
|
|
|
+ :placeholder="labels.phone"/>
|
|
|
+
|
|
|
+ <b-button @click.stop="onDelete(key)" class="mb-3 mr-sm-3" variant="primary">{{labels.delete}}</b-button>
|
|
|
+
|
|
|
+ </b-form>
|
|
|
+
|
|
|
+ <b-form-group>
|
|
|
+ <b-button @click.stop="onAddContact()" class="mb-12 mr-sm-12" variant="primary">{{labels.add}}</b-button>
|
|
|
+ </b-form-group>
|
|
|
+
|
|
|
+ <b-form-group class="text-right">
|
|
|
+ <b-button type="submit" variant="primary">{{labels.submit}}</b-button>
|
|
|
+ <b-button @click.stop="onCancel()" type="reset" variant="danger">{{labels.cancel}}</b-button>
|
|
|
+ </b-form-group>
|
|
|
</b-form-group>
|
|
|
- <b-button type="submit" variant="primary">Submit</b-button>
|
|
|
- <b-button type="reset" variant="danger">Reset</b-button>
|
|
|
</b-form>
|
|
|
-
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import {mapGetters, mapState, mapActions} from 'vuex';
|
|
|
+import {mapGetters, mapActions} from 'vuex';
|
|
|
import * as types from '../store/types';
|
|
|
+import {store} from '../store/store';
|
|
|
|
|
|
export default {
|
|
|
props: {
|
|
|
id: {
|
|
|
- type: Number,
|
|
|
default: null
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
- show: true,
|
|
|
- translations: {
|
|
|
- title: 'Distributor page',
|
|
|
- add_distributor: 'Add distributor',
|
|
|
- },
|
|
|
+ labels: {
|
|
|
+ title: 'Title:',
|
|
|
+ notes: 'Notes:',
|
|
|
+ contacts: 'Contacts:',
|
|
|
+ delete: 'Delete',
|
|
|
+ submit: 'Save',
|
|
|
+ cancel: 'Cancel',
|
|
|
+ titlePlaceholder: 'Enter title',
|
|
|
+ notesPlaceholder: 'Enter something',
|
|
|
+ add: 'Add',
|
|
|
+ name: 'Name',
|
|
|
+ email: 'Email',
|
|
|
+ phone: 'Phone',
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
-
|
|
|
- },
|
|
|
- methods: {
|
|
|
...mapGetters({
|
|
|
- distributor: types.GET_DISTRIBUTOR,
|
|
|
contacts: types.GET_CONTACTS,
|
|
|
names: types.GET_CONTACT_FIELDS,
|
|
|
}),
|
|
|
- onSubmit () {
|
|
|
- console.log(distributor);
|
|
|
+ distributor: {
|
|
|
+ get() {
|
|
|
+ return this.$store.getters['distributor/GET_DISTRIBUTOR'](this.id)
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ //Placeholder
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ distributor: {
|
|
|
+ handler(val){
|
|
|
+ this.saveDistributor({
|
|
|
+ id: val.id,
|
|
|
+ distributor: val
|
|
|
+ });
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapActions({
|
|
|
+ saveDistributor: types.SET_DISTRIBUTOR,
|
|
|
+ }),
|
|
|
+ onSubmit (ev) {
|
|
|
+ console.log(ev);
|
|
|
},
|
|
|
- onReset () {
|
|
|
- console.log('onReset');
|
|
|
+ onAddContact () {
|
|
|
+ console.log('add');
|
|
|
},
|
|
|
onDelete(item) {
|
|
|
console.log('delete', item);
|
|
|
+ },
|
|
|
+ onCancel() {
|
|
|
+ console.log('onCancel');
|
|
|
}
|
|
|
},
|
|
|
- created() {
|
|
|
- console.log(this.id);
|
|
|
- let t = this.contacts(this.id)
|
|
|
- debugger
|
|
|
- }
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
-
|
|
|
+ #distributor-form{
|
|
|
+ text-align: left;
|
|
|
+ }
|
|
|
</style>
|