jws-frontend/src/components/TabComponent.vue

112 lines
2.5 KiB
Vue
Raw Normal View History

2024-04-23 11:37:27 +07:00
<script setup lang="ts">
import { ref } from 'vue';
import { CustomerBranchCreate } from 'stores/customer/types';
2024-04-23 11:37:27 +07:00
const customerBranch = defineModel<CustomerBranchCreate[]>('customerBranch', {
default: [],
});
const tab = defineModel<number>('tabIndex', { required: true });
2024-04-23 11:37:27 +07:00
const index = ref<number>(0);
2024-04-23 11:37:27 +07:00
function addData() {
index.value++;
customerBranch.value.push({
status: 'CREATED',
legalPersonNo: '',
taxNo: '',
name: '',
nameEN: '',
addressEN: '',
address: '',
zipCode: '',
email: '',
telephoneNo: '',
longitude: '',
latitude: '',
registerName: '',
registerDate: null,
authorizedCapital: '',
subDistrictId: '',
districtId: '',
provinceId: '',
2024-04-23 11:37:27 +07:00
});
tab.value = customerBranch.value.length - 1;
2024-04-23 11:37:27 +07:00
}
2024-04-23 17:20:29 +07:00
function close(index: number) {
2024-06-06 13:56:38 +07:00
if (customerBranch.value.length === 1) return;
if (customerBranch.value.length === index + 1) {
tab.value = tab.value - 1;
} else if (tab.value >= index) {
tab.value = tab.value - 1;
}
if (customerBranch.value.length > 1) {
customerBranch.value.splice(index, 1);
2024-04-23 17:20:29 +07:00
}
}
2024-04-23 11:37:27 +07:00
</script>
<template>
<div class="column">
<q-tabs
active-bg-color="white"
active-color="primary"
indicator-color="white"
2024-04-23 17:20:29 +07:00
active-class="active-tab"
2024-04-23 11:37:27 +07:00
v-model="tab"
align="left"
inline-label
2024-04-23 17:20:29 +07:00
class="text-grey"
style="width: 960px; background-color: var(--_body-bg)"
2024-04-23 11:37:27 +07:00
>
<q-tab icon="mdi-plus" @click="addData()" />
2024-04-23 11:37:27 +07:00
<q-tab
v-for="(v, index) in customerBranch"
:key="index"
:name="index"
:label="`${$t('customerBranchFormTab')} ${index + 1}`"
2024-06-06 13:56:38 +07:00
@click="(tab = index), console.log(customerBranch)"
2024-04-23 17:20:29 +07:00
no-caps
>
<q-btn
round
flat
id="closeDialog"
icon="mdi-close"
padding="xs"
color="red"
:class="{ dark: $q.dark.isActive }"
@click.stop="close(index)"
/>
</q-tab>
2024-04-23 11:37:27 +07:00
</q-tabs>
</div>
<div class="column">
<q-tab-panels v-model="tab" class="rounded-borders">
<q-tab-panel
v-for="(v, index) in customerBranch"
:key="index"
:name="index"
>
2024-04-23 11:37:27 +07:00
<slot name="about"></slot>
<slot name="address"></slot>
<slot name="businessInformation"></slot>
<slot name="contactInformation"></slot>
<slot name="otherDocuments"></slot>
</q-tab-panel>
</q-tab-panels>
</div>
</template>
2024-04-23 17:20:29 +07:00
<style scoped>
.active-tab {
border: 1px solid #e0dcdc;
border-bottom: none;
}
</style>