I wanted to create simple invoice using bootstrap table and Vue Js.
Basically, What i wanted is shown in the image below:
I have tried as in the code below, but i am confused on two things,
How should i
1) Calculate the total cost
and show that as the footer summary
.
2) Multiply rate
and qnty
and display on the corresponding input box on cost
.
new Vue({
el: '#app',
methods: {
addService() {
this.model.services.push({});
}
},
data: {
model: {
services: []
},
fields: [{
key: "rate",
label: "Rate"
},
{
key: "qnty",
label: "Qnty"
},
{
key: "cost",
label: "Cost"
}
]
}
})
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" />
<script src="https://unpkg.com/vue"></script>
<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<div id="app">
<b-card header-tag="header" footer-tag="footer">
<template slot="header" class="mb-0">
<button type="button" class="btn btn-primary btn-sm" @click.prevent="addService">
<icons :icon="['fas', 'plus']" /> Add Items/Service</button>
</template>
<b-card-body>
<b-table responsive bordered striped hover caption-top :fields="fields" :items="model.services" foot-clone>
<template slot="rate" slot-scope="data">
<b-form-input size="sm" class="form-control" v-model="data.item.rate" :name="`rate_${data.index}`" type="text" />
</template>
<template slot="qnty" slot-scope="data">
<b-form-input size="sm" class="form-control" v-model="data.item.qnty" :name="`qnty_${data.index}`" type="text" />
</template>
<template slot="cost" slot-scope="data">
<b-form-input size="sm" class="form-control" v-model="data.item.cost" :name="`cost_${data.index}`" type="text" />
</template>
</b-table>
</b-card-body>
</b-card>
</div>
The way i wanted is easily achieved by using normal td
and tr
, with computed function.
But i am confused with how to implement using Bootstrap-vue
.
Please help!