jws-frontend/src/components/TabComponent.vue

156 lines
3.6 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
2024-06-06 10:29:30 +00:00
defineProps<{
readonly?: boolean;
edit?: boolean;
2024-06-06 10:29:30 +00: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({
2024-07-05 13:17:59 +07:00
code: '',
branchNo: undefined,
address: '',
addressEN: '',
provinceId: '',
districtId: '',
subDistrictId: '',
zipCode: '',
email: '',
telephoneNo: '',
name: '',
status: 'CREATED',
taxNo: '',
nameEN: '',
legalPersonNo: '',
registerName: '',
registerDate: new Date(),
authorizedCapital: '',
employmentOffice: '',
bussinessType: '',
bussinessTypeEN: '',
jobPosition: '',
jobPositionEN: '',
jobDescription: '',
saleEmployee: '',
payDate: new Date(),
wageRate: 0,
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 16:03:47 +07:00
if (customerBranch.value.length < 2) return;
2024-06-06 13:56:38 +07:00
2024-06-06 16:03:47 +07:00
if (
customerBranch.value.length === index + 1 &&
tab.value + 1 === customerBranch.value.length
) {
2024-06-06 13:56:38 +07:00
tab.value = tab.value - 1;
} else if (tab.value >= index) {
2024-06-06 16:03:47 +07:00
if (tab.value !== 0) {
tab.value = tab.value - 1;
}
2024-04-23 17:20:29 +07:00
}
2024-06-06 16:03:47 +07:00
customerBranch.value.splice(index, 1);
2024-04-23 17:20:29 +07:00
}
2024-04-23 11:37:27 +07:00
</script>
<template>
2024-06-06 16:03:47 +07:00
<div class="row no-wrap">
<q-btn
id="btn-add"
2024-06-07 15:15:42 +07:00
class="q-px-lg bordered-b bordered-r app-text-muted"
2024-06-06 16:03:47 +07:00
flat
2024-06-07 15:15:42 +07:00
:color="$q.dark.isActive ? 'primary' : ''"
2024-06-06 16:03:47 +07:00
style="background-color: var(--_body-bg)"
@click="addData()"
icon="mdi-plus"
2024-06-06 10:29:30 +00:00
:disable="readonly"
2024-06-06 16:03:47 +07:00
></q-btn>
2024-04-23 11:37:27 +07:00
<q-tabs
2024-06-07 15:15:42 +07:00
:active-bg-color="$q.dark.isActive ? 'dark' : 'white'"
:active-color="$q.dark.isActive ? 'white' : 'primary'"
2024-06-06 16:03:47 +07:00
indicator-color="transparent"
2024-06-07 15:15:42 +07:00
active-class="bordered-r"
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"
2024-06-06 16:03:47 +07:00
style="background-color: var(--_body-bg); max-width: 55vw"
2024-04-23 11:37:27 +07:00
>
<q-tab
:id="`tab-branch-${index}`"
v-for="(v, index) in customerBranch"
:key="index"
:name="index"
2024-07-05 13:17:59 +07:00
:label="`${$t('customerBranchFormTab')} `"
:disable="tab !== index && edit"
2024-06-06 16:03:47 +07:00
@click="tab = index"
2024-04-23 17:20:29 +07:00
no-caps
2024-06-07 15:15:42 +07:00
:class="tab === index ? '' : 'bordered-b bordered-r'"
>
<q-btn
round
flat
:id="`close-tab-${index}`"
icon="mdi-close"
padding="xs"
color="red"
:class="{ dark: $q.dark.isActive }"
@click.stop="close(index)"
2024-06-06 10:29:30 +00:00
v-if="!readonly"
/>
</q-tab>
2024-04-23 11:37:27 +07:00
</q-tabs>
</div>
2024-06-06 10:29:30 +00:00
<div class="column seprarator-fix">
2024-04-23 11:37:27 +07:00
<q-tab-panels v-model="tab" class="rounded-borders">
<q-tab-panel
2024-06-17 15:44:54 +07:00
:id="`tab-branch-${index}`"
v-for="(v, index) in customerBranch.sort(
(a, b) => (a.branchNo ?? 0) - (b.branchNo ?? 0),
)"
: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-06-06 10:29:30 +00:00
<style scoped lang="scss">
2024-04-23 17:20:29 +07:00
.active-tab {
border: 1px solid #e0dcdc;
border-bottom: none;
2024-06-06 16:03:47 +07:00
border-top: none;
border-left: none;
}
.tab-style {
border: 1px solid #e0dcdc;
border-left: none;
border-top: none;
2024-04-23 17:20:29 +07:00
}
2024-06-06 10:29:30 +00:00
:deep(.q-separator) {
padding-block: 0px !important;
}
2024-04-23 17:20:29 +07:00
</style>