Distributor-form.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div id="distributor-form">
  3. <b-form @submit="onSubmit">
  4. <!-- Title Field -->
  5. <b-form-group :label="labels.title"
  6. label-for="distributor_title">
  7. <b-form-input id="distributor_title"
  8. type="email"
  9. v-model="distributor.title"
  10. required
  11. :placeholder="labels.titlePlaceholder">
  12. </b-form-input>
  13. </b-form-group>
  14. <!-- Notes Field -->
  15. <b-form-group :label="labels.notes"
  16. label-for="distributor_notes">
  17. <b-form-textarea id="distributor_notes"
  18. v-model="distributor.notes"
  19. :placeholder="labels.notesPlaceholder"
  20. :rows="3"
  21. :max-rows="6">
  22. </b-form-textarea>
  23. </b-form-group>
  24. <!-- Contacts Fields -->
  25. <b-form-group :label="labels.contacts">
  26. <!-- If there are any contacts -->
  27. <b-table v-if="names" :items="contacts" :fields="names">
  28. <template slot="actions" slot-scope="row">
  29. <b-button size="sm" @click.stop="onDelete(row.item)" class="mr-1">
  30. {{labels.delete}}
  31. </b-button>
  32. </template>
  33. </b-table>
  34. <!-- Inline contacts form -->
  35. <b-form inline v-for="(contact, key) in distributor.contacts" :key="contact.id">
  36. <b-input class="mb-3 mr-sm-3"
  37. v-model="contact.name"
  38. :placeholder="labels.name" />
  39. <b-input class="mb-3 mr-sm-3"
  40. v-model="contact.email"
  41. :placeholder="labels.email" />
  42. <b-input class="mb-3 mr-sm-3"
  43. v-model="contact.phone"
  44. :placeholder="labels.phone"/>
  45. <b-button @click.stop="onDelete(key)" class="mb-3 mr-sm-3" variant="primary">{{labels.delete}}</b-button>
  46. </b-form>
  47. <b-form-group>
  48. <b-button @click.stop="onAddContact()" class="mb-12 mr-sm-12" variant="primary">{{labels.add}}</b-button>
  49. </b-form-group>
  50. <b-form-group class="text-right">
  51. <b-button type="submit" variant="primary">{{labels.submit}}</b-button>
  52. <b-button @click.stop="onCancel()" type="reset" variant="danger">{{labels.cancel}}</b-button>
  53. </b-form-group>
  54. </b-form-group>
  55. </b-form>
  56. </div>
  57. </template>
  58. <script>
  59. import {mapGetters, mapActions} from 'vuex';
  60. import * as types from '../store/types';
  61. import {store} from '../store/store';
  62. export default {
  63. props: {
  64. id: {
  65. default: null
  66. },
  67. },
  68. data () {
  69. return {
  70. labels: {
  71. title: 'Title:',
  72. notes: 'Notes:',
  73. contacts: 'Contacts:',
  74. delete: 'Delete',
  75. submit: 'Save',
  76. cancel: 'Cancel',
  77. titlePlaceholder: 'Enter title',
  78. notesPlaceholder: 'Enter something',
  79. add: 'Add',
  80. name: 'Name',
  81. email: 'Email',
  82. phone: 'Phone',
  83. }
  84. }
  85. },
  86. computed: {
  87. ...mapGetters({
  88. contacts: types.GET_CONTACTS,
  89. names: types.GET_CONTACT_FIELDS,
  90. }),
  91. distributor: {
  92. get() {
  93. return this.$store.getters['distributor/GET_DISTRIBUTOR'](this.id)
  94. },
  95. set(val) {
  96. //Placeholder
  97. },
  98. }
  99. },
  100. watch: {
  101. distributor: {
  102. handler(val){
  103. this.saveDistributor({
  104. id: val.id,
  105. distributor: val
  106. });
  107. },
  108. deep: true
  109. }
  110. },
  111. methods: {
  112. ...mapActions({
  113. saveDistributor: types.SET_DISTRIBUTOR,
  114. }),
  115. onSubmit (ev) {
  116. console.log(ev);
  117. },
  118. onAddContact () {
  119. console.log('add');
  120. },
  121. onDelete(item) {
  122. console.log('delete', item);
  123. },
  124. onCancel() {
  125. console.log('onCancel');
  126. }
  127. },
  128. }
  129. </script>
  130. <style lang="scss">
  131. #distributor-form{
  132. text-align: left;
  133. }
  134. </style>